### CMake project setup and common library for libiio examples Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/CMakeLists.txt Sets the minimum CMake version, declares the example projects, and creates a common object library 'iiostream_helper' from 'iiostream-common.c', linking it to 'iio' and 'iio_common_config'. ```cmake cmake_minimum_required(VERSION 3.13) project(ad9361-iiostream C) project(ad9361-iioblock C) project(ad9371-iiostream C) project(adrv9009-iiostream C) project(dummy-iiostream C) project(adrv9002-iiostream C) add_library(iiostream_helper OBJECT iiostream-common.c) target_link_libraries(iiostream_helper PUBLIC iio iio_common_config) ``` -------------------------------- ### Install prerequisites and build libiio with Python bindings Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/tests/iiod/README.rst Install system packages (libxml2-dev, socat), build the libiio C library with the network backend (WITH_USB_BACKEND=OFF, HAVE_DNS_SD=OFF, WITH_AIO=OFF), install it, and install the Python bindings. Run from the libiio module root. ```console sudo apt-get install -y libxml2-dev socat # From the libiio module root (e.g. ~/zephyrproject/modules/lib/libiio) mkdir build && cd build cmake -DWITH_USB_BACKEND=OFF -DHAVE_DNS_SD=OFF -DWITH_AIO=OFF .. make -j$(nproc) sudo make install sudo ldconfig cd .. pip install bindings/python ``` -------------------------------- ### Windows: Install stunnel as a service Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Commands to install stunnel as a Windows service from an elevated command prompt, then start it. ```shell cd "C:\Program Files\stunnel" stunnel.exe -install -quiet net start stunnel ``` -------------------------------- ### Linux: Install to build doc Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Installs Doxygen and Graphviz for building documentation. ```shell analog@precision:~$ sudo apt-get install doxygen graphviz ``` -------------------------------- ### Comment about not installing examples Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/CMakeLists.txt States that examples are not installed, only built to ensure they compile and work. ```cmake # We don't install any of these, they are examples, not tools. We build them to # make sure they build/work, not to deploy them. ``` -------------------------------- ### Install libiio system-wide with CMake Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/README.rst Run this command from the build directory to install libiio system-wide. Note that a Windows system install requires additional steps (updating PATH, registering the DLL, etc.) outside the scope of this guide. ```console cmake --build . --target install ``` -------------------------------- ### Basic system setup: update and install build-essential Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Updates the package list and installs the essential build tools (build-essential) on Debian/Ubuntu systems. ```shell analog@precision:~$ sudo apt-get update analog@precision:~$ sudo apt-get install build-essential ``` -------------------------------- ### Install from source Source: https://github.com/analogdevicesinc/libiio/blob/main/bindings/python/README.md Clone the repository and install the bindings from the python bindings directory using pip. ```shell git clone https://github.com/analogdevicesinc/libiio.git cd libiio/bindings/python pip install . ``` -------------------------------- ### Install prerequisites Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs git and cmake, which are needed to clone and configure the libiio project. ```shell analog@precision:~$ sudo apt-get install git cmake ``` -------------------------------- ### Install to build documentation: doxygen, graphviz, pandoc, python3 Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs tools required to generate documentation. ```shell analog@precision:~$ sudo apt-get install doxygen graphviz pandoc analog@precision:~$ sudo apt-get install python3 python3-pip python3-venv ``` -------------------------------- ### Install libiio Python bindings from source Source: https://github.com/analogdevicesinc/libiio/blob/main/bindings/python/doc/index.rst Clone the libiio repository and install the Python bindings from the bindings/python directory using setup.py. Optionally prefix with sudo. ```bash git clone https://github.com/analogdevicesinc/libiio.git cd bindings/python (sudo) python3 setup.py install ``` -------------------------------- ### Run the TLS demo script Source: https://github.com/analogdevicesinc/libiio/blob/main/tests/stunnel/README.md Executes the tls_demo.sh script with no arguments. The script installs missing packages via sudo apt-get, builds iiod into ../../build-tls-demo, starts iiod and both stunnel processes, runs iio_info through the tunnel, then stops everything it started. Ports used: 30431 (iiod), 30432 (TLS), 40431 (client-side tunnel). ```shell ./tls_demo.sh ``` -------------------------------- ### macOS: Install Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Installs libiio system-wide using make install. ```shell sudo make install ``` -------------------------------- ### Install libserialport on openSUSE Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libserialport using zypper on openSUSE. ```shell sudo zypper install libserialport-devel ``` -------------------------------- ### Build and install libiio with network backend Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/README.rst Commands to build libiio from source with the network backend enabled and install it system-wide. Run from the libiio module root. Disables USB backend, DNS-SD, and AIO. Installs Python bindings afterwards. ```console # From the libiio module root (e.g. ~/zephyrproject/modules/lib/libiio) mkdir build && cd build cmake -DWITH_USB_BACKEND=OFF -DHAVE_DNS_SD=OFF -DWITH_AIO=OFF .. make -j$(nproc) sudo make install sudo ldconfig cd .. pip install bindings/python ``` -------------------------------- ### Install mdns with vcpkg Source: https://github.com/analogdevicesinc/libiio/blob/main/deps/mdns/README.md Install the mdns library using vcpkg, then use find_package with cmake. ```bash vcpkg install mdns ``` -------------------------------- ### Install libiio Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs the built library and headers to the system. Default prefix is /usr on Linux; override with CMAKE_INSTALL_PREFIX. ```shell analog@precision:~/libiio/build$ sudo make install ``` -------------------------------- ### CI integration example Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/tinyiiod-linux/tests/README.md Example GitHub Actions step to run the tinyiiod tests in a CI environment. ```yaml - name: Run tinyiiod tests run: | cd build ./examples/tinyiiod-linux/tests/run_tests.sh ``` -------------------------------- ### Install prerequisites: libxml2, libzstd, bison, flex, libcdk5, cmake Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs core build dependencies required for libiio compilation. ```shell analog@precision:~$ sudo apt-get install libxml2-dev libzstd-dev bison flex libcdk5-dev cmake ``` -------------------------------- ### Install libiio on Ubuntu with apt-get Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install.md Installs the libiio runtime library on Ubuntu using the distribution's package manager. ```bash sudo apt-get install libiio0 ``` -------------------------------- ### Linux: Start stunnel with command Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Command to start stunnel on Linux using the configuration file /etc/stunnel/iiod.conf. ```shell sudo stunnel /etc/stunnel/iiod.conf ``` -------------------------------- ### WDK/DDK sources file example Source: https://github.com/analogdevicesinc/libiio/blob/main/CI/scripts/README.txt Example sources file for compiling a libiio 1.0 console application with WDK/DDK. Assumes ..\libiio\ contains libiio.h and libiio.lib. ```text TARGETNAME=your_app TARGETTYPE=PROGRAM USE_MSVCRT=1 UMTYPE=console INCLUDES=..\libiio;$(DDK_INC_PATH) TARGETLIBS=..\libiio\libiio.lib SOURCES=your_app.c ``` -------------------------------- ### macOS: Install prerequisites Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Installs required dependencies for building libiio on macOS. ```shell brew install cmake libxml2 libzstd libusb libserialport zstd ``` -------------------------------- ### Install documentation dependencies Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs the Python packages required for building the documentation. ```shell (.venv) analog@precision:~/libiio$ pip install -r doc/requirements_doc.txt ``` -------------------------------- ### CMake configuration for C# examples Source: https://github.com/analogdevicesinc/libiio/blob/main/bindings/csharp/examples/CMakeLists.txt Configures C# examples, defines a helper function to build C# executables with mcs, and creates targets for three examples. Skips if mcs is not found. ```cmake cmake_minimum_required(VERSION 3.13) message(STATUS "Configuring C# examples") set(CSHARP_EXAMPLE_DIR "${CMAKE_CURRENT_BINARY_DIR}/csharp-example-bin") # Legacy Mono / .NET Framework examples (mcs/csc), built against the # mcs-built libiio-sharp.dll. if (MCS_EXECUTABLE) set(LIBIIO_SHARP_REF "${CMAKE_BINARY_DIR}/bindings/csharp/libiio-sharp.dll") file(TO_NATIVE_PATH ${LIBIIO_SHARP_REF} LIBIIO_SHARP_REF_NATIVE) # Builds a C# example executable and creates a custom target for it. # # add_csharp_example_target( # TARGET_NAME # custom target name # EXE_NAME # output executable filename # SOURCES ... # source .cs files # COMMENT # build comment shown by make # ) function (add_csharp_example_target) cmake_parse_arguments(ARG "" "TARGET_NAME;EXE_NAME;COMMENT" "SOURCES" ${ARGN}) set(EXE_PATH "${CSHARP_EXAMPLE_DIR}/${ARG_EXE_NAME}") set(SOURCES_NATIVE "") foreach (SRC ${ARG_SOURCES}) file(TO_NATIVE_PATH ${SRC} TMP) list(APPEND SOURCES_NATIVE ${TMP}) endforeach () file(TO_NATIVE_PATH ${EXE_PATH} EXE_PATH_NATIVE) add_custom_command( OUTPUT ${EXE_PATH} COMMAND ${CMAKE_COMMAND} -E make_directory ${CSHARP_EXAMPLE_DIR} COMMAND ${MCS_EXECUTABLE} /target:exe /langversion:5 /out:${EXE_PATH_NATIVE} /reference:${LIBIIO_SHARP_REF_NATIVE} ${SOURCES_NATIVE} DEPENDS ${ARG_SOURCES} libiio-sharp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "${ARG_COMMENT}") add_custom_target(${ARG_TARGET_NAME} ALL DEPENDS ${EXE_PATH}) endfunction () add_csharp_example_target( TARGET_NAME libiio-csharp-example-program EXE_NAME ExampleProgram.exe SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ExampleProgram.cs COMMENT "Building C# ExampleProgram") add_csharp_example_target( TARGET_NAME libiio-csharp-example-pluto EXE_NAME PlutoExample.exe SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/PlutoExample.cs COMMENT "Building C# PlutoExample") add_csharp_example_target( TARGET_NAME libiio-csharp-example-event EXE_NAME ExampleIIOEvent.exe SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ExampleIIOEvent.cs COMMENT "Building C# ExampleIIOEvent") add_custom_target( libiio-csharp-examples ALL DEPENDS libiio-csharp-example-program libiio-csharp-example-pluto libiio-csharp-example-event) message(STATUS "C# examples configured in: ${CSHARP_EXAMPLE_DIR}") else () message( STATUS "mcs/csc not found: skipping legacy Mono/.NET Framework C# examples" ) endif () ``` -------------------------------- ### Install libserialport on FreeBSD Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libserialport using pkg on FreeBSD. ```shell pkg install libserialport ``` -------------------------------- ### Install pylibiio via pip Source: https://github.com/analogdevicesinc/libiio/blob/main/bindings/python/README.md Install the Python bindings with pip. Requires the libiio library to be installed separately. ```shell (sudo) pip install pylibiio ``` -------------------------------- ### Install to build python backends: python3, pip, setuptools Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs Python packages needed for building Python backends. ```shell analog@precision:~$ sudo apt-get install python3 python3-pip python3-setuptools ``` -------------------------------- ### Start the tinyIIOD server Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/tinyiiod-linux/README.md Launches the server executable. The expected output shows the IIO context details and the listening port, along with a hint to connect using iio_info. ```bash ./tinyiiod-server ``` ```text tinyIIOD Linux reference server ================================ IIO context created: Backend: simple Description: Linux tinyIIOD reference Devices: 1 XML size: XXX bytes Server listening on port 30431 Connect with: iio_info -u ip:127.0.0.1 Press Ctrl+C to stop ``` -------------------------------- ### Install documentation dependencies with pip Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/CONTRIBUTING.md Install required Python packages for building the documentation. Run from the repository root. ```bash pip install -r doc/requirements_doc.txt ``` -------------------------------- ### Install libiio development package and utilities on Ubuntu Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install.md Installs the development headers and command-line utilities for libiio on Ubuntu. ```bash sudo apt-get install libiio-dev libiio-utils ``` -------------------------------- ### Define example executables and link libraries Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/CMakeLists.txt Creates executables for each example and links them to the common helper library or directly to iio, with special handling for ad9361-iioblock. ```cmake add_executable(ad9361-iiostream ad9361-iiostream.c ${LIBIIO_RC}) add_executable(ad9361-iioblock ad9361-iioblock.c ${LIBIIO_RC}) add_executable(ad9371-iiostream ad9371-iiostream.c ${LIBIIO_RC}) add_executable(adrv9009-iiostream adrv9009-iiostream.c ${LIBIIO_RC}) add_executable(adrv9002-iiostream adrv9002-iiostream.c ${LIBIIO_RC}) add_executable(dummy-iiostream dummy-iiostream.c ${LIBIIO_RC}) target_link_libraries(ad9361-iiostream iiostream_helper ${GETOPT_LIBRARIES}) target_link_libraries(ad9361-iioblock iio iio_common_config ${GETOPT_LIBRARIES}) # sigaction()/sigprocmask() are not exposed by a strict -std=c99 compilation target_compile_definitions(ad9361-iioblock PRIVATE _POSIX_C_SOURCE=200809L) target_link_libraries(ad9371-iiostream iiostream_helper ${GETOPT_LIBRARIES}) target_link_libraries(adrv9009-iiostream iiostream_helper ${GETOPT_LIBRARIES}) target_link_libraries(dummy-iiostream iiostream_helper ${GETOPT_LIBRARIES}) target_link_libraries(adrv9002-iiostream iiostream_helper ${GETOPT_LIBRARIES}) ``` -------------------------------- ### Install Python bindings from source Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/zephyr.md Install the pylibiio package from the libiio source tree in your west workspace. This is required because the PyPI package is still built against the v0.x API. ```shell cd /modules/lib/libiio/bindings/python pip install . ``` -------------------------------- ### Install Vale on Ubuntu/Debian Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/CONTRIBUTING.md Install Vale using apt-get on Ubuntu/Debian systems. ```bash sudo apt-get install vale ``` -------------------------------- ### Install pyadi-iio dependencies Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/README.rst Installs libxml2-dev and socat, required for building Python bindings from the libiio source tree. This is needed because pip install pyadi-iio installs a pre-built libiio that is typically v0.x, while the Zephyr IIOD server uses the v1.0 binary protocol. ```console sudo apt-get install -y libxml2-dev socat ``` -------------------------------- ### Install libraries for backends: libaio, libusb, libserialport, libavahi Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libraries needed for various backends (e.g., USB, serial, network). ```shell analog@precision:~$ sudo apt-get install libaio-dev libusb-1.0-0-dev analog@precision:~$ sudo apt-get install libserialport-dev libavahi-client-dev ``` -------------------------------- ### Set up formatting environment and run format.sh Source: https://github.com/analogdevicesinc/libiio/blob/main/CONTRIBUTING.md Creates a virtual environment, installs clang-format 18.1.8 and cmakelang 0.6.13, then runs the formatting script from the repository root. The script formats tracked C/header and CMake files, including new files added with git add, and respects .clangformatignore and .cmakeformatignore. Missing formatters or formatting errors cause a non-zero exit status. ```sh python3 -m venv /tmp/libiio-format-venv . /tmp/libiio-format-venv/bin/activate python -m pip install clang-format==18.1.8 cmakelang==0.6.13 ./format.sh ``` -------------------------------- ### Install stunnel and openssl on Linux (Debian/Ubuntu and RHEL/CentOS/Fedora) Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Install stunnel and openssl using the package manager. For Debian/Ubuntu use apt-get, for RHEL/CentOS/Fedora use yum. ```shell # Debian/Ubuntu sudo apt-get install stunnel4 openssl # RHEL/CentOS/Fedora sudo yum install stunnel openssl ``` -------------------------------- ### Install stunnel and openssl on macOS with Homebrew Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Install stunnel and openssl using Homebrew on macOS. ```shell brew install stunnel openssl ``` -------------------------------- ### Build libiio with man pages for documentation Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Builds and installs libiio with man page generation enabled, required for the documentation build. ```shell (.venv) analog@precision:~/libiio$ mkdir build && cd build (.venv) analog@precision:~/libiio/build$ cmake .. -DWITH_MAN=ON (.venv) analog@precision:~/libiio/build$ make (.venv) analog@precision:~/libiio/build$ sudo make install (.venv) analog@precision:~/libiio/build$ cd .. ``` -------------------------------- ### iio_rwdev -a output showing auto-detected context and examples Source: https://github.com/analogdevicesinc/libiio/blob/main/man/iio_rwdev.1.in When no device is provided, iio_rwdev prints a few examples. The output shows the auto-detected context URI and example commands for reading from the cf-ad9361-lpc device. ```text iio_rwdev -a Using auto-detected IIO context at URI "usb:3.10.5" Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage0 Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage1 Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage2 Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc voltage3 Example : iio_rwdev -u usb:3.10.5 -b 256 -s 1024 cf-ad9361-lpc ``` -------------------------------- ### Set list of example targets Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/CMakeLists.txt Defines the list of example targets built by default. ```cmake set(IIO_EXAMPLES_TARGETS ad9361-iiostream ad9361-iioblock ad9371-iiostream adrv9009-iiostream dummy-iiostream adrv9002-iiostream) ``` -------------------------------- ### Set custom installation prefix Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Configures libiio with a custom installation prefix using CMAKE_INSTALL_PREFIX. ```powershell cmake .. -G "Visual Studio 18 2026" -A x64 -DCMAKE_INSTALL_PREFIX="C:\libiio" ... ``` -------------------------------- ### Install libserialport on macOS (Homebrew) Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libserialport using Homebrew on macOS. ```shell brew install libserialport ``` -------------------------------- ### macOS: Start stunnel in foreground Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Command to start stunnel on macOS in the foreground for testing. ```shell stunnel /usr/local/etc/stunnel/iiod.conf ``` -------------------------------- ### Install libserialport on Arch Linux Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libserialport using pacman on Arch Linux. ```shell sudo pacman -S libserialport ``` -------------------------------- ### Install ARM toolchain for cross-compiling Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs the ARM cross-compilation toolchain required for building libiio for microcontroller targets. ```shell analog@precision:~$ sudo apt-get install gcc-arm-none-eabi ``` -------------------------------- ### macOS: Install optional dependencies for documentation and Python bindings Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Installs optional tools and Python packages for building documentation and Python bindings. ```shell brew install doxygen ncurses cdk sphinx-doc pkg-config pip3 install sphinx setuptools ``` -------------------------------- ### Install libserialport on Alpine Linux Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libserialport using apk on Alpine Linux. ```shell apk add libserialport-dev ``` -------------------------------- ### macOS: Install libiio via Homebrew formula Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Installs libiio using the Homebrew formula from tfcollins. ```shell brew install tfcollins/libiio ``` -------------------------------- ### Build libiio with C# bindings enabled Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/api/csharp/index.rst Commands to build libiio with C# bindings enabled using CMake, then make and install. ```bash cmake -DCSHARP_BINDINGS=ON .. make make install ``` -------------------------------- ### Install libiio to default location Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs libiio to the default location (C:\Program Files\libiio) using CMake. ```powershell cmake --build . --config RelWithDebInfo --target install ``` -------------------------------- ### Example: Use reserved heap Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Sets the DMA heap to 'reserved' and runs an IIO application. This is one of the accepted values. ```bash export LIBIIO_DMA_HEAP_PATH=reserved ./an_iio_application ``` -------------------------------- ### Add tinyiiod-linux example subdirectory on Linux Source: https://github.com/analogdevicesinc/libiio/blob/main/CMakeLists.txt This snippet adds the examples/tinyiiod-linux subdirectory when WITH_LIBTINYIIOD is enabled and the system is Linux. ```cmake if (WITH_LIBTINYIIOD AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux") add_subdirectory(examples/tinyiiod-linux) endif () ``` -------------------------------- ### OPEN command syntax Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/theory.md Used to open a device from the network. The client thread registers as a potential customer for capturing or uploading samples. If the client is the first to open the device, a new R/W thread is started. The buffer is recreated when a new client opens the device to match the highest sample count and channel mask. ```text OPEN [CYCLIC] ``` -------------------------------- ### Low-level buffer stream API: start, enqueue, dequeue, stop Source: https://github.com/analogdevicesinc/libiio/blob/main/mainpage.dox Shows the low-level streaming workflow: open a buffer stream, create a block, start the stream, and loop with iio_block_enqueue() and iio_block_dequeue(). Stop by destroying the block and closing the stream. ```c struct iio_buffer *buf = iio_device_get_buffer(dev, 0); struct iio_buffer_stream *stream = iio_buffer_open(buf, mask); struct iio_block *block = iio_buffer_stream_create_block(stream, block_size); iio_buffer_stream_start(stream); /* Streaming loop */ while (!stop) { iio_block_enqueue(block, 0, false); iio_block_dequeue(block, false); /* Process samples via iio_block_start()/iio_block_end() */ } iio_block_destroy(block); iio_buffer_close(stream); ``` -------------------------------- ### Set up Python virtual environment for documentation Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Creates and activates a Python virtual environment for building documentation. ```shell analog@precision:~/libiio$ python3 -m venv .venv analog@precision:~/libiio$ source .venv/bin/activate ``` -------------------------------- ### CMake configuration for mdns library and example Source: https://github.com/analogdevicesinc/libiio/blob/main/deps/mdns/CMakeLists.txt Defines the mdns INTERFACE library with include directories and platform-specific link libraries (iphlpapi, ws2_32 on Windows), an optional example executable, and installation rules for the library, headers, and CMake package config files. ```cmake cmake_minimum_required(VERSION 3.5) project(mdns VERSION 1.4.2 LANGUAGES C) option(MDNS_BUILD_EXAMPLE "build example" ON) # Set the output of the libraries and executables. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) # ############################################################################## # library # ############################################################################## include(GNUInstallDirs) add_library(${PROJECT_NAME} INTERFACE) target_include_directories( ${PROJECT_NAME} INTERFACE $ $) if(WIN32) target_link_libraries(${PROJECT_NAME} INTERFACE iphlpapi ws2_32) endif() add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_compile_features(${PROJECT_NAME} INTERFACE c_std_99) # ############################################################################## # example # ############################################################################## if(MDNS_BUILD_EXAMPLE) add_executable(${PROJECT_NAME}_example mdns.c) target_link_libraries(${PROJECT_NAME}_example ${PROJECT_NAME}) endif() # ############################################################################## # install # ############################################################################## install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}_Targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) include(CMakePackageConfigHelpers) if(${CMAKE_VERSION} VERSION_LESS 3.14) write_basic_package_version_file( "${PROJECT_NAME}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) else() write_basic_package_version_file( "${PROJECT_NAME}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) endif() configure_package_config_file( "${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}) install( EXPORT ${PROJECT_NAME}_Targets FILE ${PROJECT_NAME}Targets.cmake NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}) install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}) install(FILES "${PROJECT_SOURCE_DIR}/mdns.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ``` -------------------------------- ### Linux stunnel client configuration and start command Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Configuration file for stunnel client on Linux, located at /etc/stunnel/iiod.conf. It sets client mode, listens on 127.0.0.1:30431, connects to the server at :30432, and verifies the server certificate using CAfile and checkHost. Start stunnel with the command 'sudo stunnel /etc/stunnel/iiod.conf'. ```ini pid = /var/run/stunnel-iiod-client.pid foreground = no [iiod] client = yes accept = 127.0.0.1:30431 connect = :30432 CAfile = /etc/stunnel/certs/server.crt verifyChain = yes checkHost = ``` ```shell sudo stunnel /etc/stunnel/iiod.conf ``` -------------------------------- ### Linux: Enable systemd service Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Command to enable and start the stunnel systemd service. ```shell sudo systemctl enable --now stunnel-iiod.service ``` -------------------------------- ### macOS stunnel client configuration and start command Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/tls_userguide.md Configuration file for stunnel client on macOS, located at /usr/local/etc/stunnel/iiod.conf. It sets client mode, listens on 127.0.0.1:30431, connects to the server at :30432, and verifies the server certificate using CAfile and checkHost. Start stunnel with the command 'stunnel /usr/local/etc/stunnel/iiod.conf'. ```ini foreground = yes [iiod] client = yes accept = 127.0.0.1:30431 connect = :30432 CAfile = /usr/local/etc/stunnel/certs/server.crt verifyChain = yes checkHost = ``` ```shell stunnel /usr/local/etc/stunnel/iiod.conf ``` -------------------------------- ### iio_buffer_stream_start Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/migration.md Starts the streaming process for the buffer stream. ```APIDOC ## iio_buffer_stream_start ### Description Starts the streaming process for the buffer stream. ### Parameters - **stream** (iio_buffer_stream *) - Required - Pointer to the buffer stream. ### Returns - **int** - 0 on success, or a negative error code on failure. ``` -------------------------------- ### Example: Use default_cma_region heap Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Sets the DMA heap to 'default_cma_region' and runs an IIO application. This is one of the accepted values. ```bash export LIBIIO_DMA_HEAP_PATH=default_cma_region ./an_iio_application ``` -------------------------------- ### Install Vale on macOS Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/CONTRIBUTING.md Install Vale using Homebrew on macOS. ```bash brew install vale ``` -------------------------------- ### Run specific test binaries directly Source: https://github.com/analogdevicesinc/libiio/blob/main/tests/README.md Execute individual test binaries directly from the build directory. Examples include test_context and test_buffer. ```bash ./tests/api/test_context ./tests/api/test_buffer # ... etc ``` -------------------------------- ### Iterate over samples with a for loop using iio_block_first and iio_block_end Source: https://github.com/analogdevicesinc/libiio/blob/main/mainpage.dox Iterates over sample slots for a single channel using iio_block_first() for the start, iio_block_end() for the end, and iio_device_get_sample_size() for the step. Useful for channel-by-channel processing. ```c size_t step = iio_device_get_sample_size(dev, mask); for (void *ptr = iio_block_first(block, channel); ptr < iio_block_end(block); ptr += step) { /* Use "ptr" to read or write a sample for this channel */ } ``` -------------------------------- ### CMake build and test setup for hardware tests Source: https://github.com/analogdevicesinc/libiio/blob/main/tests/hardware/CMakeLists.txt Iterates over TEST_SOURCES, creates an executable for each, links it to the iio library, and registers a CTest test with the 'hardware' label. If WITH_GCOV is enabled, it calls enable_coverage for the test. ```cmake set(TEST_SOURCES test_ad9364.c) foreach (TEST_SRC ${TEST_SOURCES}) get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE) add_executable(${TEST_NAME} ${TEST_SRC}) target_link_libraries(${TEST_NAME} LINK_PRIVATE iio) add_test( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set_tests_properties(${TEST_NAME} PROPERTIES LABELS "hardware") if (WITH_GCOV) enable_coverage(${TEST_NAME}) endif () endforeach () ``` -------------------------------- ### Back up Scopy's bundled libiio DLLs Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/README.rst Backs up the original libiio.dll and iio1.dll from the Scopy installation directory (e.g., C:\Analog Devices\Scopy) before overwriting them with freshly built DLLs. ```console copy "C:\Analog Devices\Scopy\libiio.dll" libiio.dll.bak copy "C:\Analog Devices\Scopy\iio1.dll" iio1.dll.bak ``` -------------------------------- ### Install libserialport on Debian/Ubuntu Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Installs the libserialport development package on Debian/Ubuntu systems. ```shell sudo apt-get install libserialport-dev ``` -------------------------------- ### CMake build configuration for libini Source: https://github.com/analogdevicesinc/libiio/blob/main/deps/libini/CMakeLists.txt Defines the libini project with CMake 3.10, sets build type to RelWithDebInfo by default, and configures shared/static library options. Generates libini.pc and python/setup.py from templates, builds the ini library with hidden visibility on GCC, and optionally builds a test executable if example/test.c exists. Installs the library, headers, and pkg-config file. ```cmake cmake_minimum_required(VERSION 3.10) project(libini LANGUAGES C VERSION 0.1) include(GNUInstallDirs) if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE ) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Release RelWithDebInfo MinSizeRel) endif() set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries") if (NOT BUILD_SHARED_LIBS) set(INI_STATIC_CFLAGS -Dlibini_STATIC) endif (NOT BUILD_SHARED_LIBS) set(LIBINI_PC ${CMAKE_CURRENT_BINARY_DIR}/libini.pc) configure_file(libini.pc.cmakein ${LIBINI_PC} @ONLY) install(FILES ${LIBINI_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py) configure_file(python/setup.py.cmakein ${SETUP_PY} @ONLY) set(LIBINI_CFILES libini.c) set(LIBINI_HEADERS ini.h) if (CMAKE_COMPILER_IS_GNUCC AND NOT WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") endif() add_library(ini ${LIBINI_CFILES} ${LIBINI_HEADERS}) set_target_properties(ini PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} PUBLIC_HEADER ${LIBINI_HEADERS} ) target_compile_definitions(ini PUBLIC ${INI_STATIC_CFLAGS}) if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/example/test.c") add_executable(libini_test example/test.c) target_link_libraries(libini_test PRIVATE ini) target_include_directories(libini_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(libini_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) endif() install(TARGETS ini ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) ``` -------------------------------- ### Build HTML documentation with make html Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/CONTRIBUTING.md Build the HTML documentation from the doc directory. Output is placed in doc/build/html/. ```bash cd doc make html ``` -------------------------------- ### CMake configuration for .NET bindings build Source: https://github.com/analogdevicesinc/libiio/blob/main/bindings/csharp/CMakeLists.txt This CMake snippet checks for the dotnet executable and, if found, configures the build of the libiio-sharp.dll using the dotnet build command. It sets up output directories, defines a custom command and target, and optionally installs the DLL. If the .NET SDK is not found, it prints a status message and skips the .NET bindings variant. ```cmake # .NET build (dotnet), independent of whether mcs/csc is available. if (DOTNET_EXECUTABLE) message( STATUS "Found .NET SDK ${DOTNET_SDK_VERSION}: Building the ${LIBIIO_CS_NET_TFM} bindings variant" ) set(LIBIIO_CS_NET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LIBIIO_CS_NET_TFM}") set(LIBIIO_CS_NET_DLL "${LIBIIO_CS_NET_OUT_DIR}/libiio-sharp.dll") add_custom_command( OUTPUT ${LIBIIO_CS_NET_DLL} COMMAND ${DOTNET_EXECUTABLE} build ${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp-net.csproj -c Release -o ${LIBIIO_CS_NET_OUT_DIR} -p:Version=${LIBIIO_CS_VERSION} -p:LibiioSharpTfm=${LIBIIO_CS_NET_TFM} DEPENDS ${LIBIIO_CS_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp-net.csproj WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) add_custom_target(libiio-sharp-dotnet ALL DEPENDS ${LIBIIO_CS_NET_DLL}) if (NOT SKIP_INSTALL_ALL) install( FILES ${LIBIIO_CS_NET_DLL} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION}/${LIBIIO_CS_NET_TFM} ) endif () else () message(STATUS ".NET SDK not found: skipping the .NET bindings variant") endif () add_subdirectory(examples) ``` -------------------------------- ### macOS: Install Homebrew Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Installs Homebrew, the package manager used for macOS builds. ```shell /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### List devices and attributes with iio_info Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/tinyiiod-linux/README.md Connects to the server and lists devices and attributes. The expected output shows the simple backend context and the two device-specific attributes (name and test_value). ```bash iio_info -u ip:127.0.0.1 ``` ```text Library version: X.Y (git tag: ...) Compiled with backends: local xml ip usb serial IIO context created with simple backend. Backend version: X.Y (git tag: ...) Backend description string: Linux tinyIIOD reference IIO context has 1 devices: iio:device0: simple0 2 device-specific attributes found: attr 0: name value: Simple IIO Device attr 1: test_value value: 42 ``` -------------------------------- ### View the documentation Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Opens the built HTML documentation in the default browser. ```shell (.venv) analog@precision:~/libiio/doc$ xdg-open build/html/index.html ``` -------------------------------- ### Connect to Ethernet Context and List Devices Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/examples.md Creates a libiio context over Ethernet, retrieves the device count, and prints each device name. Error handling is omitted for brevity; always check return values in real applications. ```c #include #include int main() { struct iio_context *ctx; struct iio_device *dev; struct iio_device **devices; int i, ndevices; ctx = iio_create_context(NULL, "ip:analog.local"); ndevices = iio_context_get_devices_count(ctx); for (i = 0; i < ndevices; i++) { dev = iio_context_get_device(ctx, i); printf("Device %d: %s\n", i, iio_device_get_name(dev)); } iio_context_destroy(ctx); return 0; } ``` -------------------------------- ### Build iio_info from source and connect Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/zephyr.md Builds iio_info from the west-managed libiio checkout because the distribution's iio-utils is v0.x-based. WITH_UTILS defaults to ON, so iio_info is produced alongside the library. Then connects to the running server via IP. ```shell cd /modules/lib/libiio mkdir build && cd build cmake -DWITH_TESTS=ON -DHAVE_DNS_SD=OFF -DWITH_AIO=OFF .. make -j$(nproc) ./utils/iio_info -u ip:127.0.0.1 ``` -------------------------------- ### Create libiio contexts for local, network, USB, and serial backends Source: https://github.com/analogdevicesinc/libiio/blob/main/bindings/csharp/mainpage.dox Shows how to create a libiio context for different backends: local, network (ip:), USB (usb:), and serial (serial:). The context is the entry point for accessing IIO devices. ```csharp // Local context (uses the local IIO devices) Context ctx = new Context(); // Network context (connect to a remote iiod server) Context ctx = new Context("ip:192.168.1.10"); // USB context (connect via USB) Context ctx = new Context("usb:1.2.3"); // Serial context Context ctx = new Context("serial:/dev/ttyUSB0,115200"); ``` -------------------------------- ### Build the documentation Source: https://github.com/analogdevicesinc/libiio/blob/main/README_BUILD.md Converts man pages to RST and builds the HTML documentation. ```shell (.venv) analog@precision:~/libiio$ cd doc (.venv) analog@precision:~/libiio/doc$ python man_to_rst.py (.venv) analog@precision:~/libiio/doc$ make html ``` -------------------------------- ### Build IIO client utilities (iio_info, iio_attr) on Linux Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/README.rst Builds the iio_info and iio_attr client utilities on a Linux host. Navigate to the libiio module directory in the west workspace (e.g., ~/zephyrproject/modules/lib/libiio) and run these commands. ```console mkdir build_x86_64 cd build_x86_64 cmake -DWITH_SERIAL_BACKEND=ON ../ make -j $(nproc) ``` -------------------------------- ### Build libiio on Windows with MinGW64 Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/README.rst Build the libiio library on Windows using MinGW64. This enables the USB, serial, and network backends for use with the IIO demo. ```console cd /c/libiio mkdir build-host cd build-host cmake .. -G "MinGW Makefiles" \ -DLIBIIO_COMPAT=ON \ -DWITH_SERIAL_BACKEND=ON \ -DWITH_NETWORK_BACKEND=ON \ -DWITH_USB_BACKEND=ON cmake --build . ``` -------------------------------- ### Set C standard properties for example targets Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/CMakeLists.txt Sets the C standard to C99 with required and extensions off for all example targets. ```cmake set_target_properties( ${IIO_EXAMPLES_TARGETS} PROPERTIES C_STANDARD 99 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF) ``` -------------------------------- ### Linux: Build with CMake Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Creates a build directory, configures with CMake, and compiles libiio. ```shell analog@precision:~/libiio$ mkdir build analog@precision:~/libiio$ cd build analog@precision:~/libiio/build$ cmake ../ analog@precision:~/libiio/build$ make ``` -------------------------------- ### CMakeLists.txt for libiio IIOD sample Source: https://github.com/analogdevicesinc/libiio/blob/main/zephyr/samples/iiod/CMakeLists.txt Configures the Zephyr build for the IIOD sample. Adds adc-emul.overlay and adc-emul.conf when CONFIG_LIBIIO_IIOD_ADC_EMUL is set, sensor-emul.overlay and sensor-emul.conf for CONFIG_LIBIIO_IIOD_SENSOR_EMUL, and multi-sensor-emul.overlay with sensor-emul.conf for CONFIG_LIBIIO_IIOD_MULTI_SENSOR_EMUL. Requires CMake 3.20.0 and Zephyr, and builds the application from src/main.c. ```cmake # Copyright (c) 2025 Analog Devices, Inc. # SPDX-License-Identifier: MIT cmake_minimum_required(VERSION 3.20.0) if(CONFIG_LIBIIO_IIOD_ADC_EMUL) list(APPEND EXTRA_DTC_OVERLAY_FILE adc-emul.overlay) list(APPEND EXTRA_CONF_FILE adc-emul.conf) endif() if(CONFIG_LIBIIO_IIOD_SENSOR_EMUL) list(APPEND EXTRA_DTC_OVERLAY_FILE sensor-emul.overlay) list(APPEND EXTRA_CONF_FILE sensor-emul.conf) endif() if(CONFIG_LIBIIO_IIOD_MULTI_SENSOR_EMUL) list(APPEND EXTRA_DTC_OVERLAY_FILE multi-sensor-emul.overlay) list(APPEND EXTRA_CONF_FILE sensor-emul.conf) endif() find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(iiod) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Windows: Set up Visual Studio environment Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Runs the vcvars64.bat script to set up the Visual Studio build environment. The path may vary with your Visual Studio version. ```powershell C:\> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" ``` -------------------------------- ### Windows: Download dependencies Source: https://github.com/analogdevicesinc/libiio/blob/main/doc/source/install/source.md Downloads and extracts the libiio dependencies zip file on Windows. ```powershell mkdir C:\libiio-deps cd C:\libiio-deps Invoke-WebRequest -Uri https://swdownloads.analog.com/cse/build/libiio-deps-20220517.zip -OutFile libiio-deps-20220517.zip Expand-Archive -Path libiio-deps-20220517.zip -DestinationPath . ``` -------------------------------- ### Build tinyIIOD server with CMake Source: https://github.com/analogdevicesinc/libiio/blob/main/examples/tinyiiod-linux/README.md Commands to configure and build the project with libtinyIIOD enabled. The executable is produced at examples/tinyiiod-linux/tinyiiod-server. ```bash cd libiio mkdir build && cd build cmake -DWITH_LIBTINYIIOD=ON .. make ```