libiio
Functions
Top-level functions

Functions

__api __check_ret struct iio_contextiio_create_default_context (void)
 Create a context from local or remote IIO devices. More...
 
__api __check_ret struct iio_contextiio_create_local_context (void)
 Create a context from local IIO devices (Linux only) More...
 
__api __check_ret struct iio_contextiio_create_network_context (const char *host)
 Create a context from the network. More...
 
__api __check_ret struct iio_contextiio_create_xml_context (const char *xml_file)
 Create a context from a XML file. More...
 
__api __check_ret struct iio_contextiio_create_context_from_uri (const char *uri)
 Create a context from a URI description. More...
 
__api __check_ret struct iio_scan_context * iio_create_scan_context (const char *backend, unsigned int flags)
 Create a scan context. More...
 
__api void iio_scan_context_destroy (struct iio_scan_context *ctx)
 Destroy the given scan context. More...
 
__api __check_ret ssize_t iio_scan_context_get_info_list (struct iio_scan_context *ctx, struct iio_context_info ***info)
 Enumerate available contexts. More...
 
__api void iio_context_info_list_free (struct iio_context_info **info)
 Free a context info list. More...
 
__api __check_ret __pure const char * iio_context_info_get_description (const struct iio_context_info *info)
 Get a description of a discovered context. More...
 
__api __check_ret __pure const char * iio_context_info_get_uri (const struct iio_context_info *info)
 Get the URI of a discovered context. More...
 
__api struct iio_scan_blockiio_create_scan_block (const char *backend, unsigned int flags)
 Create a scan block. More...
 
__api void iio_scan_block_destroy (struct iio_scan_block *blk)
 Destroy the given scan block. More...
 
__api ssize_t iio_scan_block_scan (struct iio_scan_block *blk)
 Enumerate available contexts via scan block. More...
 
__api struct iio_context_infoiio_scan_block_get_info (struct iio_scan_block *blk, unsigned int index)
 Get the iio_context_info for a particular context. More...
 
__api void iio_library_get_version (unsigned int *major, unsigned int *minor, char git_tag[8])
 Get the version of the libiio library. More...
 
__api __check_ret 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. More...
 
__api __check_ret 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. More...
 
__api void iio_strerror (int err, char *dst, size_t len)
 Get a string description of an error code. More...
 
__api __check_ret __cnst bool iio_has_backend (const char *backend)
 Check if the specified backend is available. More...
 
__api __check_ret __cnst unsigned int iio_get_backends_count (void)
 Get the number of available backends. More...
 
__api __check_ret __cnst const char * iio_get_backend (unsigned int index)
 Retrieve the name of a given backend. More...
 

Detailed Description

Function Documentation

◆ iio_context_get_version()

__api __check_ret 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
ctxA pointer to an iio_context structure
majorA pointer to an unsigned integer (NULL accepted)
minorA pointer to an unsigned integer (NULL accepted)
git_tagA pointer to a 8-characters buffer (NULL accepted)
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_context_info_get_description()

__api __check_ret __pure const char* iio_context_info_get_description ( const struct iio_context_info info)

Get a description of a discovered context.

Parameters
infoA pointer to an iio_context_info structure
Returns
A pointer to a static NULL-terminated string

◆ iio_context_info_get_uri()

__api __check_ret __pure const char* iio_context_info_get_uri ( const struct iio_context_info info)

Get the URI of a discovered context.

Parameters
infoA pointer to an iio_context_info structure
Returns
A pointer to a static NULL-terminated string

◆ iio_context_info_list_free()

__api void iio_context_info_list_free ( struct iio_context_info **  info)

Free a context info list.

Parameters
infoA pointer to a 'const struct iio_context_info *' typed variable

◆ iio_create_context_from_uri()

__api __check_ret struct iio_context* iio_create_context_from_uri ( const char *  uri)

Create a context from a URI description.

Parameters
uriA URI describing the context location
Returns
On success, a pointer to a iio_context structure
On failure, NULL is returned and errno is set appropriately

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"

◆ iio_create_default_context()

__api __check_ret struct iio_context* iio_create_default_context ( void  )

Create a context from local or remote IIO devices.

