My Project
Loading...
Searching...
No Matches
Context

Classes

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

Functions

struct iio_context * iio_create_context (const struct iio_context_params *params, const char *uri)
 Create a context from a URI description.
void iio_context_destroy (struct iio_context *ctx)
 Destroy the given context.
unsigned int iio_context_get_version_major (const struct iio_context *ctx)
 Get the major number of the library version.
unsigned int iio_context_get_version_minor (const struct iio_context *ctx)
 Get the minor number of the library version.
unsigned int iio_context_get_version_patch (const struct iio_context *ctx)
 Get the patch number of the library version.
const char * iio_context_get_version_tag (const struct iio_context *ctx)
 Get the git hash string of the library version.
char * iio_context_get_xml (const struct iio_context *ctx)
 Obtain a XML representation of the given context.
const char * iio_context_get_name (const struct iio_context *ctx)
 Get the name of the given context.
const char * iio_context_get_description (const struct iio_context *ctx)
 Get a description of the given context.
unsigned int iio_context_get_attrs_count (const struct iio_context *ctx)
 Get the number of context-specific attributes.
const struct iio_attr * iio_context_get_attr (const struct iio_context *ctx, unsigned int index)
 Retrieve the context-specific attribute at the given index.
const struct iio_attr * iio_context_find_attr (const struct iio_context *ctx, const char *name)
 Try to find a context-specific attribute by its name.
unsigned int iio_context_get_devices_count (const struct iio_context *ctx)
 Enumerate the devices found in the given context.
struct iio_device * iio_context_get_device (const struct iio_context *ctx, unsigned int index)
 Get the device present at the given index.
struct iio_device * iio_context_find_device (const struct iio_context *ctx, const char *name)
 Try to find a device structure by its ID, label or name.
int iio_context_set_timeout (struct iio_context *ctx, int timeout_ms)
 Set a timeout for I/O operations.
const struct iio_context_params * iio_context_get_params (const struct iio_context *ctx)
 Get a pointer to the params structure.
void iio_context_set_data (struct iio_context *ctx, void *data)
 Associate a pointer to an iio_context structure.
void * iio_context_get_data (const struct iio_context *ctx)
 Retrieve a previously associated pointer of an iio_context structure.
int iio_context_ping (struct iio_context *ctx)
 Ping the IIO context to check if it is still responsive.

Detailed Description

Function Documentation

◆ iio_context_destroy()

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_attr()

const struct iio_attr * iio_context_find_attr ( const struct iio_context * ctx,
const char * name )

Try to find a context-specific attribute by its name.

Parameters
ctxA pointer to an iio_context structure
nameA NULL-terminated string corresponding to the name of the attribute
Returns
On success, a pointer to an iio_attr structure
If the name does not correspond to any known attribute of the given context, NULL is returned.

◆ iio_context_find_device()

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

Try to find a device structure by its ID, label or name.

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

◆ iio_context_get_attr()

const struct iio_attr * iio_context_get_attr ( const struct iio_context * ctx,
unsigned int index )

Retrieve the context-specific attribute at the given index.

Parameters
ctxA pointer to an iio_context structure
indexThe index corresponding to the attribute
Returns
On success, a pointer to an iio_attr structure
If the index is out-of-range, NULL is returned

◆ iio_context_get_attrs_count()

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_data()

void * iio_context_get_data ( const struct iio_context * ctx)

Retrieve a previously associated pointer of an iio_context structure.

Parameters
ctxA pointer to an iio_context structure
Returns
The pointer previously associated if present, or NULL

◆ iio_context_get_description()

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

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

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

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_params()

const struct iio_context_params * iio_context_get_params ( const struct iio_context * ctx)

Get a pointer to the params structure.

Parameters
ctxA pointer to an iio_context structure
Returns
A pointer to the context's iio_context_params structure

◆ iio_context_get_version_major()

unsigned int iio_context_get_version_major ( const struct iio_context * ctx)

Get the major number of the library version.

