|
求助:VC程序中 如何使用 writefile() 发output report 给HID设备
[复制链接]
各位达人:
我需要发送一组数据给HID Device, 使用comtrol endpoint0.
1. 当我使用HidD_SetFeature 发送一个 Feature report 给HID,可以发送成功
(HID firmware 的 HID report descriptor , 我定义这个useage 为 Feature)
2.当我使用 writefile() API 发送一个output report 到HID firmware, 发送不成功。在USB control pipe上并没有setup transfer 发生。GetLastError()返回 Invalid_Function error code.
(我的HID firmware's HID report descriptor, 定义这个useage 为Output useage ).
下面是我的 firmware'的HID Report descriptor 片断:
...... ......
0x06, 0xFF, 0xFF, //Usage Page (Reserved)
0x09, 0x10, // Usage (Reserved)
0xA1, 0x81,// Collection (Vendor)
0x75, 0x08, // Report Size (8)
0x95, 0x01,// Report Count (1)
0x26, 0xFF, 0x00, //Logical Maximum (255)
0x85, 0x0D,// Report ID (13)
0x09, 0x7F, //Usage (Reserved)
0xB1, 0x03, // Feature (Constant)
////////////////////jiemic test
0x85, 0xF0,// Report ID (240)
0x75, 0x08, // Report Size (8)
0x95, 0x0F,// Report Count (15)
0x09, 0x88, //Usage (Reserved)
0x91, 0x82,//jiemic 080625 Output Report
//0xB1, 0x82, //Feature (Data, Variable, Absolute, Volatile)
//jiemic note: if use HidD_SetFeature(), PC can send out data,
// if change to output, writefile() failed
0x85, 0xF1,// Report ID (241)
0x75, 0x20, // Report Size (8*4)
0x95, 0x01,// Report Count (1)
0x09, 0x87, //Usage (Reserved)
0xB1, 0x82, //Feature (Data, Variable, Absolute, Volatile)
////////////////////jiemic test
0xC0, // End Collection
...... .......
我使用的 VC program片断:
BOOL CHIDControl::WriteOutputReport(char * Command)
{
BOOL bWriteSuccess = FALSE;
DWORD BytesWritten = 0;
CHAR OutputReport[16];
ULONG Result;
CString strBytesWritten = "";
/* memset(OutputReport,'\0',16);
OutputReport[0]=0xF0;
memcpy(OutputReport+1,Command,15);*/
char m_Test_Report[16];
m_Test_Report[0]=0xF0;
for(int t=1; t<16; t++)
{
m_Test_Report[t]=t;
}
Result = WriteFile
(WriteHandle,
m_Test_Report, //OutputReport,
Capabilities.OutputReportByteLength,
&BytesWritten,
(LPOVERLAPPED) &HIDOverlapped);
// DisplayLastError("WirteFile: ") ;
Result = WaitForSingleObject
(hEventObject,
500);
switch (Result)
{
case WAIT_OBJECT_0:
{
bWriteSuccess = TRUE;
break;
}
case WAIT_TIMEOUT:
{
//Cancel the Write operation.
Result = CancelIo(WriteHandle);
bWriteSuccess = FALSE;
break;
}
default:
{
bWriteSuccess = FALSE;
break;
}
}
ResetEvent(hEventObject);
if(!bWriteSuccess)
{ return FALSE;}
else
{ return TRUE;}
}
有谁知道 出错在哪里阿? 救急!
谢谢各位啦
|
|