Wiki

This version is outdated by a newer approved version.DiffThis version (29 Nov 2012 17:45) was approved by Michael Hennerich.

This is an old revision of the document!


IIO Command Server

The IIO Command Server runs on the embedded target and translates a set of simple human readable commands into more complex sysfs and device node interactions. The typical use case is to control the server via a network connection. In later case the iio-cmdsrv is used with netcats -e exec option. BusyBox Netcat (nc) is set to listen for incomming connects and then starts the server. The -l option is set twice to enable the persisten server mode.

Example: <box 100% green|shell prompt running on the target>

# /usr/bin/nc -l -l -p 1234 -e /bin/iio_cmdsrv &
</box>

However it's also possible to invoke the server on the target's command line to simplify device interactions.

Source Code

Command Syntax

SHOW IIO Devices or Attributes

Syntax:
show [<IIODeviceName> .]

Return Value:
Returns two lines separated by LF ('\n').
First Line contains ERROR return code (ERRNO), where negative values indicate errors.
Second line contains a space separated list of devices or attributes, only in case ERRNO >= 0.

Example:

Example:

show
0
ad8366-lpc ad9523-lpc adf4351-rx-lpc adf4351-tx-lpc cf-ad9643-core-lpc cf-ad9122-core-lpc 
show ad8366-lpc .
0
dev name out_voltage1_hardwaregain uevent out_voltage0_hardwaregain

READ IIO Device Attributes

Syntax:
read <IIODeviceName> <Attribute>

Return Value:
Returns two lines separated by LF ('\n').
First Line contains ERROR return code (ERRNO), where negative values indicate errors.
Second line contains the read value, only in case ERRNO >= 0.

Example:

read ad8366-lpc name
0
ad8366-lpc

WRITE IIO Device Attributes

Syntax:
write <IIODeviceName> <Attribute> <Value>

Return Value:
ERROR return code (ERRNO), where negative values indicate errors.

Example:

write ad8366-lpc out_voltage0_hardwaregain 4.5000
7

BUFREAD IIO Device Buffers

Syntax:
readbuf <IIODeviceName> <NUMSamples> <BytesPerSample>

Return Value:
First Line contains number of bytes read or negative ERROR return code (ERRNO), where negative values indicate errors.
If return code > 0, the read data is directly followed.

Example:

