1.下载 HidApi库:GitHub - yigityuce/HidApi: Human Interface Device Api (HidApi) with C++
2.pro文件添加
DEFINES -= UNICODE
LIBS += -lsetupapi
3.建立三个对象
HidApi hidApi;
HidDevice hidDev;//HID设备
HidDeviceList devList;//HID设备列表
4.对 HID 设备进行扫描,存入列表,并选择需要进行通信的赋给 hidDev
hidApi.isInitialized();
devList = hidApi.scanDevices();
for(size_t i = 0; i < devList.size(); i++)//可打印扫描到的设备的信息
{
qDebug() << i + 1 << ". DEVICE\n";
qDebug() << "Path : " << devList[i].getPath().c_str();
qDebug() << "Vendor Id : " << devList[i].getVendorId();
qDebug() << "Product Id : " << devList[i].getProductId();
//qDebug() << "Serial : " << devList[i].getSerial();
//qDebug() << "Manufacturer: " << devList[i].getManufacturer();
//qDebug() << "Product : " << devList[i].getProductString();
qDebug() << "Release No : " << devList[i].getRelease();
qDebug() << "Usage Page : " << devList[i].getUsagePage();
qDebug() << "Usage : " << devList[i].getUsage();
qDebug() << "Interface : " << devList[i].getInterface();
qDebug() << "-----------------------------------------------";
Out_Edit.append(QString("%1").arg(i + 1) + ". DEVICE");
Out_Edit.append(devList[i].getPath().c_str());
Out_Edit.append("Serial : " + QString::fromStdWString(devList[i].getSerial()));
Out_Edit.append("Manufacturer: " + QString::fromStdWString(devList[i].getManufacturer()));
Out_Edit.append("Product : " + QString::fromStdWString(devList[i].getProductString()));
Out_Edit.append("Vendor Id : " + QString("0X%1").arg(devList[i].getVendorId(), 4, 16, QLatin1Char('0')));
Out_Edit.append("Product Id : " + QString("0X%1").arg(devList[i].getProductId(),4, 16, QLatin1Char('0')));
Out_Edit.append("Release No : " + QString("%1").arg(devList[i].getRelease(), 4, 10, QLatin1Char('0')));
Out_Edit.append("Usage Page : " + QString("%1").arg(devList[i].getUsagePage(), 4, 10, QLatin1Char('0')));
Out_Edit.append("Usage : " + QString("%1").arg(devList[i].getUsage(), 4, 10, QLatin1Char('0')));
Out_Edit.append("Interface : " + QString("%1").arg(devList[i].getInterface(), 4, 10, QLatin1Char('0')));
Out_Edit.append(0);
}
5.看看效果