Send data to Honeywell Xenon 1902 barcode reader v

2019-07-25 09:25发布

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

2条回答
不美不萌又怎样
2楼-- · 2019-07-25 10:12

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.

查看更多
在下西门庆
3楼-- · 2019-07-25 10:13

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.

查看更多
登录 后发表回答