Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
resources:tools-software:linux-software:iio_cmdsrv [02 May 2014 19:50] – add location of script Di Puresources:tools-software:linux-software:iio_cmdsrv [17 Sep 2015 18:55] (current) – IIOD has been deprecate in favour of IIOD for a while now Lars-Peter Clausen
Line 1: Line 1:
 ====== IIO Command Server ====== ====== 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. +The IIO Command Server has been deprecated in favor of [[/resources/tools-software/linux-software/libiio_internals#the_network_backend_and_iio_daemon|IIOD]].
- +
-In later case the iio-cmdsrv is used with ''netcats -e'' exec option. [[http://busybox.net/downloads/BusyBox.html#nc|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: +
-<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap> +
-<xterm> +
-# /bin/nc -l -l -p 1234 -e /usr/local/bin/iio_cmdsrv & +
-</xterm></WRAP> +
- +
-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: +
-<WRAP box bggreen><wrap info>This specifies any shell prompt running on the target</wrap> +
-<xterm> +
-# /bin/nc -l -l -p 1235 -u -e /usr/local/bin/iio_cmdsrv & +
-</xterm></WRAP> +
- +
-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 Code ===== +
- +
-^  Source +
-| [[github>iio-cmdsrv?master/server | iio-cmdsrv/server]] | +
-====== 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:**\\ +
-<code>show +
-+
-ad8366-lpc ad9523-lpc adf4351-rx-lpc adf4351-tx-lpc cf-ad9643-core-lpc cf-ad9122-core-lpc  +
-</code> +
- +
-<code>show ad8366-lpc . +
-+
-dev name out_voltage1_hardwaregain uevent out_voltage0_hardwaregain +
-</code> +
- +
-===== 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:**\\ +
-<code>read ad8366-lpc name +
-+
-ad8366-lpc +
-</code> +
- +
- +
-===== WRITE IIO Device Attributes ===== +
- +
-**Syntax:**\\ +
-**write** **<**//IIODeviceName//**>** **<**//Attribute//**>** **<**//Value//**>** +
- +
-**Return Value:**\\ +
-ERROR return code (ERRNO), where negative values indicate errors.\\ +
- +
-**Example:**\\ +
-<code>write ad8366-lpc out_voltage0_hardwaregain 4.5000 +
-+
-</code> +
- +
-===== 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:**\\ +
-<code>readbuf ad7476 10 2 +
-20 +
-��?{|X?m?m|X{�?�� +
-</code> +
- +
- +
-===== BUFWRITE IIO Device Buffers ===== +
- +
-**Syntax:**\\ +
-**bufwrite** **<**//IIODeviceName//**>** **<**//NUMBytes//**>** +
- +
-**Return Value:**\\ +
-Return ERROR Code (ERRNO), where negative values indicate errors.\\ +
- +
-**Example:**\\ +
-<code>bufwrite cf-ad9122-core-lpc 64 +
-��?{|X?m?m|X{�?�� +
-+
-</code> +
- +
-===== 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:**\\ +
-<code>sample cf-ad9643-core-lpc 10 4 +
-20 +
-��?{|X?m?m|X{�?�� +
-</code> +
-===== 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:**\\ +
-<code>regread cf-ad9643-core-lpc 0x01 +
-+
-0x82 +
-</code> +
- +
- +
-===== REGWRITE IIO Device HW Registers via debugfs ===== +
- +
-**Syntax:**\\ +
-**regwrite** **<**//IIODeviceName//**>** **<**//RegisterAddress//**>** **<**//Value//**>** +
- +
-**Return Value:**\\ +
-ERROR return code (ERRNO), where negative values indicate errors.\\ +
- +
-**Example:**\\ +
-<code>regwrite cf-ad9643-core-lpc 0x1D 0xAB +
-10 +
-</code> +
- +
-===== VERSION IIO Command Server Version Information ===== +
- +
-**Syntax:**\\ +
-**version** +
- +
-**Return Value:**\\ +
-Version string\\ +
- +
-**Example:**\\ +
-<code>version +
-0.2 +
-</code> +
- +
-===== IIO Command Server Client Interfaces ===== +
- +
-==== C# Client Library ==== +
- +
-=== Source Code === +
- +
-^  Source +
-[[github>iio-cmdsrv?master/clients/csharp | iio-cmdsrv/clients/csharp]] | +
- +
-=== Example Test Code === +
- +
-<code 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(); +
-    } +
-</code> +
-==== C Client Library ==== +
- +
-=== Source Code === +
- +
-^  Source +
-| [[github>iio-cmdsrv?master/clients/c| iio-cmdsrv/clients/c]] | +
- +
-=== Example Test Code === +
- +
-<code 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; +
-+
-</code> +
- +
-==== Matlab Client Library ==== +
- +
-=== Source Code === +
- +
-^  Source +
-[[github>iio-cmdsrv?master/clients/matlab| iio-cmdsrv/clients/matlab]] +
- +
-=== Example Test Code === +
-<code 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) +
-</code>+
resources/tools-software/linux-software/iio_cmdsrv.txt · Last modified: 17 Sep 2015 18:55 by Lars-Peter Clausen