m_Hiddevice.ReadHid(RxBuffer,12);  然后将 RxBuffer的数据写成文件保存下来
确定是下位机是发送了12个字节的数据,保存的文件前8个字节是对的,但是后四个字节确实CC CC CC CC
不明就里
hid类的 ReadHid用的是百合电子的源代码,源代码中的长度为64,为什么读取操作时操作8个字节后就不正确呢
实现函数如下
void CHid::ReadHid(unsigned char ucDataBuffer[], unsigned char ucDataLength)
{
HANDLE hDevice;
unsigned long numBytesReturned;
unsigned char inbuffer[128]; /* input buffer*/
BOOL bResult;
HIDP_CAPS Capabilities;
PHIDP_PREPARSED_DATA HidParsedData;
OVERLAPPED HidOverlapped;
HANDLE ReportEvent; if(!m_bMyDeviceDetected)
return; /* Open the HID device handle */
if(OpenHidDevice( &hDevice, VID, PID) == TRUE)
{
/* get a handle to a buffer that describes the device's capabilities.  This
line plus the following two lines of code extract the report length the
device is claiming to support */
HidD_GetPreparsedData(hDevice, &HidParsedData);

/* extract the capabilities info */
HidP_GetCaps( HidParsedData ,&Capabilities);

/* Free the memory allocated when getting the preparsed data */
HidD_FreePreparsedData(HidParsedData);

/* Create a new event for report capture */
ReportEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* fill the HidOverlapped structure so that Windows knows which
event to cause when the device sends an IN report */
HidOverlapped.hEvent = ReportEvent;
HidOverlapped.Offset = 0;
HidOverlapped.OffsetHigh = 0;


bResult = ReadFile( hDevice,
&inbuffer[0],
Capabilities.InputReportByteLength,
// ucDataLength+1, //如果ucDataLength的值为64的话,Capabilities.InputReportByteLength就为65
&numBytesReturned, /* returned buffer size */ 
(LPOVERLAPPED) &HidOverlapped );/* long pointer to an OVERLAPPED structure */
bResult = WaitForSingleObject(  ReportEvent, 600);

if(bResult == WAIT_TIMEOUT || bResult == WAIT_ABANDONED)
CancelIo(&hDevice);

if(bResult == WAIT_OBJECT_0)
{
//Save data to ucDataBuffer(this parameter will return by this funciotn)
for(int i=0;i<ucDataLength;i++)
{
ucDataBuffer[i]  = inbuffer[i+1];
TRACE("0x%.2X ",ucDataBuffer[i]);
}
TRACE("\n"); } /* close the HID device handle */
CloseHandle(hDevice);
}
} 求各位发表下意见!!!!