我有一个USB设备,在WINDOWS XP下被识别为USB键盘,然后我用51和CH375芯片做了一个USB主机,目的是处理从此设备得到的数据(此设备为读码器,将读码器插到PC后,任意打开一个文档编辑器,然后扫描一个条码,就会在文档编辑器里面自动输入条形码的值最后带个回车)。 但是问题是,我做的这个主机可以正确地识别从USB键盘得到的数据,却不能正确得到从此设备发来的数据,不知道问题出在哪里?我是用驱动USB键盘的程序驱动此USB设备的。
我的USB键盘配置如下: 12 01 10 01 00 00 00 08 3c 41 03 20 00 02 01 02 00 01 config 09 02 22 00 01 01 04 a0 23 config 2 09 02 22 00 01 01 04 a0 23 09 04 00 00 01 03 01 01 05 09 21 10 01 00 01 22 41 00 07 05 81 03 08 00 18 set idle report 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 95 01 75 08 81 01 95 03 75 01 05 08 19 01 29 03 91 02 95 01 75 05 91 01 95 06 75 08 15 00 26 ff 00 05 07 19 00 2a ff 00 81 00 c0 set report /*下面是得到的键盘码*/ 00 00 1e 00 00 00 00 00 //'1' 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 //'2' 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00 //'3' 00 00 00 00 00 00 00 00 00 00 21 00 00 00 00 00 //'4' 00 00 00 00 00 00 00 00 //顺便问一下,这是什么编码形式?为何和ASC码、Unicode码都对不上?
我的USB设备配置如下: 12 01 00 01 00 00 00 08 b4 04 00 01 01 00 01 02 00 01 config 09 02 22 00 01 01 04 a0 32 config 2 09 02 22 00 01 01 04 a0 32 09 04 00 00 01 03 01 01 05 09 21 00 01 00 01 22 3f 00 07 05 81 03 08 00 0a set idle report 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 95 01 75 08 81 01 95 05 75 01 05 08 19 01 29 05 91 02 95 01 75 03 91 01 95 06 75 08 15 00 25 ff 05 07 19 00 29 ff 81 00 c0 set report /*下面是发来的数据,本应该是一个14字节长度的数据,但是却只收到了8个0*/ 00 00 00 00 00 00 00 00
之后我又用bushound抓取了与PC连接时的数据:
USB键盘的如下(字符“1”的数据流): Device Phase Data Description Cmd.Phase.Ofs(rep) ------ ----- ------------------------------------------------------------------------------------------------------ ---------------- ------------------ 25 LEN 09 00 00 00 9 1.1.0 25 DI 00 00 00 1e 00 00 00 00 00 ......... 1.2.0 25 IRP 06 00 48 01 f8 59 47 87 00 00 00 00 00 00 00 00 08 3b 4f 87 08 3b 4f 87 00 00 00 00 09 00 00 00 1.3.0 25 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 bd aa 88 18 b7 bf 88 9a ad 79 a9 READ 1.4.0 25 LEN 09 00 00 00 9 2.1.0 25 DI 00 00 00 00 00 00 00 00 00 ......... 2.2.0 25 IRP 06 00 48 01 f8 59 47 87 00 00 00 00 00 00 00 00 08 3b 4f 87 08 3b 4f 87 00 00 00 00 09 00 00 00 2.3.0 25 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 bd aa 88 18 b7 bf 88 9a ad 79 a9 READ 2.4.0
下面是USB设备一次发来的数据流(每次都发送14字节有效数据,如下例中的‘23 26 1f 21 26 22 21 1e 20 27 24 1f 23 28’): Device Phase Data Description Cmd.Phase.Ofs(rep) ------ ----- ------------------------------------------------------------------------------------------------------ ---------------- ------------------ 27 LEN 09 00 00 00 9 1.1.0 27 DI 00 00 00 23 26 1f 21 26 22 ...#&.!&" 1.2.0 27 IRP 06 00 48 01 48 dc b1 88 00 00 00 00 00 00 00 00 48 22 50 87 48 22 50 87 00 00 00 00 09 00 00 00 1.3.0 27 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d8 d4 61 89 48 c9 c7 88 9a ad 79 a9 READ 1.4.0 27 LEN 09 00 00 00 9 2.1.0 27 DI 00 00 00 00 00 00 00 00 00 ......... 2.2.0 27 IRP 06 00 48 01 48 dc b1 88 00 00 00 00 00 00 00 00 48 22 50 87 48 22 50 87 00 00 00 00 09 00 00 00 2.3.0 27 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d8 d4 61 89 48 c9 c7 88 9a ad 79 a9 READ 2.4.0 27 LEN 09 00 00 00 9 3.1.0 27 DI 00 00 00 21 1e 20 27 24 1f ...!. '$. 3.2.0 27 IRP 06 00 48 01 48 dc b1 88 00 00 00 00 00 00 00 00 48 22 50 87 48 22 50 87 00 00 00 00 09 00 00 00 3.3.0 27 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d8 d4 61 89 48 c9 c7 88 9a ad 79 a9 READ 3.4.0 27 LEN 09 00 00 00 9 4.1.0 27 DI 00 00 00 00 00 00 00 00 00 ......... 4.2.0 27 IRP 06 00 48 01 48 dc b1 88 00 00 00 00 00 00 00 00 48 22 50 87 48 22 50 87 00 00 00 00 09 00 00 00 4.3.0 27 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d8 d4 61 89 48 c9 c7 88 9a ad 79 a9 READ 4.4.0 27 LEN 09 00 00 00 9 5.1.0 27 DI 00 00 00 23 28 00 00 00 00 ...#(.... 5.2.0 27 IRP 06 00 48 01 48 dc b1 88 00 00 00 00 00 00 00 00 48 22 50 87 48 22 50 87 00 00 00 00 09 00 00 00 5.3.0 27 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d8 d4 61 89 48 c9 c7 88 9a ad 79 a9 READ 5.4.0 27 LEN 09 00 00 00 9 6.1.0 27 DI 00 00 00 00 00 00 00 00 00 ......... 6.2.0 27 IRP 06 00 48 01 48 dc b1 88 00 00 00 00 00 00 00 00 48 22 50 87 48 22 50 87 00 00 00 00 09 00 00 00 6.3.0 27 STAK 03 00 00 e0 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d8 d4 61 89 48 c9 c7 88 9a ad 79 a9 READ 6.4.0
本人刚开始读USB协议,只是略懂点皮毛,分析配置描述符还是很困难的,所以还请有经验的前辈给我指一条路,我该如何配置我的这个设备? 实验做下来,我知道完全按照USB键盘的配置是行不通的,但就是找不到关键的配置点。 希望版主能指点一下此USB设备该如何配置!多谢了! 期待前辈指点中。。。[Emot]19[/Emot]