libsigrok
unreleased development snapshot
sigrok hardware access and backend library
|
Device handling in libsigrok. More...
Functions | |
int | sr_dev_channel_name_set (struct sr_channel *channel, const char *name) |
Set the name of the specified channel. More... | |
int | sr_dev_channel_enable (struct sr_channel *channel, gboolean state) |
Enable or disable a channel. More... | |
gboolean | sr_dev_has_option (const struct sr_dev_inst *sdi, int key) |
Determine whether the specified device instance has the specified capability. More... | |
GArray * | sr_dev_options (const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) |
Enumerate the configuration options of the specified item. More... | |
int | sr_dev_config_capabilities_list (const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, const int key) |
Enumerate the configuration capabilities supported by a device instance for a given configuration key. More... | |
struct sr_dev_inst * | sr_dev_inst_user_new (const char *vendor, const char *model, const char *version) |
Allocate and init a new user-generated device instance. More... | |
int | sr_dev_inst_channel_add (struct sr_dev_inst *sdi, int index, int type, const char *name) |
Add a new channel to the specified device instance. More... | |
GSList * | sr_dev_list (const struct sr_dev_driver *driver) |
Get the list of devices/instances of the specified driver. More... | |
int | sr_dev_clear (const struct sr_dev_driver *driver) |
Clear the list of device instances a driver knows about. More... | |
int | sr_dev_open (struct sr_dev_inst *sdi) |
Open the specified device instance. More... | |
int | sr_dev_close (struct sr_dev_inst *sdi) |
Close the specified device instance. More... | |
struct sr_dev_driver * | sr_dev_inst_driver_get (const struct sr_dev_inst *sdi) |
Queries a device instances' driver. More... | |
const char * | sr_dev_inst_vendor_get (const struct sr_dev_inst *sdi) |
Queries a device instances' vendor. More... | |
const char * | sr_dev_inst_model_get (const struct sr_dev_inst *sdi) |
Queries a device instances' model. More... | |
const char * | sr_dev_inst_version_get (const struct sr_dev_inst *sdi) |
Queries a device instances' version. More... | |
const char * | sr_dev_inst_sernum_get (const struct sr_dev_inst *sdi) |
Queries a device instances' serial number. More... | |
const char * | sr_dev_inst_connid_get (const struct sr_dev_inst *sdi) |
Queries a device instances' connection identifier. More... | |
GSList * | sr_dev_inst_channels_get (const struct sr_dev_inst *sdi) |
Queries a device instances' channel list. More... | |
GSList * | sr_dev_inst_channel_groups_get (const struct sr_dev_inst *sdi) |
Queries a device instances' channel groups list. More... | |
Device handling in libsigrok.
int sr_dev_channel_enable | ( | struct sr_channel * | channel, |
gboolean | state | ||
) |
Enable or disable a channel.
[in] | channel | The channel to enable or disable. Must not be NULL. |
[in] | state | TRUE to enable the channel, FALSE to disable. |
Definition at line 144 of file device.c.
References sr_channel_group::channels, sr_channel::enabled, sr_channel::index, sr_channel::name, sr_channel_group::name, sr_channel_group::priv, sr_channel::sdi, SR_ERR_ARG, SR_OK, SR_PRIV, and sr_channel::type.
Referenced by sr_session_load().
int sr_dev_channel_name_set | ( | struct sr_channel * | channel, |
const char * | name | ||
) |
Set the name of the specified channel.
If the channel already has a different name assigned to it, it will be removed, and the new name will be saved instead.
[in] | channel | The channel whose name to set. Must not be NULL. |
[in] | name | The new name that the specified channel should get. A copy of the string is made. |
Definition at line 118 of file device.c.
References sr_channel::name, SR_ERR_ARG, and SR_OK.
Referenced by sr_session_load().
int sr_dev_clear | ( | const struct sr_dev_driver * | driver | ) |
Clear the list of device instances a driver knows about.
driver | The driver to use. This must be a pointer to one of the entries returned by sr_driver_list(). Must not be NULL. |
SR_OK | Success. |
SR_ERR_ARG | Invalid driver. |
Definition at line 687 of file device.c.
References sr_dev_driver::context, sr_dev_driver::dev_clear, SR_ERR_ARG, and SR_OK.
int sr_dev_close | ( | struct sr_dev_inst * | sdi | ) |
Close the specified device instance.
If the device instance is not open (sdi->status != SR_ST_ACTIVE), SR_ERR_DEV_CLOSED will be returned and no closing will be attempted.
Note: sdi->status will be set to SR_ST_INACTIVE, regardless of whether there are any errors during closing of the device instance (any errors will be reported via error code and log message, though).
sdi | Device instance to use. Must not be NULL. |
SR_OK | Success. |
SR_ERR_ARG | Invalid arguments. |
SR_ERR_DEV_CLOSED | Device instance was not active. |
SR_ERR | Other error. |
Definition at line 768 of file device.c.
References SR_ERR_ARG, SR_ERR_DEV_CLOSED, SR_ST_ACTIVE, and SR_ST_INACTIVE.
int sr_dev_config_capabilities_list | ( | const struct sr_dev_inst * | sdi, |
const struct sr_channel_group * | cg, | ||
const int | key | ||
) |
Enumerate the configuration capabilities supported by a device instance for a given configuration key.
sdi | Pointer to the device instance to be checked. Must not be NULL. If the device's 'driver' field is NULL (virtual device), this function will always return FALSE (virtual devices don't have a hardware capabilities list). | |
cg | Pointer to a channel group, if a specific channel group is to be checked. Must be NULL to check device-wide options. | |
[in] | key | The option that should be checked for is supported by the specified device. |
A | bitmask of enum sr_configcap values, which will be zero for invalid inputs or if the key is unsupported. |
Definition at line 425 of file device.c.
References SR_OK.
gboolean sr_dev_has_option | ( | const struct sr_dev_inst * | sdi, |
int | key | ||
) |
Determine whether the specified device instance has the specified capability.
sdi | Pointer to the device instance to be checked. Must not be NULL. If the device's 'driver' field is NULL (virtual device), this function will always return FALSE (virtual devices don't have a hardware capabilities list). | |
[in] | key | The option that should be checked for is supported by the specified device. |
TRUE | Device has the specified option. |
FALSE | Device does not have the specified option, invalid input parameters or other error conditions. |
Definition at line 333 of file device.c.
References SR_OK.
Add a new channel to the specified device instance.
[in] | sdi | Device instance to use. Must not be NULL. |
[in] | index | The index of this channel, starting at 0. Logic channels will be encoded according to this index in SR_DF_LOGIC packets. |
[in] | type | Channel type (SR_CHANNEL_LOGIC, ...) |
[in] | name | Name of channel. |
Definition at line 489 of file device.c.
References SR_ERR_ARG, SR_ERR_DATA, SR_INST_USER, SR_OK, SR_PRIV, and sr_session_dev_remove().
GSList* sr_dev_inst_channel_groups_get | ( | const struct sr_dev_inst * | sdi | ) |
GSList* sr_dev_inst_channels_get | ( | const struct sr_dev_inst * | sdi | ) |
const char* sr_dev_inst_connid_get | ( | const struct sr_dev_inst * | sdi | ) |
Queries a device instances' connection identifier.
sdi | Device instance to use. Must not be NULL. |
Definition at line 869 of file device.c.
References SR_INST_SCPI, SR_INST_SERIAL, and SR_INST_USB.
struct sr_dev_driver* sr_dev_inst_driver_get | ( | const struct sr_dev_inst * | sdi | ) |
const char* sr_dev_inst_model_get | ( | const struct sr_dev_inst * | sdi | ) |
const char* sr_dev_inst_sernum_get | ( | const struct sr_dev_inst * | sdi | ) |
struct sr_dev_inst* sr_dev_inst_user_new | ( | const char * | vendor, |
const char * | model, | ||
const char * | version | ||
) |
Allocate and init a new user-generated device instance.
vendor | Device vendor. |
model | Device model. |
version | Device version. |
struct | sr_dev_inst *. Dynamically allocated, free using sr_dev_inst_free(). |
Definition at line 463 of file device.c.
References SR_INST_USER.
const char* sr_dev_inst_vendor_get | ( | const struct sr_dev_inst * | sdi | ) |
const char* sr_dev_inst_version_get | ( | const struct sr_dev_inst * | sdi | ) |
GSList* sr_dev_list | ( | const struct sr_dev_driver * | driver | ) |
Get the list of devices/instances of the specified driver.
driver | The driver to use. Must not be NULL. |
Definition at line 668 of file device.c.
References sr_dev_driver::dev_list.
int sr_dev_open | ( | struct sr_dev_inst * | sdi | ) |
Open the specified device instance.
If the device instance is already open (sdi->status == SR_ST_ACTIVE), SR_ERR will be returned and no re-opening of the device will be attempted.
If opening was successful, sdi->status is set to SR_ST_ACTIVE, otherwise it will be left unchanged.
sdi | Device instance to use. Must not be NULL. |
SR_OK | Success. |
SR_ERR_ARG | Invalid arguments. |
SR_ERR | Device instance was already active, or other error. |
Definition at line 726 of file device.c.
References SR_ERR, SR_ERR_ARG, SR_OK, and SR_ST_ACTIVE.
GArray* sr_dev_options | ( | const struct sr_dev_driver * | driver, |
const struct sr_dev_inst * | sdi, | ||
const struct sr_channel_group * | cg | ||
) |
Enumerate the configuration options of the specified item.
driver | Pointer to the driver to be checked. Must not be NULL. |
sdi | Pointer to the device instance to be checked. May be NULL to check driver options. |
cg | Pointer to a channel group, if a specific channel group is to be checked. Must be NULL to check device-wide options. |
Definition at line 375 of file device.c.
References sr_dev_driver::config_list, and SR_OK.