.NET 的 POS |区分(条形码)扫描仪和键盘输入
我想区分 WPF 应用程序中的(条形码)扫描仪和键盘输入。 我需要的是每当我的扫描仪提供数据时就会发生的事件。
在我的应用程序中,有一个特殊字段将填充扫描仪的输入。因此,如果用户专注于其他字段,我不想在其中插入扫描代码,而是插入我的特殊字段。
首先,我将扫描仪(通过 USB 连接)的输入模式从“键盘模拟”切换为“原始”。但我现在需要做什么?
I want to differentiate between (barcode) scanner and keyboard input in an WPF application.
What I need is an event which occurs whenever my scanner is providing data.
In my application there is a special field which will be filled with the input from the scanner. So, if the user has focused an other field I don't want to insert the scanned code in that, but my special field.
First of all I switch the input mode of my scanner (connected by USB) from "keyboard emulation" to "raw". But what do I need to do now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实施 OPOS 或
WEPOS(WEB 内容不再可用)具有封装设备驱动程序的 COM 和/或 .Net 组件。这些组件可以在扫描数据时引发事件。这些标准还适用于更多设备,包括磁条读取器、秤、现金抽屉、零钱分配器和 MICR(支票)读取器。如果未提供 xPOS 驱动程序,您可以获取 USB/串口驱动程序。这使得设备看起来像是通过 rs232 连接到 Windows。然后您可以使用 System.IO.Ports.SerialPort 编写“扫描仪”抽象。
另一种选择是获取 .sys 和 .h 文件。然后你正在做一些涉及的 PInvoke 和可能的一些 C。
Scanners that implement OPOS or
WEPOS(WEB CONTENT NOT AVAILABLE ANYMORE) have COM and/or .Net components that wrap the drivers for the devices. These components can raise an event when data is scanned. These standards also apply to much more including magnetic stripe readers, scales, cash drawers, change dispensers, and MICR(check) readers.If an xPOS driver is not provided, you may get a usb/serial port driver. This makes the device look like it is connected via rs232 to windows. Then you can use System.IO.Ports.SerialPort to write a 'scanner' abstraction.
Another option, is just getting a .sys and .h file. Then you are doing some involved PInvoke and possibly some C.
我已经放弃了使用 POS for .NET 实现这一点的方法。自己做几乎更容易,因为扫描仪处理它是您感兴趣的框架的唯一相关部分。这基本上是我正在使用的:
class Win32
导入使用的Win32 API 函数并包含它们使用的一些常量:I've discarded my approach to realize this with POS for .NET. It's almost easier to do it yourself, in so far as you the scanner handling it the only relevant part of the framework you were interested in. Here's basically what I'm using:
The
class Win32
imports the used Win32 API functions and contains some constants used by them:您在使用 POS for .Net 和 USB HID 设备方面走在正确的道路上。扫描仪将提供一个数据事件供您处理。您遇到的问题以及我遇到的相同问题是,在 WPF 中您无法本机从 POSExplorer 对象接收数据事件。这是因为 POSExplorer 需要 Windows 表单的句柄。事实证明,由于该技术中使用的线程模型,来自对象的 WPF 是不可接受的。
如果 Microsoft 可以为 WPF 创建一个 POSExplorer,那么您就已经准备好了,但在此之前,最简单的解决方案是使用 Windows 窗体创建一个单独的项目,以便您可以处理来自 POSExplorer 的数据事件。之后,您就可以解决将该信息传递给 WPF UI 的小问题了。
You are on the right track for using POS for .Net and a USB HID device. The Scanner will provide a Data Event for you to handle. The problem you are experiencing, and the same problem I have come accross, is that in WPF you can not natively receive Data Events from the POSExplorer object. This is because POSExplorer requires a handle to a Windows form. It turns out that a WPF from object is not acceptable because of the threading model used in that technology.
If Microsoft could create a POSExplorer for WPF then you would be set, but until then the simplest soltuion is to create a seperate project using a windows form so that you can handle the Data Event from the POSExplorer. After that is working you can then work the minor issue of communicating that information to your WPF UI.
我尝试使用 WinAPI 使其工作。我可以枚举键盘、鼠标和其他人机界面设备:
但 GetRawInputDeviceList 似乎还提供 RDP 设备和其他虚拟设备。如何识别我的键盘和扫描仪?
I tried to get this to work by using the WinAPI. I can enumerate keyboard, mouse and other human interface devices:
But it seems that GetRawInputDeviceList also provide RDP-devices and other virtual devices. How can I identify my keyboard and my scanner?