This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
resources:tools-software:linux-software:iio_cmdsrv [02 May 2014 19:50] – add location of script Di Pu | resources: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 | + | The IIO Command Server |
- | + | ||
- | In later case the iio-cmdsrv is used with '' | + | |
- | + | ||
- | Example: | + | |
- | <WRAP box bggreen>< | + | |
- | < | + | |
- | # /bin/nc -l -l -p 1234 -e / | + | |
- | </ | + | |
- | + | ||
- | 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 '' | + | |
- | <WRAP box bggreen>< | + | |
- | < | + | |
- | # /bin/nc -l -l -p 1235 -u -e / | + | |
- | </ | + | |
- | + | ||
- | This script is normally | + | |
- | + | ||
- | It's also possible to invoke the server on the target' | + | |
- | ===== Source Code ===== | + | |
- | + | ||
- | ^ Source | + | |
- | | [[github> | + | |
- | ====== Command Syntax ====== | + | |
- | + | ||
- | ===== SHOW IIO Devices or Attributes ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **show** **[< | + | |
- | + | ||
- | **Return Value: | + | |
- | Returns two lines separated by LF (' | + | |
- | 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: | + | |
- | < | + | |
- | 0 | + | |
- | ad8366-lpc ad9523-lpc adf4351-rx-lpc adf4351-tx-lpc cf-ad9643-core-lpc cf-ad9122-core-lpc | + | |
- | </ | + | |
- | + | ||
- | < | + | |
- | 0 | + | |
- | dev name out_voltage1_hardwaregain uevent out_voltage0_hardwaregain | + | |
- | </ | + | |
- | + | ||
- | ===== READ IIO Device Attributes ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **read** **< | + | |
- | + | ||
- | **Return Value: | + | |
- | Returns two lines separated by LF (' | + | |
- | First Line contains ERROR return code (ERRNO), where negative values indicate errors.\\ | + | |
- | Second line contains the read value, only in case ERRNO >= 0. | + | |
- | + | ||
- | **Example: | + | |
- | < | + | |
- | 0 | + | |
- | ad8366-lpc | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== WRITE IIO Device Attributes ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **write** **< | + | |
- | + | ||
- | **Return Value: | + | |
- | ERROR return code (ERRNO), where negative values indicate errors.\\ | + | |
- | + | ||
- | **Example: | + | |
- | < | + | |
- | 7 | + | |
- | </ | + | |
- | + | ||
- | ===== BUFREAD IIO Device Buffers ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **readbuf** **< | + | |
- | + | ||
- | **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: | + | |
- | < | + | |
- | 20 | + | |
- | ��? | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== BUFWRITE IIO Device Buffers ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **bufwrite** **< | + | |
- | + | ||
- | **Return Value: | + | |
- | Return ERROR Code (ERRNO), where negative values indicate errors.\\ | + | |
- | + | ||
- | **Example: | + | |
- | < | + | |
- | ��? | + | |
- | 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** **< | + | |
- | + | ||
- | **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: | + | |
- | < | + | |
- | 20 | + | |
- | ��? | + | |
- | </ | + | |
- | ===== REGREAD IIO Device HW Registers via debugfs ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **regread** **< | + | |
- | + | ||
- | **Return Value: | + | |
- | Returns two lines separated by LF (' | + | |
- | First Line contains ERROR return code (ERRNO), where negative values indicate errors.\\ | + | |
- | Second line contains the read value, only in case ERRNO >= 0. | + | |
- | + | ||
- | **Example: | + | |
- | < | + | |
- | 0 | + | |
- | 0x82 | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== REGWRITE IIO Device HW Registers via debugfs ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **regwrite** **< | + | |
- | + | ||
- | **Return Value: | + | |
- | ERROR return code (ERRNO), where negative values indicate errors.\\ | + | |
- | + | ||
- | **Example: | + | |
- | < | + | |
- | 10 | + | |
- | </ | + | |
- | + | ||
- | ===== VERSION IIO Command Server Version Information ===== | + | |
- | + | ||
- | **Syntax: | + | |
- | **version** | + | |
- | + | ||
- | **Return Value: | + | |
- | Version string\\ | + | |
- | + | ||
- | **Example: | + | |
- | < | + | |
- | 0.2 | + | |
- | </ | + | |
- | + | ||
- | ===== IIO Command Server Client Interfaces ===== | + | |
- | + | ||
- | ==== C# Client Library ==== | + | |
- | + | ||
- | === Source Code === | + | |
- | + | ||
- | ^ Source | + | |
- | | [[github> | + | |
- | + | ||
- | === Example Test Code === | + | |
- | + | ||
- | <code csharp> | + | |
- | /* TEST CODE */ | + | |
- | + | ||
- | public class test_iio_srv | + | |
- | { | + | |
- | public static void Main(string[] args) | + | |
- | { | + | |
- | + | ||
- | | + | |
- | // Connect to IIO command server | + | |
- | | + | |
- | + | ||
- | /* Show IIO Server Version Information */ | + | |
- | | + | |
- | + | ||
- | //Server Version: 0.2 | + | |
- | + | ||
- | + | ||
- | /* List Available IIO Devices on the Server */ | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | + | ||
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | + | ||
- | + | ||
- | /* A single server may handle multiple devices/ | + | |
- | | + | |
- | + | ||
- | /* Read the name attribute */ | + | |
- | | + | |
- | + | ||
- | //Device Name: cf-ad9643-core-lpc | + | |
- | + | ||
- | + | ||
- | /* Read the in_voltage_scale_available attribute */ | + | |
- | | + | |
- | + | ||
- | // | + | |
- | + | ||
- | + | ||
- | /* Set test modes for AD9643 Channel 0 and 1 */ | + | |
- | | + | |
- | | + | |
- | + | ||
- | /* Get 10 Samples */ | + | |
- | | + | |
- | for (var i = 0; i < buf.Length; i+=2) | + | |
- | | + | |
- | + | ||
- | //8191 | + | |
- | //5461 | + | |
- | //8191 | + | |
- | //-5462 | + | |
- | //8191 | + | |
- | //5461 | + | |
- | //8191 | + | |
- | //-5462 | + | |
- | //8191 | + | |
- | //5461 | + | |
- | //8191 | + | |
- | //-5462 | + | |
- | //8191 | + | |
- | //5461 | + | |
- | //8191 | + | |
- | //-5462 | + | |
- | //8191 | + | |
- | //5461 | + | |
- | //8191 | + | |
- | //-5462 | + | |
- | + | ||
- | + | ||
- | /* Turn test modes off */ | + | |
- | | + | |
- | | + | |
- | + | ||
- | + | ||
- | /* Test Direct Register Access methods */ | + | |
- | | + | |
- | + | ||
- | //Device ID: (dec)130 | + | |
- | + | ||
- | | + | |
- | | + | |
- | + | ||
- | //Reg 0x20: (dec)171 | + | |
- | + | ||
- | + | ||
- | /* List all device attributes */ | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | + | ||
- | + | ||
- | /* List all device scan elements */ | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | + | ||
- | + | ||
- | /* Disconnect Server */ | + | |
- | | + | |
- | } | + | |
- | </ | + | |
- | ==== C Client Library ==== | + | |
- | + | ||
- | === Source Code === | + | |
- | + | ||
- | ^ Source | + | |
- | | [[github> | + | |
- | + | ||
- | === Example Test Code === | + | |
- | + | ||
- | <code c> | + | |
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | #include " | + | |
- | + | ||
- | 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(" | + | |
- | if (ret) | + | |
- | perror(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | + | ||
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_send(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_send(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_read(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_sample(& | + | |
- | buf, 40, 4); | + | |
- | printf(" | + | |
- | for (i = 0; i < 40; i++) | + | |
- | printf(" | + | |
- | + | ||
- | + | ||
- | ret = iio_cmd_sample(& | + | |
- | buf, 40, 4); | + | |
- | printf(" | + | |
- | for (i = 0; i < 40; i++) | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regread(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regread(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regread(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regwrite(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regread(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regwrite(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_regread(& | + | |
- | printf(" | + | |
- | + | ||
- | ret = iio_cmd_bufwrite(& | + | |
- | buf, 400000); | + | |
- | printf(" | + | |
- | + | ||
- | return 0; | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | ==== Matlab Client Library ==== | + | |
- | + | ||
- | === Source Code === | + | |
- | + | ||
- | ^ Source | + | |
- | | [[github> | + | |
- | + | ||
- | === Example Test Code === | + | |
- | <code matlab> | + | |
- | clear all; | + | |
- | close all; | + | |
- | + | ||
- | obj = iio_cmdsrv; | + | |
- | + | ||
- | iio_cmdsrv_connect(obj, | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | ret = iio_cmd_send(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | ret = iio_cmd_send(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_read(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, rbuf] = iio_cmd_sample(obj, | + | |
- | sprintf(' | + | |
- | uint8(rbuf) | + | |
- | + | ||
- | [ret, val] = iio_cmd_regread(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, val] = iio_cmd_regread(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, val] = iio_cmd_regread(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | ret = iio_cmd_regwrite(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, val] = iio_cmd_regread(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | ret = iio_cmd_regwrite(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | [ret, val] = iio_cmd_regread(obj, | + | |
- | sprintf(' | + | |
- | + | ||
- | ret = iio_cmdsrv_disconnect(obj); | + | |
- | sprintf(' | + | |
- | </ | + |