是否有带有 .net api 的条形码扫描仪(硬件)可供我用来集成到我的应用程序中?
据我了解,条形码扫描仪就像键盘一样,其作用也是如此。我需要的是一个具有某种 api(最好是 .net/c#)的扫描仪,我可以将其插入到我的应用程序中。是否有特定的扫描仪硬件供应商开发人员已经使用或当前正在使用,具有 .net api?或者我可以使用任意扫描仪并围绕它构建 api 或使用开源扫描仪之一?
所以我想做的一件事是能够从 USB 扫描仪获取值,而无需将光标放在特定的文本字段上。
谢谢
I understand the barcode scanner is like a keyboard and acts as such. What I need is a scanner that has some sort of api (.net/c# preferably) that i can plug into my app. Is there a particular scanner hardware vendor devs have used or are currently using, that has a .net api? or can I use any arbitrary scanner and build an api around it or use one of the open source ones?
So 1 thing I would like to do, is be able to get the value off the usb scanner without placing the cursor on the particular text field.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,这取决于。如果您有 USB 条形码扫描仪,它的作用就像键盘一样,将扫描的文本直接读取到聚焦控件中。如果您有串行条形码扫描仪,则需要使用 .NET 中的
SerialPort
类。如果您需要在填充文本框等之前解析数据,那么最好的选择是使用串行扫描仪。
这是一个可供使用的代码示例:
Well, it depends. If you have a USB barcode scanner it acts exactly like a keyboard, reading the scanned text directly into a focused control. If you have a serial barcode scanner, you will need to use the
SerialPort
class in .NET.If you are going to need to parse the data before filling a textbox, etc. then best bet would be to use a Serial Scanner.
Here's a code sample for use:
要留在像键盘一样的扫描仪上,您还可以尝试检测整个应用程序中按下的所有按键。要在应用程序中获取
KeyPress
事件,您应该将Form.KeyPreview
设置为true
并注册到表单的上述事件。现在,您将在将每个密钥发送到当前活动控件之前收到它,并且您可以随心所欲地使用它。为了防止它在完成工作后发送到当前活动控件,请将
e.Handled
设置为true
。但这个解决方案肯定有两个缺点:
To stay on a scanner that acts like a keyboard you could also try, to detect all key pressed within your whole application. To get a
KeyPress
event within your application you should setForm.KeyPreview
totrue
and register to the above mentioned event of your form.Now you'll receive every key before it is send to the current active control and you can do with it, whatever you like. To prevent that it will send to the current active control after you have done your work, set
e.Handled
totrue
.But this solution has definitely two drawbacks:
我已经使用条形码扫描仪实现了类似的系统。我非常确定(不是100%,这是很久以前的事了)文本作为一个大字符串传入,并且只引发了一个按键事件。因此,您可以做的是将输入字符串与典型的条形码字符串进行匹配,例如 KeyPressEvent,如果匹配则查找该项目。或者甚至只是检查字符串中字符的长度(就好像它的键盘输入一次只能是 1 个字符一样)。
您是否在基本表单上测试过它?
I have implemented a similar system using a barcode scanner. I am pretty sure (not 100% it was a long time ago) that the text came in as the one large string and only raised the one keypress event. So what you could do is match the input string against a typical barcode string e.g. KeyPressEvent, and if it matches then lookup the item. Or even just check the length of chars in the string (as if its keyboard input it should only be 1 char at a time).
Have you tested it out on a basic form?