Returns
On success, A pointer to an iio_context structure
On failure, NULL is returned and errno is set appropriately

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.

◆ iio_create_local_context()

__api __check_ret 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
On failure, NULL is returned and errno is set appropriately

◆ iio_create_network_context()

__api __check_ret struct iio_context* iio_create_network_context ( const char *  host)

Create a context from the network.

Parameters
hostHostname, IPv4 or IPv6 address where the IIO Daemon is running
Returns
On success, a pointer to an iio_context structure
On failure, NULL is returned and errno is set appropriately

◆ iio_create_scan_block()

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

Create a scan block.

Parameters
backendA NULL-terminated string containing the backend to use for scanning. If NULL, all the available backends are used.
flagsUnused for now. Set to 0.
Returns
on success, a pointer to a iio_scan_block structure
On failure, NULL is returned and errno is set appropriately

Introduced in version 0.20.

◆ iio_create_scan_context()

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

Create a scan context.

Parameters
backendA 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.
flagsUnused for now. Set to 0.
Returns
on success, a pointer to a iio_scan_context structure
On failure, NULL is returned and errno is set appropriately

◆ iio_create_xml_context()

__api __check_ret struct iio_context* iio_create_xml_context ( const char *  xml_file)

Create a context from a XML file.

Parameters
xml_filePath to the XML file to open
Returns
On success, A pointer to an iio_context structure
On failure, NULL is returned and errno is set appropriately

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

◆ iio_device_set_kernel_buffers_count()

__api __check_ret 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
devA pointer to an iio_device structure
nb_buffersThe number of buffers
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_get_backend()

__api __check_ret __cnst const char* iio_get_backend ( unsigned int  index)

Retrieve the name of a given backend.

Parameters
indexThe index corresponding to the attribute
Returns
On success, a pointer to a static NULL-terminated string
If the index is invalid, NULL is returned

Introduced in version 0.9.

◆ iio_get_backends_count()

__api __check_ret __cnst unsigned int iio_get_backends_count ( void  )

Get the number of available backends.

Returns
The number of available backends

Introduced in version 0.9.

◆ iio_has_backend()

__api __check_ret __cnst bool iio_has_backend ( const char *  backend)

Check if the specified backend is available.

Parameters
backendThe name of the backend to query
Returns
True if the backend is available, false otherwise

Introduced in version 0.9.

◆ iio_library_get_version()

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

Get the version of the libiio library.

Parameters
majorA pointer to an unsigned integer (NULL accepted)
minorA pointer to an unsigned integer (NULL accepted)
git_tagA pointer to a 8-characters buffer (NULL accepted)

◆ iio_scan_block_destroy()

__api void iio_scan_block_destroy ( struct iio_scan_block blk)

Destroy the given scan block.

Parameters
blkA pointer to an iio_scan_block structure

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

Introduced in version 0.20.

◆ iio_scan_block_get_info()

__api 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.

Parameters
blkA pointer to an iio_scan_block structure
indexThe index corresponding to the context.
Returns
A pointer to the iio_context_info for the context
On success, a pointer to the specified iio_context_info
On failure, NULL is returned and errno is set appropriately

Introduced in version 0.20.

◆ iio_scan_block_scan()

__api ssize_t iio_scan_block_scan ( struct iio_scan_block blk)

Enumerate available contexts via scan block.

Parameters
blkA pointer to a iio_scan_block structure.
Returns
On success, the number of contexts found.
On failure, a negative error number.

Introduced in version 0.20.

◆ iio_scan_context_destroy()

__api void iio_scan_context_destroy ( struct iio_scan_context *  ctx)

Destroy the given scan context.

Parameters
ctxA pointer to an iio_scan_context structure

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

◆ iio_scan_context_get_info_list()

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

Enumerate available contexts.

Parameters
ctxA pointer to an iio_scan_context structure
infoA 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.
On failure, a negative error number.

◆ iio_strerror()

__api void iio_strerror ( int  err,
char *  dst,
size_t  len 
)

Get a string description of an error code.

Parameters
errThe error code
dstA pointer to the memory area where the NULL-terminated string corresponding to the error message will be stored
lenThe available length of the memory area, in bytes