- 打开设备:BOOL bOpenHidDevice(HANDLE *HidDevHandle, USHORT vid, USHORT pid)
- 设置波特率、奇偶校验、停止位:
outbuffer[0] = 0; /* 无 report ID */
*(unsigned int *)&outbuffer[1] = 19200; /* 波特率 */
/*Configuration Byte
7 6 5 4 3 2 1 0
Reset 0 Parity Type Parity Enable Stop Bits 0 Data Bits
*/
outbuffer[5] = 0x03; /* 数据位 8, 奇偶校验 无, 停止位 1*/
bResult = HidD_SetFeature(HidDevHandle, outbuffer, Capabilities.FeatureReportByteLength);
if(bResult)
{
}else
printf("HidD_SetFeature failed %d\n",GetLastError());
- 读写数据
outbuffer[0] = 0; /* 无 report ID */
outbuffer[1] = 7; /* 数据长度 */
for(int i=0; i < 7; i++)
outbuffer[2+i] = 'a'+i;
bResult = WriteFile(HidDevHandle,
&outbuffer[0],
Capabilities.OutputReportByteLength,
&numBytesReturned,
NULL);
inbuffer[0] = 0; /* 无 report ID */
bResult = ReadFile(HidDevHandle,
&inbuffer[0],
Capabilities.InputReportByteLength,
&numBytesReturned,
NULL);
if(bResult)
{
//dump data
printf("len = %d\n",inbuffer[1]);
for(int i=0; i < inbuffer[1]; i++)
printf("%c ",inbuffer[i+2]);
}
TODO.