This is an old revision of the document!
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 incoming connects and then starts the server. The -l
option is set twice to enable the persistent server mode.
Example:
This specifies any shell prompt running on the target
# /bin/nc -l -l -p 1234 -e /usr/local/bin/iio_cmdsrv &
The default above would listen to port 1234, with tcp. If you wanted to do things on a different port with udp, just change the port number, and add a -u
; something like:
This specifies any shell prompt running on the target
# /bin/nc -l -l -p 1235 -u -e /usr/local/bin/iio_cmdsrv &
This script is normally in /usr/local/bin/start_srv.sh
It's also possible to invoke the server on the target's command line to simplify device interactions.
Source |
---|
iio-cmdsrv/server |
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
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
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
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{�?��
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
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{�?��
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
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
Syntax:
version
Return Value:
Version string
Example:
version 0.2
Source |
---|
iio-cmdsrv/clients/csharp |
/* 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(); }
Source |
---|
iio-cmdsrv/clients/c |
#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; }
Source |
---|
iio-cmdsrv/clients/matlab |
clear all; close all; obj = iio_cmdsrv; iio_cmdsrv_connect(obj, '192.168.11.153', 1234); [ret, rbuf] = iio_cmd_read(obj, 200, 'read cf-ad9643-core-lpc name\n'); sprintf('\nread cf-ad9643-core-lpc name --> return: %d, data: %s\n', ret, rbuf) [ret, rbuf] = iio_cmd_read(obj, 200, 'read cf-ad9643-core-lpc in_voltage0_test_mode\n'); sprintf('\nread cf-ad9643-core-lpc in_voltage0_test_mode --> return: %d, data: %s\n', ret, rbuf) [ret, rbuf] = iio_cmd_read(obj, 1000, 'read cf-ad9643-core-lpc in_voltage_scale_available\n'); sprintf('\nread cf-ad9643-core-lpc in_voltage_scale_available --> return: %d, data: %s\n', ret, rbuf) [ret, rbuf] = iio_cmd_read(obj, 200, 'read cf-ad9643-core-lpc in_voltage_scale\n'); sprintf('\nread cf-ad9643-core-lpc in_voltage_scale --> return: %d, data: %s\n', ret, rbuf) [ret, rbuf] = iio_cmd_read(obj, 200, 'read cf-ad9643-core-lpc name\n'); sprintf('\nread cf-ad9643-core-lpc name --> return: %d, data: %s\n', ret, rbuf) ret = iio_cmd_send(obj, 'write cf-ad9643-core-lpc in_voltage_scale %f\n', 0.025024); sprintf('\nwrite cf-ad9643-core-lpc in_voltage_scale %f --> return: %d\n', 0.025024, ret) [ret, rbuf] = iio_cmd_read(obj, 200, 'read cf-ad9643-core-lpc in_voltage_scale\n'); sprintf('\nread cf-ad9643-core-lpc in_voltage_scale --> return: %d, data: %s\n', ret, rbuf) ret = iio_cmd_send(obj, 'write cf-ad9643-core-lpc in_voltage_scale %f\n', 0.030060); sprintf('\nwrite cf-ad9643-core-lpc in_voltage_scale %f --> return: %d\n', 0.030060, ret) [ret, rbuf] = iio_cmd_read(obj, 200, 'read cf-ad9643-core-lpc in_voltage_scale\n'); sprintf('\nread cf-ad9643-core-lpc in_voltage_scale --> return: %d, data: %s\n', ret, rbuf) [ret, rbuf] = iio_cmd_sample(obj, 'cf-ad9643-core-lpc', 40, 4); sprintf('\niio_cmd_sample cf-ad9643-core-lpc 40, 4 --> return: %d, data: \n', ret) uint8(rbuf) [ret, val] = iio_cmd_regread(obj, 'cf-ad9643-core-lpc', 1); sprintf('\niio_cmd_regread cf-ad9643-core-lpc 1 --> return: %d, data: %d\n', ret, val) [ret, val] = iio_cmd_regread(obj, 'cf-ad9643-core-lpc', 2); sprintf('\niio_cmd_regread cf-ad9643-core-lpc 2 --> return: %d, data: %d\n', ret, val) [ret, val] = iio_cmd_regread(obj, 'cf-ad9643-core-lpc', 1); sprintf('\niio_cmd_regread cf-ad9643-core-lpc 1 --> return: %d, data: %d\n', ret, val) ret = iio_cmd_regwrite(obj, 'cf-ad9643-core-lpc', hex2dec('20'), hex2dec('AB')); sprintf('\niio_cmd_regwrite cf-ad9643-core-lpc 0x20, 0xAB --> return: %d\n', ret) [ret, val] = iio_cmd_regread(obj, 'cf-ad9643-core-lpc', hex2dec('20')); sprintf('\niio_cmd_regread cf-ad9643-core-lpc 0x20 --> return: %d, data: %d\n', ret, val) ret = iio_cmd_regwrite(obj, 'cf-ad9643-core-lpc', hex2dec('20'), 0); sprintf('\niio_cmd_regwrite cf-ad9643-core-lpc 0x20 0 --> return: %d\n', ret) [ret, val] = iio_cmd_regread(obj, 'cf-ad9643-core-lpc', hex2dec('20')); sprintf('\niio_cmd_regread cf-ad9643-core-lpc --> return: %d, data: %d\n', ret, val) ret = iio_cmdsrv_disconnect(obj); sprintf('\niio_cmdsrv_disconnect --> return: %d\n', ret)