与外部(硬件)按钮通信
我想创建一个外部按钮以与我的应用程序之一一起使用。我的问题并不集中在硬件本身(这就是我在这里问的原因),而是集中在软件/通信方面。最好、最直接的方法是什么?良好的速度很重要,因此它不应与普通键盘的延迟相差太大。
我想到了以下解决方案:
- 让硬件成为一个修改过的键盘,或者至少应该被系统识别为键盘。优点:不需要软件方面的额外工作。缺点:如果我还需要使用普通键盘怎么办?好吧,还不错,使用当今的 USB 键盘...
- 通过串行端口进行通信。这将是最直接的方法,或者更好的是,就像 10 年前一样。现在大多数计算机甚至都没有,当然,周围有很多串行 USB 转换器。
- 让它成为一个标准的USB设备。我不喜欢这个想法,安装驱动程序,并且必须关心不同的操作系统等。
您有更好的想法吗?
I would like to create an external pushbutton to use with one of my applications. My question does not focus on the hardware itself (that's why I'm asking it here), but on the software/communication side. What would be the best and most straightforward way to do? A good speed is important, so it should not differ too much from the latency of a normal keyboard.
The following solutions come to my mind:
- let the hardware be a modified keyboard, or at least it should be recognized by the system as a keyboard. Pro: no extra work from software-side required. Con: what if I need to use a normal keyboard as well? Ok, not so bad, with today's USB keyboards...
- Communicate through serial port. This would be the most straightforward approach, or better yet, it would have been like 10 years ago. Now most computers don't even have one, of course, there are plenty of serial-usb converters around.
- Let it be a standard USB device. I don't like the idea, with installing drivers, and having to care about different OS, etc.
Does anything better come to your minds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
USB 键盘类 HID 对我来说似乎是最好的。您可以使用与标准键盘不同的扫描码,或者不常用的扫描码,例如某些键盘上用于特定于应用程序的按钮的扫描码。 (请注意,当前的 X.Org 驱动程序仍然限于扫描码 < 256。)
为您的设备找到参考 HID 键盘实现可能也不难。
现代 PC,尤其是笔记本电脑中,串行端口很少见。即使系统板有 RS232 电路,它也没有外部连接器。
为 PC 端编写自定义驱动程序意味着更多的工作和更多的错误空间。使用经过时间验证的标准驱动程序会更安全。
The USB keyboard class HID seems the best to me. You can use different scancodes than standard keyboards, or less often used like those used for app-specific buttons on some keyboards. (Note that current X.Org drivers are still limited to scancodes < 256.)
Probably it's not hard to find a reference HID keyboard implementation for your device, too.
Serial ports are rare in modern PCs and especially notebooks; even if the system board has RS232 circuitry it has no external connector.
Writing a custom driver for the PC side means much more work and more space for bugs. You're far safer using a time-proven standard driver.