用于窗口的 HID 终端
HID terminal for windows
我已经为我的STM32设备开发了固件。在此设备中,我通过此接口为发送/接收字符串定义了一个自定义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++(日田比项目
- (实用(逸
在我的测试中,我发送了这样的消息:
0x00 (Report ID)
0x41 (Report payload) (A)
...
但是在我的所有测试中,我发现并非所有消息都发送到设备。例如,在设备收到消息之前,我需要发送 10 次或更多次相同的字符串。 如何改善 Windows 和设备之间的通信?
经过大量调试,我发现了问题。
在STM32库上,可以定义HID缓冲区大小
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE ...
Unix系统省略了对这个缓冲区大小的控制,但Windows没有! 就我而言,我定义了 1024 字节的缓冲区(在 USB FS 版本中(。当我尝试发送消息时,Windows 发送 64 字节的块,并且在缓冲区未满之前无法从 USB 接收任何字节。
使用正确的值 64 字节更改缓冲区大小后,通信在 Windows 上也能很好地工作。
相关文章:
- 如何在linux终端中同时编译和运行c++代码
- 终端不会为C++文件创建.exe文件吗
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 用于窗口的 HID 终端
- 如何集成 HID USB 控制器?
- 使用 ubuntu 终端在 c++ 上运行线程类的问题
- 写入文件 a.txt,而终端重定向到文件 b.txt
- VSCode C++终端进程已终止,退出代码为:1
- 终端如何在 shell 提示符下以编程方式阻止退格,以便您无法在其上退格,例如 $ 表示 bash 或 C:\blah\>
- Mac os x app bundle 在下载并运行时崩溃,但在终端或更改 Info.plist 时运行良好
- C printf 无法从终端按预期工作
- 如何在不丢失输出的情况下杀死/停止终端中正在运行的进程?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- 在终端中运行可执行文件与在Mac查找器中打开
- 从 GUI 文件资源管理器执行程序,并且不生成终端
- 终端无法在 c++ 中打印矢量
- 终端命令在程序运行后自动打开图形
- 如何用C++将数据写入usb HID终端