简体   繁体   English

用vb.net进行条形码扫描

[英]bar code scanning with vb.net

I am doing on 1 desktop application . 我正在1个桌面应用程序上做。 I want to add barcode reading facility in this. 我想在其中添加条形码读取功能。 In my app all products would have barcodes in their price tags. 在我的应用中,所有产品的价格标签中都会包含条形码。 I will use some bar code scanner for scanning. 我将使用一些条形码扫描仪进行扫描。 but i am having no ides about all these. 但我对所有这些都没有想法。 can anybody give apme sample code or some reference for this? 有人可以为此提供apme示例代码或参考吗?

Most available barcode scanners emulate a keyboard. 大多数可用的条形码扫描仪都模拟键盘。 They come with configuration barcodes that let you configure it to do different things, such as include a carriage return at the end of the code once it scans. 它们带有配置条形码,可让您对其进行配置以执行其他操作,例如,扫描后在代码末尾添加回车符。 So, once you scan a code, it will appear on the screen as if it was typed out (if, for example, a textbox has focus). 因此,一旦您扫描了代码,它就会像被键入一样出现在屏幕上(例如,如果文本框具有焦点)。

For COM over USB you need the COM port number (look in your device manager), lets say COM15 Using VB.net use the System.IO.Ports.SerialPort class: 对于通过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'

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

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