VB.NET如何操作条码扫描枪,如何设置,如何进行条形码的设置及打印

VB.NET条码扫描... VB.NET 条码扫描 展开
 我来答
smh1982
2011-12-06 · TA获得超过842个赞
知道小有建树答主
回答量:1578
采纳率:0%
帮助的人:881万
展开全部
这个要看扫描枪的通讯接口和通讯协议,以及接口程序是否支持VB.NET等。
优博讯
2024-11-01 广告
二维码扫描器是一种用于读取二维码信息的设备。常见的二维码扫描器有枪式和扫帚式,可以进行移动支付、产品防伪、溯源信息、电商网站、共享单车的扫描等等。 优博讯致力于成为全球领先的IoT行业数字化解决方案提供商,专注于智能数据终端、智能支付终端以... 点击进入详情页
本回答由优博讯提供
wy3568
2011-12-11
知道答主
回答量:66
采纳率:0%
帮助的人:12.7万
展开全部
Imports System
Imports System.IO.Ports

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'获取计算机有效串口
Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间,用SerialPort,获取计算机的有效串口
Dim port As String
For Each port In ports
portnamebox.Items.Add(port) '向combobox中添加项
Next port
'初始化界面
baudratebox.SelectedIndex() = 2
portnamebox.SelectedIndex() = 0
Serial_Port1() '初始化串口
Label3.Text = SerialPort1.IsOpen
statuslabel.Text = "串口未连接"
statuslabel.ForeColor = Color.Red
sendbox.Text = "123"
' baudratebox.Text = baudratebox.Items(0) 注释和不注释的地方可以替换
'portnamebox.Text = portnamebox.Items(0)
End Sub

Private Sub Serial_Port1() '设置串口参数
SerialPort1.BaudRate = Val(baudratebox.Text) '波特率
SerialPort1.PortName = portnamebox.Text '串口名称
SerialPort1.DataBits = 8 '数据位
SerialPort1.StopBits = IO.Ports.StopBits.One '停止位
SerialPort1.Parity = IO.Ports.Parity.None '校验位
End Sub

'关闭串口连接
Private Sub closebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closebtn.Click
Try
SerialPort1.Close() '关闭串口
Label3.Text = SerialPort1.IsOpen
If SerialPort1.IsOpen = False Then
statuslabel.Text = "串口未连接"
statuslabel.ForeColor = Color.Red
receivebox.Text = ""
receivebytes.Text = ""
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

'打开串口连接
Private Sub openbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openbtn.Click
Try
SerialPort1.Open() '打开串口
Label3.Text = SerialPort1.IsOpen
If SerialPort1.IsOpen = True Then
statuslabel.Text = "串口已连接"
statuslabel.ForeColor = Color.Green
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

'发送数据
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
SerialPort1.Write(sendbox.Text)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

'触发接收事件
Public Sub Sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Me.Invoke(New EventHandler(AddressOf Sp_Receiving)) '调用接收数据函数
End Sub

'接收数据
Private Sub Sp_Receiving(ByVal sender As Object, ByVal e As EventArgs)
Dim strIncoming As String
Try
receivebytes.Text = Str(Val(receivebytes.Text) + SerialPort1.BytesToRead)
If SerialPort1.BytesToRead > 0 Then
Threading.Thread.Sleep(100) '添加的延时
strIncoming = SerialPort1.ReadExisting.ToString '读取缓冲区中的数据
SerialPort1.DiscardInBuffer()
receivebox.Text = strIncoming
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式