赞
踩
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] =
{
0x05, 0x8c, /* USAGE_PAGE (ST Page) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x01, /* COLLECTION (Application) */
// The Input report
0x09,0x03, // USAGE ID - Vendor defined
0x15,0x00, // LOGICAL_MINIMUM (0)
0x26,0x00, 0xFF, // LOGICAL_MAXIMUM (255)
0x75,0x08, // REPORT_SIZE (8bit)
0x95,0x40, // REPORT_COUNT (64Byte)
0x81,0x02, // INPUT (Data,Var,Abs)
// The Output report
0x09,0x04, // USAGE ID - Vendor defined
0x15,0x00, // LOGICAL_MINIMUM (0)
0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)
0x75,0x08, // REPORT_SIZE (8bit)
0x95,0x40, // REPORT_COUNT (64Byte)
0x91,0x02, // OUTPUT (Data,Var,Abs)
0xc0 /* END_COLLECTION */
}; /* CustomHID_ReportDescriptor */
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/**
* @brief 发送数据后读取数据
* @param None
* @retval None
*/
void HIDSampleFunc( void )
{
HANDLE hDev;
BYTE recvDataBuf[1024],reportBuf[1024];;
DWORD bytes;
hDev = OpenMyHIDDevice(0); // 打开设备,不使用重叠(异步)方式 ;
if (hDev == INVALID_HANDLE_VALUE){
printf ( "INVALID_HANDLE_VALUE\n" );
return ;
}
reportBuf[0] = 0; // 输出报告的报告 ID 是 0
for ( int i=0;i<REPORT_COUNT;i++){
reportBuf[i+1]=i+1; //将数据存放在数据缓冲区
}
printf ( "开始写数据到设备...\n" );
// 写入数据到设备,注意,第三个参数值必须为REPORT_COUNT+1,否则会返回1784错误
if (!WriteFile(hDev, reportBuf, REPORT_COUNT+1, &bytes, NULL)){
printf ( "write data error! %d\n" ,GetLastError());
return ;
} else {
printf ( "成功向设备写出%d个数据... \n" ,bytes);
}
printf ( "开始从设备读取数据...\n" );
// 从设备读取数据,注意,第三个参数值必须大于等于REPORT_COUNT+1,否则会返回1784错误
if (!ReadFile(hDev, recvDataBuf, REPORT_COUNT+1, &bytes, NULL)){ // 读取设备发给主机的数据
printf ( "read data error! %d\n" ,GetLastError());
return ;
} else {
printf ( "成功向设备读出%d个数据... \n" ,bytes);
}
printf ( "设备返回的数据为:\n" );
//显示读取回来的数据
for ( int i=0;i<REPORT_COUNT;i++){
printf ( "0x%02X " ,recvDataBuf[i+1]);
}
printf ( "\n\r" );
}
|
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。