-
Notifications
You must be signed in to change notification settings - Fork 354
Expand file tree
/
Copy pathExampleProgram.cs
More file actions
152 lines (134 loc) · 5.56 KB
/
ExampleProgram.cs
File metadata and controls
152 lines (134 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright (C) 2014 Analog Devices, Inc.
* Author: Paul Cercueil <paul.cercueil@analog.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* */
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)
{
const uint blocksize = 1024;
Scan scan = new Scan();
if (scan.nb_results > 0) {
Console.WriteLine("* Scanned contexts: " + scan.nb_results);
}
foreach (var entry in scan.results) {
Console.WriteLine("\t" + entry.Key + " " + entry.Value);
}
scan.Dispose();
Context ctx;
try
{
ctx = new Context("ip:192.168.2.1");
Console.WriteLine(ctx.xml);
} catch (IIOException e)
{
Console.WriteLine(e.ToString());
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)
{
string attr_name = "\t\t\t\t" + attr.name;
string attr_val = "";
try
{
if (attr.name == "calibscale")
{
double val = attr.read_double();
Console.WriteLine(attr_name + " " + val);
}
else
{
attr_val = attr.read();
Console.WriteLine(attr_name + " " + attr_val);
}
}
catch (IIOException)
{
Console.WriteLine(attr_name);
}
}
}
/* If we find cf-ad9361-lpc, try to read a few bytes from the first channel */
if (dev.name.CompareTo("cf-ad9361-lpc") == 0)
{
ChannelsMask chnmask = new ChannelsMask((uint)dev.channels.Count);
Channel rx0_i = dev.channels[0];
rx0_i.enable(chnmask);
Channel rx0_q = dev.channels[1];
rx0_q.enable(chnmask);
IOBuffer buf = dev.buffers[0];
uint sampleSize = dev.get_sample_size(chnmask);
Console.WriteLine("* Sample size is " + sampleSize + "\n");
Console.WriteLine("\t\t\t" + buf.attrs.Count + " buffer-specific attributes found:");
foreach (Attr attr in buf.attrs)
{
Console.WriteLine("\t\t\t\t" + attr.name + " " + attr.read());
}
iio.Stream stream = new iio.Stream(buf, chnmask, 4, blocksize);
for (int i=0; i < 10; i++) {
Block block = stream.next();
byte[] databuf = new byte[blocksize];
block.read(databuf);
Console.WriteLine("* ("+ i + ") Read " + databuf.Length + " bytes from hardware");
}
stream.Dispose();
chnmask.Dispose();
}
if (dev.attrs.Count == 0)
{
continue;
}
Console.WriteLine("\n\t\t" + dev.attrs.Count + " device-specific attributes found:");
foreach (Attr attr in dev.attrs)
{
Console.WriteLine("\t\t\t" + attr.name);
}
}
}
}
}