Sending serial command to trigger scanner Honeywell 1900

Viewed 1667

The problem is, that I can trigger scanner using Serial Port software "Hercules" sending command <SYN>T<CR><LF>, in datasheet is said to use command [SYN]T[CR] to trigger scanner, but I cant trigger it (both commands) using my serial port comunication bellow. I get input when use scanner manually but can't trigger it... What is a problem? (The port is virtual)

private static SerialPort port;
private static bool _continue = false;

public static void Main(string[] args)
{
    port = new SerialPort();
    port.PortName = "COM8";
    port.BaudRate = 115200;
    port.Parity = Parity.None;
    port.DataBits = 8;
    port.StopBits = StopBits.One;
    port.Handshake = Handshake.None;
    port.RtsEnable = true;
    port.DtrEnable = true;
    port.ReadTimeout = 500;
    port.WriteTimeout = 500;
    port.Open();

    _continue = true;
    Thread thr = new Thread(SerialPortProgram);
    thr.Start();

}


private static void SerialPortProgram()
{
    Console.WriteLine("Writing to port: <SYN>T<CR><LF>");
    string command = "<SYN>T<CR><LF>";
    port.WriteLine(command);

     while (_continue)
    {
        try
        {
           string input = port.ReadLine();
           Console.WriteLine("Input is - " + input);

        }
        catch (TimeoutException) { }
    }

}
2 Answers

Python barcode scanner serial trigger is an article that I answered similar Python question.

The contents are shown below.

This happens because you coded the abstract expression written in the document as raw output data.

The document represents 3 bytes of data transmission.

'SYN' and 'CR' are the following hexadecimal numbers.

'SYN' = \x16

'CR' = \x0d or escape sequence \r

'T' is an ordinary ASCII character.

Whitespace and < > [ ] { } are used to delimit the data in the document, not the data to send.

And, even you need to command prefix it.

Also use Write instead of WriteLine as written by @Turbofant.

You should write like this. Please try it.

string command = "\x16M\x0d\x16T\x0d";
port.Write(command);

I guess the problem is, that you are sending the wrong command string. The <Syn>, <CR> and <LF> stands for the special, non printable ascii characters synchronous idle, Carriage return and line feed. You need to encode them correctly in the string

Try sending:

string command = "\x16t\r\n";
port.Write(command);

\x16is <Syn> (Because Syn is ascii character 0x16, or 22 in decimal )

\r is <CR>

\n is <LN>

And use port.Write instead of port.WriteLine, because WriteLine automatically adds the \r\n at the end of the string.

Related