简体   繁体   English

在 Visual Basic .net 中使用 HID 条码扫描仪

[英]Using an HID bar code scanner in visual basic .net

I am using visual basic 2019 and I need to use a bar code scanner as an HID device, not as a keyboard wedge.我正在使用 Visual Basic 2019,我需要将条形码扫描仪用作 HID 设备,而不是用作键盘楔。 Is there a form control like the RS-232 serial port control that I can add to a form and place code in event handling routines to handle received data?是否有像 RS-232 串行端口控件这样的表单控件,我可以将其添加到表单中并将代码放置在事件处理例程中以处理接收到的数据?

I'm not an expert in this particular area, but I did find a few classes that could be helpful to you:我不是这个特定领域的专家,但我确实找到了一些可能对您有所帮助的课程:

Windows.Devices.HumanInterfaceDevice.HidDevice

and

System.IO.Ports.SerialPort

There are instructions and examples on the msdn pages. msdn 页面上有说明和示例。 You should be able to create an instance of one of these classes and use it to communicate with your hardware.您应该能够创建这些类之一的实例并使用它与您的硬件进行通信。

There is a SerialPort control you can find in the toolbox.您可以在工具箱中找到一个SerialPort控件。 You will also need to include Imports System.IO.Ports in your form.您还需要在表单中包含Imports System.IO.Ports

Then it's just a matter of configuring the port with calls such as:然后只需使用以下调用配置端口即可:

    SerialPortScanner.BaudRate = "19200"
    SerialPortScanner.ReadTimeout = 5000
    SerialPortScanner.DataBits = 8
    SerialPortScanner.Parity = Parity.None
    SerialPortScanner.Open()
    SerialPortScanner.DiscardOutBuffer()    'start fresh
    SerialPortScanner.DiscardInBuffer()

Finally you read bytes with something like:最后,您使用以下内容读取字节:

    CharBuff = SerialPortHCT.ReadByte()

Of course, you will need to loop on reading bytes and know when to stop (assuming you have to read them as bytes and don't have the luxury of having a scanner that sends delimited strings.当然,您将需要循环读取字节并知道何时停止(假设您必须将它们作为字节读取并且没有扫描仪发送分隔字符串的奢侈。

The tricky part is if you have to controller the scanner with non-printable characters.棘手的部分是,如果您必须使用不可打印字符的扫描仪 controller。 I have done this by making some constants like this:我通过制作一些像这样的常量来做到这一点:

    Const ACK As Byte = 6   ' ACKnowledge ASCII Code

Then you can write out the byte like this:然后你可以像这样写出字节:

    SerialPortScanner.Write({ACK}, 0, 1) ' Send ACK byte

There are other settings and controls, but that's the basics.还有其他设置和控件,但这是基础。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM