使用WinUSB检测USB设备是什么设备速率?高速、低速、全速
2022-05-11
1408
0
WinUSB提供了检测USB设备的速率代码,详见:
// Device Information types
#define DEVICE_SPEED 0x01
// Device Speeds
#define LowSpeed 0x01
#define FullSpeed 0x02
#define HighSpeed 0x03
BOOL GetUSBDeviceSpeed(WINUSB_INTERFACE_HANDLE hDeviceHandle, UCHAR* pDeviceSpeed)
{
if (!pDeviceSpeed || hDeviceHandle == INVALID_HANDLE_VALUE)
{
return FALSE;
}
BOOL bResult = TRUE;
ULONG length = sizeof(UCHAR);
bResult = WinUsb_QueryDeviceInformation(hDeviceHandle, DEVICE_SPEED, &length, pDeviceSpeed);
if (!bResult)
{
printf("Error getting device speed: %d.\n", GetLastError());
goto done;
}
if (*pDeviceSpeed == LowSpeed)
{
printf("Device speed: %d (Low speed).\n", *pDeviceSpeed);
goto done;
}
if (*pDeviceSpeed == FullSpeed)
{
printf("Device speed: %d (Full speed).\n", *pDeviceSpeed);
goto done;
}
if (*pDeviceSpeed == HighSpeed)
{
printf("Device speed: %d (High speed).\n", *pDeviceSpeed);
goto done;
}
done:
return bResult;
}
调用函数代码:
DEVICE_DATA deviceData;
BOOL noDevice;
hr = OpenDevice(&deviceData, &noDevice);
UCHAR speed = 0;
if(GetUSBDeviceSpeed(deviceData.WinusbHandle, &speed))
{
printf("speed =%d\n", speed);
}
...
CloseDevice(&deviceData);
参考资料:
- 怎么更专业的区分USB2.0设备工作在高速还是全速态?http://www.usbzh.com/zone/detail-41.html
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936