readbuf ad7476 10 2
20
��?{|X?m?m|X{�?��

BUFWRITE IIO Device Buffers

Syntax:
bufwrite <IIODeviceName> <NUMBytes>

Return Value:
Return ERROR Code (ERRNO), where negative values indicate errors.

Example:

bufwrite cf-ad9122-core-lpc 64
��?{|X?m?m|X{�?��
0

SAMPLE IIO Device

Unlike READBUF the SAMPLE command takes control over the buffer control attributes.
It sets buffer length and enables the buffer, then busy waits until the requested amount of samples are available.

Syntax:
sample <IIODeviceName> <NUMSamples> <BytesPerSample>

Return Value:
First Line contains number of bytes read or negative ERROR return code (ERRNO), where negative values indicate errors.
If return code > 0, the read data is directly followed.

Example:

sample cf-ad9643-core-lpc 10 4
20
��?{|X?m?m|X{�?��

REGREAD IIO Device HW Registers via debugfs

Syntax:
regread <IIODeviceName> <RegisterAddress>

Return Value:
Returns two lines separated by LF ('\n').
First Line contains ERROR return code (ERRNO), where negative values indicate errors.
Second line contains the read value, only in case ERRNO >= 0.

Example:

regread cf-ad9643-core-lpc 0x01
0
0x82

REGWRITE IIO Device HW Registers via debugfs

Syntax:
regwrite <IIODeviceName> <RegisterAddress> <Value>

Return Value:
ERROR return code (ERRNO), where negative values indicate errors.

Example:

regwrite cf-ad9643-core-lpc 0x1D 0xAB
10

VERSION IIO Command Server Version Information

Syntax:
version

Return Value:
Version string

Example:

version
0.2

IIO Command Server Client Interfaces

C# Client Library

Source Code

Example Test Code

/*  TEST CODE */
 
public class test_iio_srv
{
    public static void Main(string[] args)
    {
 
     IIOCmdSrv srv  = new IIOCmdSrv();
     // Connect to IIO command server
     srv.Connect("10.44.2.110");
 
     /* Show IIO Server Version Information */       
     Console.WriteLine("Server Version: " + srv.Version());
 
//Server Version: 0.2
 
 
     /* List Available IIO Devices on the Server */  
     IIODevice [] iio_devices = srv.ListDevices();
     foreach (var device in iio_devices)  
           Console.WriteLine("iio_devices are:" + device);
 
 
//iio_devices are:ad8366-lpc
//iio_devices are:ad9523-lpc
//iio_devices are:adf4351-rx-lpc
//iio_devices are:adf4351-tx-lpc
//iio_devices are:cf-ad9643-core-lpc
//iio_devices are:cf-ad9122-core-lpc
 
 
     /* A single server may handle multiple devices/drivers */
     IIODevice ad9643 = new IIODevice(srv, "cf-ad9643-core-lpc");
 
     /* Read the name attribute */
     Console.WriteLine("Device Name: " + ad9643.Read("name"));
 
//Device Name: cf-ad9643-core-lpc
 
 
     /* Read the in_voltage_scale_available attribute */
     Console.WriteLine("in_voltage_scale_available: " + ad9643.Read("in_voltage_scale_available"));
 
//in_voltage_scale_available: 0.031738 0.031403 0.031067 0.030731 0.030396 0.030060 0.029724 0.029388 0.029053 0.028717 0.028381 0.028046 0.027710 0.027374 0.027039 0.026703 0.026367 0.026031 0.025696 0.025360 0.025024 0.024689 0.024353 0.024017 0.023682 0.023346 0.023010 0.022675 0.022339 0.022003 0.021667 0.021332
 
 
     /* Set test modes for AD9643 Channel 0 and 1 */ 
     ad9643.Write("in_voltage0_test_mode", "checkerboard");
     ad9643.Write("in_voltage1_test_mode", "pos_fullscale");    
 
     /* Get 10 Samples */
     byte[] buf = ad9643.Sample(10, 4);
     for (var i = 0; i < buf.Length; i+=2)
           Console.Write(string.Format("{0}\n",BitConverter.ToInt16(buf, i)));
 
//8191
//5461
//8191
//-5462
//8191
//5461
//8191
//-5462
//8191
//5461
//8191
//-5462
//8191
//5461
//8191
//-5462
//8191
//5461
//8191
//-5462
 
 
     /* Turn test modes off */       
     ad9643.Write("in_voltage0_test_mode", "off");
     ad9643.Write("in_voltage1_test_mode", "off");
 
 
     /* Test Direct Register Access methods */  
     Console.WriteLine("Device ID: (dec)" + ad9643.RegRead(0x1));          
 
//Device ID: (dec)130
 
     ad9643.RegWrite(0x20, 0xAB);               
     Console.WriteLine("Reg 0x20: (dec)" + ad9643.RegRead(0x20));
 
//Reg 0x20: (dec)171
 
 
     /* List all device attributes */
     string [] attributes =     ad9643.ListAttributes();
     foreach (string s in attributes)     
           Console.WriteLine("Attributes are:" + s);
 
//Attributes are:dev
//Attributes are:name
//Attributes are:in_voltage1_calibbias
//Attributes are:in_voltage_scale
//Attributes are:in_voltage1_frequency_domain_calibbias
//Attributes are:in_voltage0_calibscale
//Attributes are:in_voltage0_calibbias
//Attributes are:in_voltage1_calibscale
//Attributes are:in_voltage1_test_mode
//Attributes are:in_voltage_frequency_domain_scale
//Attributes are:in_voltage_test_mode_available
//Attributes are:in_voltage0_frequency_domain_calibbias
//Attributes are:in_voltage0_test_mode
//Attributes are:uevent
//Attributes are:in_voltage1_frequency_domain_calibscale
//Attributes are:in_voltage_scale_available
//Attributes are:in_voltage0_frequency_domain_calibscale
 
 
     /* List all device scan elements */  
     string [] scan_elements = ad9643.ListScanElements();
     foreach (string s in scan_elements)  
           Console.WriteLine("Scan_elements are:" + s);         
 
//Scan_elements are:in_voltage1_frequency_domain_type
//Scan_elements are:in_voltage0_index
//Scan_elements are:in_voltage0_en
//Scan_elements are:in_voltage1_en
//Scan_elements are:in_voltage1_frequency_domain_index
//Scan_elements are:in_voltage0_frequency_domain_index
//Scan_elements are:in_voltage1_index
//Scan_elements are:in_voltage0_type
//Scan_elements are:in_voltage1_type
//Scan_elements are:in_voltage0_frequency_domain_en
//Scan_elements are:in_voltage0_frequency_domain_type
//Scan_elements are:in_voltage1_frequency_domain_en
 
 
     /* Disconnect Server */
     srv.Disconnect();
    }

C Client Library

Source Code

Example Test Code

#include <stdio.h>
#include <stdlib.h>
 
#include "lib_iio_cmdsrv.h"
 
int main (int argc , char* argv[])
{
	struct iio_cmdsrv srv;
	int ret; unsigned i;
	short buf2[400000];
	char *buf = (char*) buf2;
 
	ret = iio_cmdsrv_connect("10.44.2.188", "1234", &srv);
	if (ret)
		perror("connection failed");
 
	ret = iio_cmd_read(&srv, buf, 200, "read cf-ad9643-core-lpc name\n", NULL);
 
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_read(&srv, buf, 200, "read cf-ad9643-core-lpc in_voltage0_test_mode\n", NULL);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_read(&srv, buf, 1000, "read cf-ad9643-core-lpc in_voltage_scale_available\n", NULL);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_read(&srv, buf, 200, "read cf-ad9643-core-lpc in_voltage_scale\n", NULL);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_read(&srv, buf, 200, "read cf-ad9643-core-lpc name\n", NULL);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_send(&srv, "write cf-ad9643-core-lpc in_voltage_scale %f\n", 0.025024);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_read(&srv, buf, 200, "read cf-ad9643-core-lpc in_voltage_scale\n", NULL);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_send(&srv, "write cf-ad9643-core-lpc in_voltage_scale %f\n", 0.030060);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_read(&srv, buf, 200, "read cf-ad9643-core-lpc in_voltage_scale\n", NULL);
	printf("main:retval %s (ret %d)\n", buf, ret);
 
	ret = iio_cmd_sample(&srv, "cf-ad9643-core-lpc",
		   buf, 40, 4);
	printf("main:retval (ret %d)\n", ret);
	for (i = 0; i < 40; i++)
		printf("[%d] = %d\n", i, buf2[i]);
 
 
	ret = iio_cmd_sample(&srv, "cf-ad9643-core-lpc",
		   buf, 40, 4);
	printf("main:retval (ret %d)\n", ret);
	for (i = 0; i < 40; i++)
		printf("[%d] = %d\n", i, buf2[i]);
 
	ret = iio_cmd_regread(&srv, "cf-ad9643-core-lpc", 1, &i);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_regread(&srv, "cf-ad9643-core-lpc", 2, &i);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_regread(&srv, "cf-ad9643-core-lpc", 1, &i);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_regwrite(&srv, "cf-ad9643-core-lpc", 0x20, 0xAB);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_regread(&srv, "cf-ad9643-core-lpc", 0x20, &i);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_regwrite(&srv, "cf-ad9643-core-lpc", 0x20, 0);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_regread(&srv, "cf-ad9643-core-lpc", 0x20, &i);
	printf("%d [%x]\n", ret, i);
 
	ret = iio_cmd_bufwrite(&srv, "cf-ad9643-core-lpc",
		   buf, 400000);
	printf("main:retval (ret %d)\n", ret);
 
	return 0;
}
resources/tools-software/linux-software/iio_cmdsrv.1354207528.txt.gz · Last modified: 29 Nov 2012 17:45 by Michael Hennerich