• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using iio;
7 
8 namespace IIOCSharp
9 {
10     class ExampleProgram
11     {
Main(string[] args)12         static void Main(string[] args)
13         {
14             Context ctx = new Context("10.44.2.241");
15             if (ctx == null)
16             {
17                 Console.WriteLine("Unable to create IIO context");
18                 return;
19             }
20 
21             Console.WriteLine("IIO context created: " + ctx.name);
22             Console.WriteLine("IIO context description: " + ctx.description);
23 
24             Console.WriteLine("IIO context has " + ctx.devices.Count + " devices:");
25             foreach (Device dev in ctx.devices) {
26                 Console.WriteLine("\t" + dev.id + ": " + dev.name);
27 
28                 if (dev is Trigger)
29                 {
30                     Console.WriteLine("Found trigger! Rate=" + ((Trigger) dev).get_rate());
31                 }
32 
33                 Console.WriteLine("\t\t" + dev.channels.Count + " channels found:");
34 
35                 foreach (Channel chn in dev.channels)
36                 {
37                     string type = "input";
38                     if (chn.output)
39                         type = "output";
40                     Console.WriteLine("\t\t\t" + chn.id + ": " + chn.name + " (" + type + ")");
41 
42                     if (chn.attrs.Count == 0)
43                         continue;
44 
45                     Console.WriteLine("\t\t\t" + chn.attrs.Count + " channel-specific attributes found:");
46                     foreach (Attr attr in chn.attrs)
47                     {
48                         Console.WriteLine("\t\t\t\t" + attr.name);
49                         if (attr.name.CompareTo("frequency") == 0)
50                         {
51                             Console.WriteLine("Attribute content: " + attr.read());
52                         }
53                     }
54 
55                 }
56 
57 				/* If we find cf-ad9361-lpc, try to read a few bytes from the first channel */
58                 if (dev.name.CompareTo("cf-ad9361-lpc") == 0)
59                 {
60                     Channel chn = dev.channels[0];
61                     chn.enable();
62                     IOBuffer buf = new IOBuffer(dev, 0x8000);
63                     buf.refill();
64 
65                     Console.WriteLine("Read " + chn.read(buf).Length + " bytes from hardware");
66                     buf.Dispose();
67                 }
68 
69                 if (dev.attrs.Count == 0)
70                     continue;
71 
72                 Console.WriteLine("\t\t" + dev.attrs.Count + " device-specific attributes found:");
73                 foreach (Attr attr in dev.attrs)
74                     Console.WriteLine("\t\t\t" + attr.name);
75 
76             }
77 
78 			/* Wait for user input */
79             Console.ReadLine();
80         }
81     }
82 }
83