使用 USB 条码扫描仪读取条码并忽略键盘数据输入,同时扫描仪产品 ID 和供应商 ID 未知
有没有一种方法可以在忽略键盘且不知道 USB 扫描仪的 PID 或 VID 的情况下从 USB 条形码阅读器读取数据? 我知道有一种方法可以通过使用USB扫描仪的VID和/或PID来区分USB扫描仪输入和键盘输入; 这是使用 中的代码完成的http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/ 但是,是否有另一种解决方案可以区分键盘和 USB 扫描仪,而无需将扫描仪的 VID 或 PID 放入配置文件(或源代码)中? 不想将各种 VID 或 PID 放入配置文件中的原因是,正在开发的应用程序将部署在许多笔记本电脑上,并附加任意类型的扫描仪。
另外,我不想用要输出的开始和/或结束序列来配置扫描仪,因为扫描仪也被同一台机器上的其他软件使用,并且我不想更改代码在其他软件上。 出于与前面提到的相同原因,我不想将条形码读取器编程为串行模式。
Is there a way to read from a USB barcode reader while ignoring the keyboard and not knowing the PID or VID of the USB scanner? I know that there is a way of differentiating between USB scanner input and keyboard input by using the VID and or PID of the USB scanner; this was done using code from http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/
But is there another solution to differentiate between keyboard and USB scanner without putting the scanner's VID or PID in a configuration file (or source code)? The reason for not wanting to put various VIDs or PIDs in a configuration file is that, the application being developed will be deployed on numerous laptops and have arbitrary types of scanners attached to them.
Also, I don't want to configure the scanner's with a starting and or ending sequence that would be outputted, since the scanner is being used by other software on the same machine as well and I don't want to have to change the code on the other software. I don't want to program the barcode reader to be in serial mode either for the same reason mentioned previously.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一种方法可以区分键盘和 USB 条形码阅读器
从以下假设开始:
这个使用VS2005 VB的简单表格包含:
There is a way to differentiate between keyboard and USB barcode reader
Starting with the following assumptions:
This simple form using VS2005 VB contains:
好吧,我使用的解决方案非常类似于 Ehab 的解决方案 - 我只是为我的应用程序清理了一点代码。 我正在为我的编辑控件使用自定义类(它也执行其他一些操作) - 但这些是重要的部分:
Well, I am using a solution pretty like the one from Ehab - I just cleaned up the code a little bit for my application. I am using a custom class for my edit controls (it is doing some other things too) - but these are the important parts:
也许这是一个过于简单的解决方案,但是您可以捕获按键事件并简单地阻止通过键盘输入吗?
Perhaps this is an oversimplified solution, but could you capture the key press event and simply prevent entry via keyboard?
还有一个关于条形码的问题 此处,该链接会将您发送至通过串行端口使用条形码的答案。 也许这对你来说是一个解决方案?
恕我直言:最简单的解决方案是接受来自键盘的输入。
There is another question about barcodes here, the link will send you to an answer that uses the barcode via a serial port. Maybe that's a solution for you?
IMHO: The most easy solution will be accepting the input from the keyboard.