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

人走茶凉 提交于 2019-12-11 04:27:17

问题


I am trying to send a query to the Honeywell Xenon 1902 barcode scanner. The scanner is connected via virtual com port. Setting up the communication works fine:

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

When I press manually the button for scanning I receive the data of reading from the scanner:

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

Now I would like to send the query command "cbr?." from the Honeywell Documentation to the scanner and receive the answer. If I do this on the Honeywell WebInterface it all works fine:

Screenshot from the Honeywell Web Interface Terminal So my problem is that I am unable to send commands to the scanner neither via Tera Term or any other terminal nor via my code:

 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

回答1:


Due to kunif tip I read the Honeywell Documentation again and I solved my problem:

The command need the prefix "SYN M CR" (ASCII 22,77,13) --> "SYNMCRcbr?." has to be send to the scanner via serial connection.

This is the code I send to the scanner:

 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

Then I get an answer as defined in the documentation.




回答2:


Perhaps, removing the "vbCr" at the end of the command may work.
There is a CR code in the prefix of "Menu Command Syntax" on page 11-1 of Area-Imaging Scanner User's Guide, but there is no CR code in "cbr?." of "Examples of Query Commands" on page 11-3.

Alternatively, you can investigate what kind of communication is occurring using software/hardware called SerialPort/USB protocol monitor/sniffer.



来源:https://stackoverflow.com/questions/47775930/send-data-to-honeywell-xenon-1902-barcode-reader-via-virtual-com-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!