mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-13 13:32:53 +08:00
fix usb2.0 device alaim interface error bug
This commit is contained in:
parent
82da3a6acd
commit
092827434e
@ -38,6 +38,8 @@
|
||||
#include "config.h"
|
||||
#include "pv/appcontrol.h"
|
||||
|
||||
//#include <libsigrok4DSL/libsigrok.h>
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stdout,
|
||||
@ -54,6 +56,8 @@ void usage()
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// sr_test_usb_api();return 0;
|
||||
|
||||
int ret = 0;
|
||||
const char *open_file = NULL;
|
||||
|
||||
|
@ -1779,6 +1779,7 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo
|
||||
int ret;
|
||||
uint8_t hw_info;
|
||||
struct ctl_rd_cmd rd_cmd;
|
||||
int fdError = 0;
|
||||
|
||||
devc = sdi->priv;
|
||||
usb = sdi->conn;
|
||||
@ -1799,7 +1800,7 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo
|
||||
sr_err("%s: Unable to open device.", __func__);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
|
||||
ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
|
||||
if (ret != 0) {
|
||||
switch(ret) {
|
||||
@ -1810,13 +1811,27 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo
|
||||
case LIBUSB_ERROR_NO_DEVICE:
|
||||
sr_err("%s: Device has been disconnected.", __func__);
|
||||
break;
|
||||
case LIBUSB_ERROR_NOT_FOUND:
|
||||
{
|
||||
sr_err("%s: Unable to claim interface, try again: LIBUSB_ERROR_NOT_FOUND.", __func__);
|
||||
ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
|
||||
fdError = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sr_err("%s: Unable to claim interface: %s.",
|
||||
sr_err("%s: Unable to claim interface, try again: %s.",
|
||||
__func__, libusb_error_name(ret));
|
||||
break;
|
||||
}
|
||||
|
||||
return SR_ERR;
|
||||
if (ret != 0 && fdError == 1){
|
||||
sr_err("%s: Unable to claim interface, the second time: %s.",
|
||||
__func__, libusb_error_name(ret));
|
||||
}
|
||||
|
||||
if (ret != 0){
|
||||
return SR_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
rd_cmd.header.dest = DSL_CTL_HW_STATUS;
|
||||
|
@ -287,7 +287,9 @@ static GSList *scan(GSList *options)
|
||||
|
||||
/* Find all DSLogic compatible devices and upload firmware to them. */
|
||||
devices = NULL;
|
||||
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
|
||||
int usbnum = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
|
||||
int stdnum = 0;
|
||||
|
||||
for (i = 0; devlist[i]; i++) {
|
||||
if (conn) {
|
||||
usb = NULL;
|
||||
@ -314,6 +316,8 @@ static GSList *scan(GSList *options)
|
||||
(usb_speed != LIBUSB_SPEED_SUPER))
|
||||
continue;
|
||||
|
||||
stdnum++;
|
||||
|
||||
prof = NULL;
|
||||
for (j = 0; supported_DSLogic[j].vid; j++) {
|
||||
if (des.idVendor == supported_DSLogic[j].vid &&
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include <glib.h>
|
||||
#include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
|
||||
|
||||
#include "hardware/DSL/dsl.h"
|
||||
|
||||
/* Message logging helpers with subsystem-specific prefix string. */
|
||||
#define LOG_PREFIX "hwdriver: "
|
||||
#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
|
||||
@ -475,3 +477,79 @@ SR_PRIV int sr_source_add(int fd, int events, int timeout,
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
test usb device api
|
||||
*/
|
||||
SR_API void sr_test_usb_api()
|
||||
{
|
||||
libusb_context *ctx;
|
||||
struct libusb_device_descriptor des;
|
||||
int usb_speed;
|
||||
int ret;
|
||||
int i;
|
||||
int num_devs;
|
||||
libusb_device **devlist;
|
||||
int stdnum = 0;
|
||||
int j;
|
||||
int bfind = 0;
|
||||
int dlsnum = 0;
|
||||
struct libusb_device_handle *devhandle;
|
||||
|
||||
printf("\n");
|
||||
|
||||
ret = libusb_init(&ctx);
|
||||
if (ret) {
|
||||
printf("unable to initialize libusb: %i\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
num_devs = libusb_get_device_list(ctx, &devlist);
|
||||
printf("usb dev num:%d\n", num_devs);
|
||||
|
||||
for (i=0; i<num_devs; i++){
|
||||
libusb_get_device_descriptor(devlist[i], &des);
|
||||
|
||||
usb_speed = libusb_get_device_speed( devlist[i]);
|
||||
|
||||
if ((usb_speed != LIBUSB_SPEED_HIGH) && (usb_speed != LIBUSB_SPEED_SUPER))
|
||||
continue;
|
||||
stdnum++;
|
||||
bfind = 0;
|
||||
|
||||
for (j = 0; supported_DSLogic[j].vid; j++) {
|
||||
if (des.idVendor == supported_DSLogic[j].vid &&
|
||||
des.idProduct == supported_DSLogic[j].pid &&
|
||||
usb_speed == supported_DSLogic[j].usb_speed) {
|
||||
bfind = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bfind){
|
||||
dlsnum++;
|
||||
|
||||
devhandle = NULL;
|
||||
ret = libusb_open(devlist[i], &devhandle);
|
||||
if (ret){
|
||||
printf("open device error!%s\n", libusb_error_name(ret));
|
||||
}
|
||||
else{
|
||||
//printf("dev open success\n");
|
||||
ret = libusb_claim_interface(devhandle, USB_INTERFACE);
|
||||
if (ret){
|
||||
printf("Unable to claim interface: %s\n", libusb_error_name(ret));
|
||||
}
|
||||
|
||||
libusb_close(devhandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("std usb dev num:%d\n", stdnum);
|
||||
printf("dls dev num:%d\n", dlsnum);
|
||||
|
||||
libusb_free_device_list(devlist, 0);
|
||||
|
||||
libusb_exit(NULL);
|
||||
}
|
||||
|
@ -82,10 +82,16 @@ SR_API int sr_status_get(const struct sr_dev_inst *sdi, struct sr_status *status
|
||||
SR_API struct sr_config *sr_config_new(int key, GVariant *data);
|
||||
SR_API void sr_config_free(struct sr_config *src);
|
||||
|
||||
/*--- session.c -------------------------------------------------------------*/
|
||||
SR_API void sr_test_usb_api();
|
||||
|
||||
/*--------------------session.c----------------*/
|
||||
typedef void (*sr_datafeed_callback_t)(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet, void *cb_data);
|
||||
|
||||
SR_API void sr_set_export_original_data(int flag);
|
||||
SR_API int sr_get_export_original_flag();
|
||||
SR_API void sr_set_firmware_resource_dir(const char *dir);
|
||||
|
||||
|
||||
/* Session setup */
|
||||
SR_API int sr_session_load(const char *filename);
|
||||
@ -183,13 +189,5 @@ SR_PRIV uint16_t ds_trigger_get_mask1(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
SR_PRIV uint16_t ds_trigger_get_value1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
SR_PRIV uint16_t ds_trigger_get_edge1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
|
||||
/*--------------------session.c----------------*/
|
||||
|
||||
SR_API void sr_set_export_original_data(int flag);
|
||||
|
||||
SR_API int sr_get_export_original_flag();
|
||||
|
||||
SR_API void sr_set_firmware_resource_dir(const char *dir);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.11.0, 2021-11-29T18:27:06. -->
|
||||
<!-- Written by QtCreator 4.11.0, 2021-12-03T14:57:33. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
Loading…
x
Reference in New Issue
Block a user