【发布时间】:2019-03-27 11:02:30
【问题描述】:
我已经为我的 STM32 设备开发了一个固件。在这个设备中,我定义了一个 CUSTOM HID 接口,用于通过这个接口发送/接收字符串。我的USB接口描述向量:
/**** Descriptor of CUSTOM HID interface ****/
0x09, /*bLength: Interface Descriptor size*/
0x04, /*bDescriptorType: Interface descriptor type*/
0x00, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x02, /*bNumEndpoints*/
0x03, /*bInterfaceClass: CUSTOM_HID*/
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0x00, /*iInterface: Index of string descriptor*/
/**** Descriptor of CUSTOM_HID ****/
0x09, /*bLength: CUSTOM_HID Descriptor size*/
0x21, /*bDescriptorType: CUSTOM_HID*/
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of CUSTOM_HID class descriptors to follow*/
0x22, /*bDescriptorType*/
0x33,/*wItemLength: Total length of Report descriptor*/
0x00,
/**** Descriptor of Custom HID endpoints ****/
0x07, /* bLength: Endpoint Descriptor size */
0x05, /* bDescriptorType: */
0x04, /*bEndpointAddress: Endpoint Address (OUT)*/
0x03, /* bmAttributes: Interrupt endpoint */
0x40, /* wMaxPacketSize (64 bytes) */
0x00,
0x0A, /* bInterval: Polling Interval (10 ms) */
0x07, /*bLength: Endpoint Descriptor size*/
0x05, /*bDescriptorType:*/
0x81, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x40, /*wMaxPacketSize (64 bytes) */
0x00,
0x0A, /*bInterval: Polling Interval (10 ms)*/
我已经在 Linux 上测试了我的设备的发送/接收字符串,它工作得很好(一个简单的回显字符串到 hidraw 设备)。 现在我正在尝试在 Windows 中开发一个简单的程序(尝试使用 v7x64 和 v10x64)。我已经测试了很多库:
- (Python)pywinusb
- (C#)HIDSharp
- (C++)hidapi project
- (实用程序)YAT
在我的测试中,我发送这样的消息:
0x00 (Report ID)
0x41 (Report payload) (A)
...
但在我的所有测试中,我发现并非所有消息都发送到设备。例如,我需要在设备收到消息之前发送 10 次或更多次相同的字符串。 如何改善 Windows 和设备之间的通信?
【问题讨论】:
-
如果它适用于 Linux 而不是 windows,则问题通常是字符串的终止字符。您使用什么字符来终止消息?您是否发送二进制数据。如果是这样,您需要在发送数据之前添加消息的长度。
-
在 windows 中,字符串以回车和 NL 结束。在 Linux 中它只是 NL。
-
我在每个环境中都使用 NL