我正在尝试向Honeywell Xenon 1902条形码扫描仪发送查询。扫描仪通过虚拟COM端口连接。 设置通信工作正常:
With SerialPort1
If Not .IsOpen Then
Try
.PortName = "Com9"
.BaudRate = 115200
.DataBits = 8
.Parity = Parity.None
.StopBits = StopBits.One
.Handshake = Handshake.None
.DtrEnable = False
.RtsEnable = False
.Open()
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Öffnen des COM Ports", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End With
当我手动按下扫描按钮时,我会收到扫描仪读取的数据:
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Try
Dim sp As SerialPort = CType(sender, SerialPort)
PufferString = sp.ReadExisting
MsgBox(PufferString)
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Empfangen", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
现在我想发送查询命令" cbr?。"从霍尼韦尔文档到扫描仪并获得答案。如果我在霍尼韦尔WebInterface上这样做,一切正常:
Screenshot from the Honeywell Web Interface Terminal 所以我的问题是我无法通过Tera Term或任何其他终端或我的代码向扫描仪发送命令:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim BefehlsString As String = "cbr?."
Dim enc As System.Text.Encoding = New System.Text.ASCIIEncoding()
Try
Dim ByteArray() As Byte ' Oder String in ...
ByteArray = enc.GetBytes(BefehlsString & vbCr) ' ... Einzelbytes umwandeln
SerialPort1.BaseStream.Write(ByteArray, 0, ByteArray.Length) ' Einzelbytes senden
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Senden", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
答案 0 :(得分:0)
也许,在命令末尾删除“vbCr”可能有效 “区域 - 成像扫描仪用户指南”第11-1页的“菜单命令语法”前缀中有一个CR代码,但“cbr?”中没有CR代码。第11-3页上的“查询命令示例”。
或者,您可以使用名为SerialPort / USB协议监视器/嗅探器的软件/硬件来调查正在进行的通信类型。
答案 1 :(得分:0)
由于kunif提示,我再次阅读霍尼韦尔文档并解决了我的问题:
该命令需要前缀“SYN M CR”(ASCII 22,77,13) - > “SYNMCRcbr?”必须通过串行连接发送到扫描仪。
这是我发送给扫描仪的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim BefehlsString As String = Chr(&H16) & "M" & Chr(&HD) & "cbr?."
serialport.WriteLine(BefehlsString)
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Senden", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
然后我得到了文档中定义的答案。