//发送LED的状态。
BOOL CMyUsbHidTestAppDlg::SendLedStatus()
{
BOOL Result;
UINT LastError;
UINT i;
CString Str;
//如果设备没有找到,则返回失败
if(MyDevFound==FALSE)
{
AddToInfOut("设备未找到");
return FALSE;
}
//如果句柄无效,则说明打开设备失败
if(hWriteHandle==INVALID_HANDLE_VALUE)
{
AddToInfOut("无效的写报告句柄,可能是打开设备时失败");
return FALSE;
}
//如果数据仍在发送中,则返回失败
if(DataInSending==TRUE)
{
AddToInfOut("数据正在发送中,暂时不能发送");
return FALSE;
}
//设置要发送报告的数据
//WriteReportBuffer[0]=0x00; //报告ID为0
//WriteReportBuffer[1]=LedStatus; //将LED状态放到缓冲区中
WriteReportBuffer[1]=0x00;
WriteReportBuffer[1]=0x25;
WriteReportBuffer[2]=0x2B;
WriteReportBuffer[3]=0x02;
WriteReportBuffer[4]=0x01;
WriteReportBuffer[5]=0x01;
WriteReportBuffer[6]=0x2F;
WriteReportBuffer[7]=0x21;
//显示发送数据的信息
AddToInfOut("发送输出报告9字节");
Str="";
for(i=0;i<64;i++)
{
Str+=itos(WriteReportBuffer[i],16).Right(2)+" ";
}
AddToInfOut(Str,FALSE);
//设置正在发送标志
DataInSending=TRUE;
//调用WriteFile函数发送数据
Result=WriteFile(hWriteHandle,WriteReportBuffer,65,NULL,&WriteOverlapped);
if(Result==1)
{
Result=ReadFile(hReadHandle,ReadReportBuffer,64,NULL,&ReadOverlapped);
LastError=GetLastError(); //总返回1784 是什么情况
DataInSending=FALSE;
return TRUE;
}
}
Bus Hound工具获取到的数据是正常的,为什么读总返回错误代码1784呢
Device Phase Data Description Cmd.Phase.Ofs(rep)
------ ----- ----------- ---------------- ------------------
29.2 OUT 25 2b 02 01 %+.. 1.1.0(6)
01 2f 21 00 ./!. 1.1.4
00 00 00 00 .... 1.1.8
00 00 00 00 .... 1.1.12
00 00 00 00 .... 1.1.16
00 00 00 00 .... 1.1.20
00 00 00 00 .... 1.1.24
00 00 00 00 .... 1.1.28
29.2 IN 25 2b 12 01 %+.. 2.1.0(6)
01 00 27 10 ..'. 2.1.4
00 00 00 27 ...' 2.1.8
11 11 24 00 ..$. 2.1.12
43 eb 00 00 C... 2.1.16
da eb 21 ..! 2.1.20 |