Libiio is a library that has been developed by Analog Devices to ease the development of software interfacing Linux Industrial I/O (IIO) devices.
The library abstracts the low-level details of the hardware, and provides a simple yet complete programming interface that can be used for advanced projects.
The library is composed by one high-level API, and several backends:
iiodserver through a network link.
The IIO Daemon (IIOD) server is a good example of an application that uses libiio. It creates a libiio context that uses the “local” backend, and then share it on the network to any client application using the “network” backend of libiio and connected to the server.
If you just want to use libiio and iiod, which may be on a pre-compiled image - there are many places you can stream data to.
The libiio library can be obtained on the Github page of the project.
Check out how to stay up to date. This will check out and build the latest version.
Building libiio is pretty straightforward.
The first step is to fetch the dependencies, which as of now is only libxml2. On a Debian-flavoured GNU/Linux distribution, like Ubuntu for instance:
rgetz@pinky:~$ sudo apt-get install libxml2 libxml2-dev bison flex libcdk5-dev cmake
Depending on the backend (how you want to attach the IIO device), you may need at least one of:
rgetz@pinky:~$ sudo apt-get install libaio-dev libusb-1.0-0-dev libserialport-dev libxml2-dev libavahi-client-dev doxygen graphviz
If you want to have local context attributes, its a good idea to install libini. This will allow reading of a local file in
/etc/libiio.ini for this purpose.
analog@pinky:~$ git clone https://github.com/pcercuei/libini.git analog@pinky:~$ cd libini analog@pinky:~/libini$ mkdir build && cd build && cmake ../ && make && sudo make install
Then, you can clone the GIT repository:
rgetz@pinky:~$ git clone https://github.com/analogdevicesinc/libiio.git
Finally, in the
rgetz@pinky:~/libiio$ cmake ./ rgetz@pinky:~/libiio$ make all rgetz@pinky:~/libiio$ sudo make install
This will build and install
/usr. Note that it is possible to install to a different location by setting the PREFIX variable.
To build iio oscilloscope you'll have to make sure libiio directories can be found, one way to do this given it installed to /usr/lib is add it to your sessions PATH:
During development, sometimes it can be a puzzle which version of libiio is being used. An easy way to tell is to do something like:
analog@imhotep:~/github/libiio$ git describe --tags v0.8-13-g6847e22
To check what is running:
analog@imhotep:~/github/libiio/build$ iio_info Library version: 0.8 (git tag: 6847e22) Unable to create IIO context
If you are running an application, and want to find out:
analog@imhotep:~/github/libiio/build$ strace -ofoo iio_info Library version: 0.8 (git tag: 6847e22) Unable to create IIO context analog@imhotep:~/github/libiio/build$ grep -e ^open foo | grep libiio open("./tls/x86_64/libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("./tls/libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("./x86_64/libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("./libiio.so.0", O_RDONLY|O_CLOEXEC) = 3 analog@imhotep:~/github/libiio/build$ ls -l ./libiio.so.0 lrwxrwxrwx 1 analog analog 13 Nov 15 10:36 ./libiio.so.0 -> libiio.so.0.8 analog@imhotep:~/github/libiio/build$ ls -l ./libiio.so.0.8 -rwxr-xr-x 1 analog analog 408432 Nov 15 10:36 ./libiio.so.0.8
This found a version in the same directory.
analog@imhotep:~$ strace -ofoo iio_info Library version: 0.8 (git tag: 6847e22) Unable to create IIO context analog@imhotep:~$ grep -e ^open foo | grep libiio open("./tls/x86_64/libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("./tls/libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("./x86_64/libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("./libiio.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("/usr/lib/x86_64-linux-gnu/libiio.so.0", O_RDONLY|O_CLOEXEC) = 3 analog@imhotep:~$ ls -l /usr/lib/x86_64-linux-gnu/libiio.so.0 lrwxrwxrwx 1 root root 13 Nov 9 21:05 /usr/lib/x86_64-linux-gnu/libiio.so.0 -> libiio.so.0.8 analog@imhotep:~$ ls -l /usr/lib/x86_64-linux-gnu/libiio.so.0.8 -rw-r--r-- 1 root root 408432 Nov 15 10:36 /usr/lib/x86_64-linux-gnu/libiio.so.0.8
This found the version in
If you want to cross-compile libiio, you can do so by passing the corresponding toolchain information file to cmake. Normally this is done by creating a toolchain file, and passing this to Cmake with a
-DCMAKE_TOOLCHAIN_FILE=path/to/file option, the file will be loaded early to set values for the compilers. This is described in the mainline cmake doc.
The instructions for building libiio with Visual Studio are available here: http://wiki.analog.com/resources/tools-software/linux-software/building_libiio_for_windows
In order to use the libIIO USB Backend - support must be built into IIOD. A simple check is shown below:
This specifies any shell prompt running on the target
root@analog:~# iiod -F foo ERROR: IIOD was not compiled with USB support.
In this case LibIIO / IIOD needs to be built with USBD support. (WITH_IIOD_USBD)
If all the dependencies are met, the USB Backend is built automatically. However the 'WITH_IIOD_USBD' option is only available under certain conditions.
In the log of cmake, if you see: Check size of struct usb_functionfs_descs_head_v2 - failed
Although your kernel itself probably is recent enough, your kernel headers are too old.
This specifies any shell prompt running on the target
root@analog:~# cd /usr/include/linux/usb root@analog:/usr/include/linux/usb# rm functionfs.h root@analog:/usr/include/linux/usb# wget https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/usb/functionfs.h
In order to use the libIIO USB Backend, the target must support USB Device Mode.
Kernel compiled with USB UDC Gadget support.
CONFIG_USB_CHIPIDEA=y CONFIG_USB_CHIPIDEA_UDC=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_XILINX=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_F_FS=y
Copy (and replace) iiod.conf upstart script into /etc/init
If everything works out well the USB context should be included in the available context list.
michael@mhenneri-D04:~/devel/pshare/iiod usb$ iio_info -s Library version: 0.10 (git tag: c95ff6a) Compiled with backends: local xml ip usb Available contexts: 0: Local devices [local:] 1: 0456:b671 (Analog Devices Inc. Generic USB IIOD), serial=00000000 [usb:1.36.0]
An automatically generated documentation of the API can be found here: http://analogdevicesinc.github.com/libiio/
Python and C# have official bindings available in the repository but third parties have developed others for more languages. Python and C# bindings documentation is available on the libiio internals page and within the API documentation.
See the dedicated page: About libiio.
|ad9361-iiostream.c||Configures the AD9361 transceiver, receives samples, processes them and sends them back out.|