0.x Compatibility API

libiio provides an optional compatibility layer, iio-compat, which implements the old libiio 0.x API on top of the current library. It exists to help existing applications keep building while they migrate to the version 1 API described in Library API; see Libiio 0.x to 1.x API update guide for a guide on porting away from it.

This compatibility layer is a separate library (libiio-compat, enabled with the LIBIIO_COMPAT build option) and is documented here on its own, rather than alongside the version 1 API.

struct iio_context *iio_create_default_context(void)

Create a context from local or remote IIO devices.

NOTE: This function will create a context with the URI provided in the IIOD_REMOTE environment variable. If not set, a local context will be created instead.

Returns:

On success, A pointer to an iio_context structure

Returns:

On failure, NULL is returned and errno is set appropriately

struct iio_context *iio_create_local_context(void)

Create a context from local IIO devices (Linux only)

Returns:

On success, A pointer to an iio_context structure

Returns:

On failure, NULL is returned and errno is set appropriately

struct iio_context *iio_create_network_context(const char *host)

Create a context from the network.

Parameters:

host – Hostname, IPv4 or IPv6 address where the IIO Daemon is running

Returns:

On success, a pointer to an iio_context structure

Returns:

On failure, NULL is returned and errno is set appropriately

struct iio_context *iio_create_xml_context(const char *xml_file)

Create a context from a XML file.

NOTE: The format of the XML must comply to the one returned by iio_context_get_xml.

Parameters:

xml_file – Path to the XML file to open

Returns:

On success, A pointer to an iio_context structure

Returns:

On failure, NULL is returned and errno is set appropriately

struct iio_context *iio_create_context_from_uri(const char *uri)

Create a context from a URI description.

NOTE: The following URIs are supported based on compile time backend support:

  • Local backend, “local:”

    Does not have an address part. For example

    ”local:”

  • XML backend, “xml:”

    Requires a path to the XML file for the address part. For example

    ”xml:/home/user/file.xml”

  • Network backend, “ip:”

    Requires a hostname, IPv4, or IPv6 to connect to a specific running IIO Daemon or no address part for automatic discovery when library is compiled with ZeroConf support. For example

    ”ip:192.168.2.1”, or “ip:localhost”, or “ip:” or “ip:plutosdr.local”

  • USB backend, “usb:”

    When more than one usb device is attached, requires bus, address, and interface parts separated with a dot. For example

    ”usb:3.32.5”. Where there is only one USB device attached, the shorthand “usb:” can be used.

  • Serial backend, “serial:”

    Requires:

    • a port (/dev/ttyUSB0),

    • baud_rate (default 115200)

    • serial port configuration

      • data bits (5 6 7 8 9)

      • parity (’n’ none, ‘o’ odd, ‘e’ even, ‘m’ mark, ‘s’ space)

      • stop bits (1 2)

      • flow control (’\0’ none, ‘x’ Xon Xoff, ‘r’ RTSCTS, ‘d’ DTRDSR)

    For example “serial:/dev/ttyUSB0,115200” or “serial:/dev/ttyUSB0,115200,8n1”

Parameters:

uri – A URI describing the context location

Returns:

On success, a pointer to a iio_context structure

Returns:

On failure, NULL is returned and errno is set appropriately

struct iio_scan_context *iio_create_scan_context(const char *backend, unsigned int flags)

Create a scan context.

Parameters:
  • backend – A NULL-terminated string containing the backend(s) to use for scanning (example: pre version 0.20 : “local”, “ip”, or “usb”; post version 0.20 can handle multiple, including “local:usb:”, “ip:usb:”, “local:usb:ip:”). If NULL, all the available backends are used.

  • flags – Unused for now. Set to 0.

Returns:

on success, a pointer to a iio_scan_context structure

Returns:

On failure, NULL is returned and errno is set appropriately

void iio_scan_context_destroy(struct iio_scan_context *ctx)

Destroy the given scan context.

NOTE: After that function, the iio_scan_context pointer shall be invalid.

Parameters:

ctx – A pointer to an iio_scan_context structure

ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx, struct iio_context_info ***info)

Enumerate available contexts.

Parameters:
  • ctx – A pointer to an iio_scan_context structure

  • info – A pointer to a ‘const struct iio_context_info **’ typed variable. The pointed variable will be initialized on success.

Returns:

On success, the number of contexts found.

Returns:

On failure, a negative error number.

void iio_context_info_list_free(struct iio_context_info **info)

Free a context info list.

Parameters:

info – A pointer to a ‘const struct iio_context_info *’ typed variable

const char *iio_context_info_get_description(const struct iio_context_info *info)

Get a description of a discovered context.

Parameters:

info – A pointer to an iio_context_info structure

Returns:

A pointer to a static NULL-terminated string

const char *iio_context_info_get_uri(const struct iio_context_info *info)

Get the URI of a discovered context.

Parameters:

info – A pointer to an iio_context_info structure

Returns:

A pointer to a static NULL-terminated string

struct iio_scan_block *iio_create_scan_block(const char *backend, unsigned int flags)

Create a scan block.

Introduced in version 0.20.

Parameters:
  • backend – A NULL-terminated string containing the backend to use for scanning. If NULL, all the available backends are used.

  • flags – Unused for now. Set to 0.

Returns:

on success, a pointer to a iio_scan_block structure

Returns:

On failure, NULL is returned and errno is set appropriately

void iio_scan_block_destroy(struct iio_scan_block *blk)

Destroy the given scan block.

NOTE: After that function, the iio_scan_block pointer shall be invalid.

Introduced in version 0.20.

Parameters:

blk – A pointer to an iio_scan_block structure

ssize_t iio_scan_block_scan(struct iio_scan_block *blk)

Enumerate available contexts via scan block.

Introduced in version 0.20.

Parameters:

blk – A pointer to a iio_scan_block structure.

Returns:

On success, the number of contexts found.

Returns:

On failure, a negative error number.

struct iio_context_info *iio_scan_block_get_info(struct iio_scan_block *blk, unsigned int index)

Get the iio_context_info for a particular context.

Introduced in version 0.20.

Parameters:
  • blk – A pointer to an iio_scan_block structure

  • index – The index corresponding to the context.

Returns:

A pointer to the iio_context_info for the context

Returns:

On success, a pointer to the specified iio_context_info

Returns:

On failure, NULL is returned and errno is set appropriately

void iio_library_get_version(unsigned int *major, unsigned int *minor, char git_tag[8])

Get the version of the libiio library.

Parameters:
  • major – A pointer to an unsigned integer (NULL accepted)

  • minor – A pointer to an unsigned integer (NULL accepted)

  • git_tag – A pointer to a 8-characters buffer (NULL accepted)

int iio_context_get_version(const struct iio_context *ctx, unsigned int *major, unsigned int *minor, char git_tag[8])

Get the version of the backend in use.

Parameters:
  • ctx – A pointer to an iio_context structure

  • major – A pointer to an unsigned integer (NULL accepted)

  • minor – A pointer to an unsigned integer (NULL accepted)

  • git_tag – A pointer to a 8-characters buffer (NULL accepted)

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned

int iio_device_set_kernel_buffers_count(const struct iio_device *dev, unsigned int nb_buffers)

Configure the number of kernel buffers for a device.

This function allows to change the number of buffers on kernel side.

Parameters:
  • dev – A pointer to an iio_device structure

  • nb_buffers – The number of buffers

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned