控制传输一般只用来发送简单的命令,实际有时也可能用来发送,命令+若干数据的情况,所以我参考书上的例程改写了一下,下面就是PC机的程序,不过当数据长度是64字节时,下位机可以收到的,就是不知到如何再发一个64字节的数据包!
完整程序
PC机端程序:
ept->Target = TGT_DEVICE;//固定用法
ept->ReqType = REQ_VENDOR; //自定义请求
ept->Direction = DIR_TO_DEVICE; //方向 主机->设备
ept->ReqCode = 0xBD; //自定义请求码
ept->Value = 0;
ept->Index = 0;
PUCHAR buf=new UCHAR[64];
ZeroMemory(buf, 64);
LONG buflen = 64;
memset(buf,0x5a,buflen);
//buf[0]=0xbd;
ept->XferData(buf,buflen);//发送数据0x5a
ZeroMemory(buf, buflen);
memset(buf,0x6a,buflen);
ept->XferData(buf,buflen);//发送数据0x6a
下位机程序:
BOOL DR_CONTRLTEST(void)
{
unsigned int i;
for(i=0;i<128;i++)
{
SendByte(EP0BUF);//通过串口返回USB接收的数据
EZUSB_Delay(10);
}
EP0BCH=0;
EP0BCL=128;
EP0CS |= bmHSNAK;
return(TRUE);
}
串口调试助手显示的返回结果:
6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A 6A CF BB D9 FF 97 7F 78 C7 EF DF 6F EF FF EF DF CF BD EE 0D A7 FD F7 FF 8F BF F7 EE BB FB EB 7F 3F 76 39 AB B6 77 F2 FB CF 61 7F 51 F5 7E EE FF 34 BD DF F7 F5 9F BF DF FF AB 33 FA 7F BF 9E CB B7 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A CF BB D9 FF 97 7F 78 C7 EF DF 6F EF FF EF DF CF BD EE 0D A7 FD F7 FF 8F BF F7 EE BB FB EB 7F 3F 76 39 AB B6 77 F2 FB CF 61 7F 51 F5 7E EE FF 34 BD DF F7 F5 9F BF DF FF AB 33 FA 7F BF 9E CB B7
不知道为什么,先发的是0x5a,后发0x6a。这里怎么先显示ox6a呢?
抓包数据,为什么会最后canceled
Dev Phase Data Info Time Cmd.Phase.Ofs
--- ----- ----------- ------------- ----- ------------------
21 USTS 00 00 01 c0 canceled 4us 2.3.0
21 CTL 40 bd 00 00 VENDOR 4.5sc 3.1.0
00 00 80 00 3.1.4
21 DO 5a 5a 5a 5a ZZZZ 9.9sc 3.2.0
5a 5a 5a 5a ZZZZ 3.2.4
5a 5a 5a 5a ZZZZ 3.2.8
5a 5a 5a 5a ZZZZ 3.2.12
5a 5a 5a 5a ZZZZ 3.2.16
5a 5a 5a 5a ZZZZ 3.2.20
5a 5a 5a 5a ZZZZ 3.2.24
5a 5a 5a 5a ZZZZ 3.2.28
21 USTS 00 00 01 c0 canceled 4us 3.3.0 |
|