2
0
forked from Ivasoft/DSView

The device can only be accessed by one process

This commit is contained in:
dreamsourcelabTAI
2023-05-11 10:36:52 +08:00
parent 1f8487e0f1
commit ae5c4e63c3
6 changed files with 45 additions and 13 deletions

View File

@@ -1826,7 +1826,8 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo
assert(usb->devhdl);
ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
if (ret != 0) {
if (ret != LIBUSB_SUCCESS) {
switch(ret) {
case LIBUSB_ERROR_BUSY:
sr_err("%s: Unable to claim USB interface. Another "
@@ -1848,12 +1849,13 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo
break;
}
if (ret != 0 && fdError == 1){
if (ret != LIBUSB_SUCCESS && fdError == 1){
sr_err("%s: Unable to claim interface, the second time: %s.",
__func__, libusb_error_name(ret));
}
if (ret != 0){
if (ret != LIBUSB_SUCCESS){
dsl_dev_close(sdi);
return SR_ERR;
}
}

View File

@@ -341,12 +341,15 @@ SR_API int ds_active_device(ds_device_handle handle)
struct sr_dev_inst *dev;
int bFind = 0;
int ret;
struct sr_dev_inst *old_dev;
if (handle == NULL_HANDLE)
{
return SR_ERR_ARG;
}
ret = SR_OK;
old_dev = NULL;
sr_info("%s", "Start activating device.");
@@ -371,6 +374,7 @@ SR_API int ds_active_device(ds_device_handle handle)
{
sr_info("Close the previous device \"%s\"", lib_ctx.actived_device_instance->name);
close_device_instance(lib_ctx.actived_device_instance);
old_dev = lib_ctx.actived_device_instance;
}
}
@@ -391,14 +395,25 @@ SR_API int ds_active_device(ds_device_handle handle)
else
sr_info("device name: \"%s\".", dev->name);
if (open_device_instance(dev) == SR_OK)
ret = open_device_instance(dev);
if (ret == SR_OK)
{
lib_ctx.actived_device_instance = dev;
}
else
{
sr_err("%s", "Open device error!");
ret = SR_ERR_CALL_STATUS;
{
if (old_dev != NULL && old_dev != dev){
sr_err("%s", "Open device error! the current device switch failed.");
lib_ctx.actived_device_instance = old_dev;
ret = open_device_instance(old_dev);
}
else if(lib_ctx.device_list != NULL){
old_dev = lib_ctx.device_list->data;
sr_err("%s", "Open device error! the current device switch to demo.");
lib_ctx.actived_device_instance = old_dev;
ret = open_device_instance(old_dev);
}
}
break;
}
@@ -1493,8 +1508,7 @@ static int open_device_instance(struct sr_dev_inst *dev)
if (driver_ins->dev_open)
{
driver_ins->dev_open(dev);
return SR_OK;
return driver_ins->dev_open(dev);
}
return SR_ERR_CALL_STATUS;