Loading...
Searching...
No Matches
ExampleProgram.cs

Small example program

/*
* 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)
{
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();
}
}
}
iio.Attr
iio.Attr class: Contains the representation of a channel or device attribute.
Definition Attr.cs:21
iio.Attr.read
string read()
Read the value of this attribute as a string.
iio.Attr.name
readonly string name
The name of this attribute.
Definition Attr.cs:23
iio.Channel
iio.Channel class: Contains the representation of an input or output channel.
Definition Channel.cs:22
iio.Channel.name
readonly string name
The name of this channel.
Definition Channel.cs:258
iio.Channel.attrs
readonly List< Attr > attrs
A list of all the attributes that this channel has.
Definition Channel.cs:276
iio.Channel.enable
void enable()
Enable the current channel, so that it can be used for I/O operations.
Definition Channel.cs:320
iio.Channel.output
readonly bool output
Contains true if the channel is an output channel, false otherwise.
Definition Channel.cs:267
iio.Channel.id
readonly string id
An identifier of this channel.
Definition Channel.cs:263
iio.Channel.read
byte[] read(IOBuffer buffer, bool raw=false)
Extract the samples corresponding to this channel from the given iio.IOBuffer object.
Definition Channel.cs:344
iio.Context
iio.Context class: Contains the representation of an IIO context.
Definition Context.cs:35
iio.Context.name
readonly string name
The name of the current context.
Definition Context.cs:104
iio.Context.description
readonly string description
Retrieve a human-readable information string about the current context.
Definition Context.cs:107
iio.Context.devices
readonly List< Device > devices
A List of all the IIO devices present on the current context.
Definition Context.cs:112
iio.Device
iio.Device class: Contains the representation of an IIO device.
Definition Device.cs:21
iio.Device.channels
readonly List< Channel > channels
A list of all the iio.Channel objects that this device possesses.
Definition Device.cs:226
iio.Device.id
readonly string id
An identifier of this device.
Definition Device.cs:205
iio.Device.name
readonly string name
The name of this device.
Definition Device.cs:208
iio.Device.attrs
readonly List< Attr > attrs
A list of all the attributes that this device has.
Definition Device.cs:217
iio.IOBuffer
iio.IOBuffer class: The class used for all I/O operations.
Definition IOBuffer.cs:23
iio.IOBuffer.refill
void refill()
Fetch a new set of samples from the hardware.
Definition IOBuffer.cs:103
iio.IOBuffer.Dispose
void Dispose()
Releases all resource used by the iio.IOBuffer object.
Definition IOBuffer.cs:140
iio.Trigger
iio.Trigger class: Contains the representation of an IIO device that can act as a trigger.
Definition Trigger.cs:21
iio
Definition Attr.cs:17