1

我正在做 1 个桌面应用程序。我想在此添加条码读取功能。在我的应用程序中,所有产品的价格标签中都会有条形码。我将使用一些条形码扫描仪进行扫描。但我对所有这些一无所知。任何人都可以为此提供apme示例代码或一些参考吗?

4

2 回答 2

0

对于 USB 上的 COM,您需要 COM 端口号(在您的设备管理器中查看),假设 COM15 使用 VB.net 使用 System.IO.Ports.SerialPort 类:

Dim comPort As New SerialPort("COM15") 'New com port'
Dim terminatingChar As Char = Chr(10) 'Terminate at vbLF (new line)'

comPort.BaudRate = 9600 '9600 baud speed'
comPort.Encoding = Encoding.ASCII 'Decode the bytes via ASCII code'

comPort.Open() 'Open the port'

Dim myBarcode as String = "" 'Current barcode is empty'

While True'Read chars until the terminating char appears'
    Dim tempChar as Char = Convert.ToChar(comPort.ReadChar()) 'Read a char'
    If tempChar = terminatingChar Then Exit While 'If its the terminating char, exit the loop'
    myBarcode = myBarcode & tempChar 'If not append it to the barcode string'
End While

comPort.Close() '(!) Close the port'

Console.WriteLine(myBarcode.Trim()) 'Trim it and show it to the user'
于 2012-07-18T10:09:24.750 回答
0

大多数可用的条形码扫描仪模拟键盘。它们带有配置条形码,可让您对其进行配置以执行不同的操作,例如在扫描后在代码末尾包含回车符。因此,一旦您扫描了一个代码,它就会出现在屏幕上,就好像它是被输入的一样(例如,如果一个文本框有焦点)。

于 2012-07-18T09:57:44.543 回答