Parameters
ctxOptional pointer to an iio_context structure
Returns
The major number

NOTE: If ctx is non-null, it will return the major version of the remote library, if running remotely.

◆ iio_context_get_version_minor()

unsigned int iio_context_get_version_minor ( const struct iio_context * ctx)

Get the minor number of the library version.

Parameters
ctxOptional pointer to an iio_context structure
Returns
The minor number

NOTE: If ctx is non-null, it will return the minor version of the remote library, if running remotely.

◆ iio_context_get_version_patch()

unsigned int iio_context_get_version_patch ( const struct iio_context * ctx)

Get the patch number of the library version.

Parameters
ctxOptional pointer to an iio_context structure
Returns
The patch number

NOTE: If ctx is non-null, it will return the patch version of the remote library, if running remotely. Returns 0 for older remote servers that don't report patch version.

◆ iio_context_get_version_tag()

const char * iio_context_get_version_tag ( const struct iio_context * ctx)

Get the git hash string of the library version.

Parameters
ctxOptional pointer to an iio_context structure
Returns
A NULL-terminated string that contains the git tag or hash

NOTE: If ctx is non-null, it will return the git tag or hash of the remote library, if running remotely.

◆ iio_context_get_xml()

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
On success, an allocated string. Must be deallocated with free().
On failure, a pointer-encoded error is returned

◆ iio_context_ping()

int iio_context_ping ( struct iio_context * ctx)

Ping the IIO context to check if it is still responsive.

Parameters
ctxA pointer to an iio_context structure
Returns
On success, 0 is returned
On error, a negative errno code is returned

NOTE: This performs a lightweight round-trip operation to verify the connection is still alive. It does not access hardware or change any device state. This operation is only meaningful for remote contexts (network, USB, serial). For local contexts, it always succeeds.

◆ iio_context_set_data()

void iio_context_set_data ( struct iio_context * ctx,
void * data )

Associate a pointer to an iio_context structure.

Parameters
ctxA pointer to an iio_context structure
dataThe pointer to be associated

◆ iio_context_set_timeout()

int iio_context_set_timeout ( struct iio_context * ctx,
int timeout_ms )

Set a timeout for I/O operations.

Parameters
ctxA pointer to an iio_context structure
timeout_msTimeout value in milliseconds:
  • IIO_TIMEOUT_BACKEND (0): use backend default timeout
  • IIO_TIMEOUT_INFINITE (-1): no timeout (wait indefinitely)
  • IIO_TIMEOUT_NONBLOCK (INT_MIN): non-blocking
  • Positive: timeout after specified milliseconds
  • Other negative values: returns -EINVAL
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_create_context()

struct iio_context * iio_create_context ( const struct iio_context_params * params,
const char * uri )

Create a context from a URI description.

Parameters
paramsA pointer to a iio_context_params structure that contains context creation information; can be NULL
uria URI describing the context location. If NULL, the backend will be created using the URI string present in the IIOD_REMOTE environment variable, or if not set, a local backend is created.
Returns
On success, a pointer to a iio_context structure
On failure, a pointer-encoded error is returned

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". To support alternative port numbers the standard ip:host:port format is used. A special format is required as defined in RFC2732 for IPv6 literal hostnames, (adding '[]' around the host) to use a ip:[x:x:x:x:x:x:x:x]:port format. Valid examples would be:
    • ip: Any host on default port
    • ip::40000 Any host on port 40000
    • ip:analog.local Default port
    • ip:brain.local:40000 Port 40000
    • ip:192.168.1.119 Default Port
    • ip:192.168.1.119:40000 Port 40000
    • ip:2601:190:400:da:47b3:55ab:3914:bff1 Default Port
    • ip:[2601:190:400:da:9a90:96ff:feb5:acaa]:40000 Port 40000
    • ip:fe80::f14d:3728:501e:1f94eth0 Link-local through eth0, default port
    • ip:[fe80::f14d:3728:501e:1f94eth0]:40000 Link-local through eth0, port 40000
  • 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"