for (j = 0; j < ARRAY_SIZE(channel_names); j++)
sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
- channel_names[j]);
+ channel_names[j]);
devc = g_malloc0(sizeof(struct dev_context));
devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
struct sr_usb_dev_inst *usb;
struct libusb_device_descriptor des;
struct drv_context *drvc;
- int ret, i, device_count;
+ int ret = SR_ERR, i, device_count;
char connection_id[64];
di = sdi->driver;
drvc = di->context;
usb = sdi->conn;
- if (sdi->status == SR_ST_ACTIVE)
- /* Device is already in use. */
- return SR_ERR;
-
device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
if (device_count < 0) {
sr_err("Failed to get device list: %s.",
} else {
sr_err("Failed to open device: %s.",
libusb_error_name(ret));
+ ret = SR_ERR;
break;
}
if (ret == LIBUSB_ERROR_BUSY) {
sr_err("Unable to claim USB interface. Another "
"program or driver has already claimed it.");
+ ret = SR_ERR;
break;
} else if (ret == LIBUSB_ERROR_NO_DEVICE) {
sr_err("Device has been disconnected.");
+ ret = SR_ERR;
break;
} else if (ret != 0) {
sr_err("Unable to claim interface: %s.",
libusb_error_name(ret));
+ ret = SR_ERR;
break;
}
break;
}
- sdi->status = SR_ST_ACTIVE;
sr_info("Opened device on %d.%d (logical) / %s (physical), interface %d.",
usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
+ ret = SR_OK;
+
break;
}
+
libusb_free_device_list(devlist, 1);
- if (sdi->status != SR_ST_ACTIVE) {
+ if (ret != SR_OK) {
if (usb->devhdl) {
libusb_release_interface(usb->devhdl, USB_INTERFACE);
libusb_close(usb->devhdl);
struct sr_usb_dev_inst *usb;
usb = sdi->conn;
+
if (!usb->devhdl)
- return SR_ERR;
+ return SR_ERR_BUG;
sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
libusb_release_interface(usb->devhdl, USB_INTERFACE);
libusb_close(usb->devhdl);
usb->devhdl = NULL;
- sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
(void)cg;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
devc = sdi->priv;
ret = SR_OK;
unsigned char *buf;
size_t size, convsize;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
drvc = di->context;
devc = sdi->priv;
usb = sdi->conn;
usb_source_add(sdi->session, devc->ctx, timeout, receive_data, (void *)sdi);
- std_session_send_df_header(sdi, LOG_PREFIX);
+ std_session_send_df_header(sdi);
if ((ret = logic16_start_acquisition(sdi)) != SR_OK) {
abort_acquisition(devc);
{
int ret;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
ret = logic16_abort_acquisition(sdi);
abort_acquisition(sdi->priv);