qt 通过hid获取指定usb设备 并读取数据

时间:2023-05-21 04:15:05
【文件属性】:
文件名称:qt 通过hid获取指定usb设备 并读取数据
文件大小:10KB
文件格式:RAR
更新时间:2023-05-21 04:15:05
qt usb hidapi 文件夹中包含hidapi.h hidapi.dll hidapi.lib,我是在windows10系统中用VS2013编译的release版本,我用于qt的调用,是可以实现的。 调用过程: int res; res = hid_init(); wchar_t wstr[MAX_STR]; int i; // Open the device using the VID, PID, // and optionally the Serial number. handle = hid_open(0x0483, 0x5750, NULL); if(handle == NULL) { qDebug() << "NULL-----------------------NULL" ; return; } else { qDebug() << " not ------------NULL-----------------------NULL" ; } // Read the Manufacturer String res = hid_get_manufacturer_string(handle, wstr, MAX_STR); wprintf(L"Manufacturer String: %s\n", wstr); // Read the Product String res = hid_get_product_string(handle, wstr, MAX_STR); wprintf(L"Product String: %s\n", wstr); // Read the Serial Number String res = hid_get_serial_number_string(handle, wstr, MAX_STR); wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr); // Read Indexed String 1 res = hid_get_indexed_string(handle, 1, wstr, MAX_STR); wprintf(L"Indexed String 1: %s\n", wstr); qDebug("hid read start"); int res = hid_set_nonblocking(handle, 0); while (1) { res = hid_read(handle,buf,sizeof(buf)); QString asd ; for(int i = 0;i < sizeof(buf);i++) { char str[20]; sprintf(str , "%02x",buf[i]); asd+=str ; } if(!cardInfo.contains(asd.toUpper())) { cardInfo.append(asd.toUpper() ); for(int i = 0;i < cardInfo.size() ;i++) { dealWithData( cardInfo[i]); } } }
【文件预览】:
HID-QT
----hidapi.lib(5KB)
----hidapi.h(14KB)
----hidapi.dll(12KB)

网友评论

  • 没有用,没有用
  • 压缩文件坏掉了