diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 23:05:39 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 23:05:39 +0000 |
commit | 7a7b2927e185a4afba77bfa20f488e70d2e05799 (patch) | |
tree | 8ef1ac5ece7c909ae7a9b7668f7f9a8022d337c8 /bindings/csharp/examples/ExampleProgram.cs | |
parent | 4caadda7b78022e8b668bd18359261f233e6a641 (diff) | |
parent | 66c87e00364040f3d258d58301dcf06bc5749451 (diff) | |
download | libiio-7a7b2927e185a4afba77bfa20f488e70d2e05799.tar.gz |
Snap for 11785460 from 66c87e00364040f3d258d58301dcf06bc5749451 to sdk-releasesdk-release
Change-Id: If16b5fbb0619531b573cc830ebbf9d416f23077e
Diffstat (limited to 'bindings/csharp/examples/ExampleProgram.cs')
-rw-r--r-- | bindings/csharp/examples/ExampleProgram.cs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/bindings/csharp/examples/ExampleProgram.cs b/bindings/csharp/examples/ExampleProgram.cs new file mode 100644 index 0000000..f33e381 --- /dev/null +++ b/bindings/csharp/examples/ExampleProgram.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using iio; + +namespace IIOCSharp +{ + class ExampleProgram + { + static void Main(string[] args) + { + Context ctx = new Context("10.44.2.241"); + if (ctx == null) + { + Console.WriteLine("Unable to create IIO context"); + return; + } + + Console.WriteLine("IIO context created: " + ctx.name); + Console.WriteLine("IIO context description: " + ctx.description); + + Console.WriteLine("IIO context has " + ctx.devices.Count + " devices:"); + foreach (Device dev in ctx.devices) { + Console.WriteLine("\t" + dev.id + ": " + dev.name); + + if (dev is Trigger) + { + Console.WriteLine("Found trigger! Rate=" + ((Trigger) dev).get_rate()); + } + + Console.WriteLine("\t\t" + dev.channels.Count + " channels found:"); + + foreach (Channel chn in dev.channels) + { + string type = "input"; + if (chn.output) + type = "output"; + Console.WriteLine("\t\t\t" + chn.id + ": " + chn.name + " (" + type + ")"); + + if (chn.attrs.Count == 0) + continue; + + Console.WriteLine("\t\t\t" + chn.attrs.Count + " channel-specific attributes found:"); + foreach (Attr attr in chn.attrs) + { + Console.WriteLine("\t\t\t\t" + attr.name); + if (attr.name.CompareTo("frequency") == 0) + { + Console.WriteLine("Attribute content: " + attr.read()); + } + } + + } + + /* If we find cf-ad9361-lpc, try to read a few bytes from the first channel */ + if (dev.name.CompareTo("cf-ad9361-lpc") == 0) + { + Channel chn = dev.channels[0]; + chn.enable(); + IOBuffer buf = new IOBuffer(dev, 0x8000); + buf.refill(); + + Console.WriteLine("Read " + chn.read(buf).Length + " bytes from hardware"); + buf.Dispose(); + } + + if (dev.attrs.Count == 0) + continue; + + Console.WriteLine("\t\t" + dev.attrs.Count + " device-specific attributes found:"); + foreach (Attr attr in dev.attrs) + Console.WriteLine("\t\t\t" + attr.name); + + } + + /* Wait for user input */ + Console.ReadLine(); + } + } +} |