通过虚拟 com 端口将数据发送到 Honeywell Xenon 1902 条码 reader

Send data to Honeywell Xenon 1902 barcode reader via virtual com port

我正在尝试向 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?." 发送到扫描仪并接收答案。如果我在 Honeywell 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

或许,删除命令末尾的 "vbCr" 可能会奏效。
Area-Imaging Scanner User's Guide第11-1页的"Menu Command Syntax"前缀有CR码,11-3页"Examples of Query Commands"的"cbr?."没有CR码.

或者,您可以使用称为 SerialPort/USB 协议 monitor/sniffer.

的 software/hardware 调查正在发生的通信类型

由于 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

然后我得到文档中定义的答案。