各位大神好!
我使用WINUSB提供的函数WinUsb_ReadPipe来读取BULK IN端点的值,发现根本就没有读到任何数据。
我的BULK端点设置的类是0xFE(Application Specific Interface)。
以下是我的代码:
// 读取来自设备的信息
HRESULT readfromdevice(_Inout_ PDEVICE_DATA DeviceData)
{
BOOL bResult = NULL;
ULONG cbSize = 30;
UCHAR *szBuffer = (UCHAR*)LocalAlloc(LPTR, sizeof(UCHAR)*cbSize);
ULONG cbRead = 0;
HRESULT error_infomation;
// 若接口不存在
if (DeviceData->WinusbHandle == INVALID_HANDLE_VALUE){
printf("the device is invalid\n");
}
// 清楚PIPE中的原有值
//WinUsb_FlushPipe(DeviceData->WinusbHandle, DeviceData->InPipe);
// 读取pipe中的内容
//while (!bResult)
bResult = WinUsb_ReadPipe(DeviceData->WinusbHandle, DeviceData->InPipe, szBuffer, cbSize, &cbRead, 0);
// 若读取失败
if (!bResult){
error_infomation = HRESULT_FROM_WIN32(GetLastError());
printf("read pipe failed %x\n", bResult);
} printf("Read from pipe 0x%x: %s\nActual data read: %d.\n", DeviceData->InPipe, szBuffer, cbRead);
// 释放szBuffer
LocalFree(szBuffer);
return 0;
}
奇怪的是,同样的代码我读取interrupt端点的数据就正常。
莫非是BULK端点有一些不一样的设置?