mysql读取usb 数据_windows 通过hidapi库读取usb端口的报文数据

(1)这里使用的是第三方的hidapi库,我已经用VS编译源码,现在把hidapi.h和hidapi.dll和hidapi.lib直接分享下。

链接:https://pan.baidu.com/s/1JxDqJhWstC34qxZTMeOqiA

提取码:kqrj

当然也可以自己去下载。

(2)使用qt调用hidapi库的。

(3)在源码里面引用lib文件和h文件,源码如下

#include "../../../../Users/Administrator/Personal/123123/card/hidapi.h"

#pragma comment(lib, "C:/Users/Administrator/Personal/123123/card/hidapi.lib")

(3) 因为接收数据是采用阻塞的方式,为了不影响主程序,我新建一个线程去接收数据,主要具体代码如下:

#define MAX_STR 255

void UBKAERThread::run()

{

int res;

res = hid_init();

wchar_t wstr[MAX_STR];

int i;

//0x0483和0x5750 是指定usb设备的vid和pid  在系统的硬件设备里面可以找到对应的值

handle = hid_open(0x0483, 0x5750, NULL);

if(handle == NULL)

{

return;

}

else

{

}

res = hid_get_manufacturer_string(handle, wstr, MAX_STR);

wprintf(L"Manufacturer String: %s\n", wstr);

res = hid_get_product_string(handle, wstr, MAX_STR);

wprintf(L"Product String: %s\n", wstr);

res = hid_get_serial_number_string(handle, wstr, MAX_STR);

wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr);

res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);

wprintf(L"Indexed String 1: %s\n", wstr);

updataUsb();

}

void UBKAERThread::updataUsb()

{

qDebug("hid read start");

int        res = hid_set_nonblocking(handle, 0);

QString asd ;

while (1)

{

res = hid_read(handle,buf,sizeof(buf));

//16进制转换成10进制

for(int i = 0;i < sizeof(buf);i++)

{

char str[20];

sprintf(str , "%02x",buf[i]);

asd+=str ;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值