libiio
Classes | Functions
Context

Classes

struct  iio_context
 Contains the representation of an IIO context. More...
 

Functions

__api struct iio_contextiio_create_default_context (void)
 Create a context from local or remote IIO devices. More...
 
__api struct iio_contextiio_create_local_context (void)
 Create a context from local IIO devices (Linux only) More...
 
__api struct iio_contextiio_create_xml_context (const char *xml_file)
 Create a context from a XML file. More...
 
__api struct iio_contextiio_create_xml_context_mem (const char *xml, size_t len)
 Create a context from XML data in memory. More...
 
__api struct iio_contextiio_create_network_context (const char *host)
 Create a context from the network. More...
 
__api struct iio_contextiio_create_context_from_uri (const char *uri)
 Create a context from a URI description. More...
 
__api struct iio_contextiio_context_clone (const struct iio_context *ctx)
 Duplicate a pre-existing IIO context. More...
 
__api void iio_context_destroy (struct iio_context *ctx)
 Destroy the given context. More...
 
__api 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 __pure const char * iio_context_get_xml (const struct iio_context *ctx)
 Obtain a XML representation of the given context. More...
 
__api __pure const char * iio_context_get_name (const struct iio_context *ctx)
 Get the name of the given context. More...
 
__api __pure const char * iio_context_get_description (const struct iio_context *ctx)
 Get a description of the given context. More...
 
__api __pure unsigned int iio_context_get_attrs_count (const struct iio_context *ctx)
 Get the number of context-specific attributes. More...
 
__api int iio_context_get_attr (const struct iio_context *ctx, unsigned int index, const char **name, const char **value)
 Retrieve the name and value of a context-specific attribute. More...
 
__api const char * iio_context_get_attr_value (const struct iio_context *ctx, const char *name)
 Retrieve the value of a context-specific attribute. More...
 
__api __pure unsigned int iio_context_get_devices_count (const struct iio_context *ctx)
 Enumerate the devices found in the given context. More...
 
__api __pure struct iio_deviceiio_context_get_device (const struct iio_context *ctx, unsigned int index)
 Get the device present at the given index. More...
 
__api __pure struct iio_deviceiio_context_find_device (const struct iio_context *ctx, const char *name)
 Try to find a device structure by its name of ID. More...
 
__api int iio_context_set_timeout (struct iio_context *ctx, unsigned int timeout_ms)
 Set a timeout for I/O operations. More...
 

Detailed Description

Function Documentation

§ iio_context_clone()

__api struct iio_context* iio_context_clone ( const struct iio_context ctx)

Duplicate a pre-existing IIO context.

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

§ iio_context_destroy()

__api void iio_context_destroy ( struct iio_context ctx)

Destroy the given context.

Parameters
ctxA pointer to an iio_context structure

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

§ iio_context_find_device()

__api __pure struct iio_device* iio_context_find_device ( const struct iio_context ctx,
const char *  name 
)

Try to find a device structure by its name of ID.

Parameters
ctxA pointer to an iio_context structure
nameA NULL-terminated string corresponding to the name or the ID of the device to search for
Returns
On success, a pointer to an iio_device structure
If the name or ID does not correspond to any known device, NULL is returned

§ iio_context_get_attr()

__api int iio_context_get_attr ( const struct iio_context ctx,
unsigned int  index,
const char **  name,
const char **  value 
)

Retrieve the name and value of a context-specific attribute.

Parameters
ctxA pointer to an iio_context structure
indexThe index corresponding to the attribute
nameA pointer to a const char * pointer (NULL accepted)
valueA pointer to a const char * pointer (NULL accepted)
Returns
On success, 0 is returned
On error, a negative errno code is returned

Introduced in version 0.9.

§ iio_context_get_attr_value()

__api const char* iio_context_get_attr_value ( const struct iio_context ctx,
const char *  name 
)

Retrieve the value of a context-specific attribute.

Parameters
ctxA pointer to an iio_context structure
nameThe name of the context attribute to read
Returns
On success, a pointer to a static NULL-terminated string
If the name does not correspond to any attribute, NULL is returned

Introduced in version 0.9.

§ iio_context_get_attrs_count()

__api __pure unsigned int iio_context_get_attrs_count ( const struct iio_context ctx)

Get the number of context-specific attributes.

Parameters
ctxA pointer to an iio_context structure
Returns
The number of context-specific attributes

Introduced in version 0.9.

§ iio_context_get_description()

__api __pure const char* iio_context_get_description ( const struct iio_context ctx)

Get a description of the given context.

Parameters
ctxA pointer to an iio_context structure
Returns
A pointer to a static NULL-terminated string

NOTE:The returned string will contain human-readable information about the current context.

§ iio_context_get_device()

__api __pure struct iio_device* iio_context_get_device ( const struct iio_context ctx,
unsigned int  index 
)

Get the device present at the given index.

Parameters
ctxA pointer to an iio_context structure
indexThe index corresponding to the device
Returns
On success, a pointer to an iio_device structure
If the index is invalid, NULL is returned

§ iio_context_get_devices_count()

__api __pure unsigned int iio_context_get_devices_count ( const struct iio_context ctx)

Enumerate the devices found in the given context.

Parameters
ctxA pointer to an iio_context structure
Returns
The number of devices found

§ iio_context_get_name()

__api __pure const char* iio_context_get_name ( const struct iio_context ctx)

Get the name of the given context.

Parameters
ctxA pointer to an iio_context structure
Returns
A pointer to a static NULL-terminated string

NOTE:The returned string will be local, xml or network when the context has been created with the local, xml and network backends respectively.

§ iio_context_get_version()

__api 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_get_xml()

__api __pure const char* iio_context_get_xml ( const struct iio_context ctx)

Obtain a XML representation of the given context.

Parameters
ctxA pointer to an iio_context structure
Returns
A pointer to a static NULL-terminated string

§ iio_context_set_timeout()

__api int iio_context_set_timeout ( struct iio_context ctx,
unsigned int  timeout_ms 
)

Set a timeout for I/O operations.

Parameters
ctxA pointer to an iio_context structure
timeout_msA positive integer representing the time in milliseconds after which a timeout occurs. A value of 0 is used to specify that no timeout should occur.
Returns
On success, 0 is returned
On error, a negative errno code is returned

§ iio_create_context_from_uri()

__api 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", "ip:localhost", "ip:"
  • USB backend, "usb:"
    Requires bus, address, and interface parts separated with a dot. For example "usb:3.32.5"
  • Serial backend, "serial:"
    Requires a port, baud_rate, parity ('n' none, 'o' odd, 'e' even, 'm' mark, 's' space), bits (8), and flow ('\0' none, 'x' Xon Xoff, 'r' RTSCTS, 'd' DTRDSR) parts separated with a comma. For example "serial:/dev/ttyUSB0,115200", "serial:/dev/ttyUSB0,115200,n,8,1"

§ iio_create_default_context()

__api 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 network context if the IIOD_REMOTE environment variable is set to the hostname where the IIOD server runs. If set to an empty string, the server will be discovered using ZeroConf. If the environment variable is not set, a local context will be created instead.

§ iio_create_local_context()

__api 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 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_xml_context()

__api 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_create_xml_context_mem()

__api struct iio_context* iio_create_xml_context_mem ( const char *  xml,
size_t  len 
)

Create a context from XML data in memory.

Parameters
xmlPointer to the XML data in memory
lenLength of the XML string in memory (excluding the final \0)
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