C# 与 USB 端口通信

发布于 2024-12-21 02:35:05 字数 181 浏览 3 评论 0原文

我正在尝试使用 USB 条形码扫描仪作为串行端口,使用他的虚拟 COM 端口名称和串行端口类。

我尝试这样做的原因是避免将扫描仪用作键盘楔子,因为即使在隐藏表单的情况下我也需要能够进行扫描。

问题是,当我将条形码扫描仪连接到 USB 端口并运行“GetPortNames”函数时,我得到一个空列表。有什么建议吗?谢谢

I'm trying to contact an usb barcode scanner as a serial port, using his virtual COM port name and the Serial Port class.

The reason I'm trying to do it this way is to avoid using the scanner as a keyboard wedge since I need the possibility to scan even when the form is hidden.

Problem is that when I connect the barcode scanner to the usb port, and I run the "GetPortNames" function, I get an empty list. Any suggestions why? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽容 2024-12-28 02:35:05

通常,许多 USB 条形码扫描仪仅显示为虚拟键盘设备,而不是虚拟 COM 端口。这可以解释为什么它没有出现。

您的扫描仪支持某种串行仿真模式吗?您可能需要配置它或安装不同的驱动程序才能启用此功能。它在设备管理器中是否显示为串行端口? (查看端口树下)

顺便说一句:

如果您发现“键盘模式”是唯一受支持的模式,请看一下这个问题:
使用 USB 读取条形码条形码扫描仪以及忽略键盘数据输入,而扫描仪产品 ID 和供应商 ID 未知

这个问题引用了这篇文章,其中提供了大量有关键盘挂钩和过滤扫描条形码的好信息:
http://nicholas .piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/

Typically many USB barcode scanners will just appear as virtual keyboard devices - not virtual COM ports. That would explain why it doesn't appear.

Does your scanner support some kind of serial emulation mode? You may need to configure it or install different drivers to enable this. Does it appear as a serial port in Device Manager? (Look under the Ports tree)

As an aside:

Take a look at this question if you find that the 'keyboard mode' is the only one supported:
Reading a barcode using a USB barcode scanner along with ignoring keyboard data input while scanner product id and vendor id are not known

This question refers to this article with a large amount of good information relating to keyboard hooks and filtering out the scanned barcodes:
http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/

九八野马 2024-12-28 02:35:05

我不能保证它适用于您的特定设备,但我曾经见过解决类似问题的代码。解决方案是在注册表中查找端口名称。

其代码可以在开源项目 ez430chronosnet 中找到;一个 .NET 库,可以通过 USB 适配器访问 TI 的 EZ430 Chronos 手表。

您需要查看 PortName.cs 文件 在注册表中查找名称(它至少会为您指出正确的键)和 Chronos.cs 文件 使用 SerialPort 打开实际的端口。

I cannot guarantee that it will work with your specific device, but I've seen code that solved a similar problem once. The solution was looking for the port name in the registry.

The code for it can be found in the open source project ez430chronosnet; a .NET library that can access TI's EZ430 Chronos watch via its USB dongle.

You'll want to look at the PortName.cs file that looks for the name in the registry (it will at least point you to the right keys) and the Chronos.cs file that does the actual port opening with SerialPort.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文