使用vb.net扫描条形码

时间:2012-07-18 09:53:51

标签: c# vb.net barcode

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

2 个答案:

答案 0 :(得分:0)

大多数可用的条形码扫描仪模拟键盘。它们带有配置条形码,允许您将其配置为执行不同的操作,例如在扫描后在代码末尾包含回车符。因此,一旦您扫描代码,它就会在屏幕上显示,就像它被输入一样(例如,如果文本框具有焦点)。

答案 1 :(得分:0)

对于COM over USB,您需要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'
相关问题