Send CR LF through the serial port C #

2

I'm communicating with Serial ( SerialPort ) with a device that needs me to send the CR LF commands at the end of each statement so the device understands that an instruction has been sent to it.

The instructions that I should send are all in ASCII.

I know that in the ASCII table there are the commands Line-Feed - Line feed (10) and Carriage-Return - Carriage return (13).

The communication is working perfectly, but the device always returns me an invalid command because I need to send these characters at the end of each statement.

How do I write together in Port.Write or Port.WriteLine at the end of each statement these characters in ASCII?

    
asked by anonymous 10.01.2014 / 17:44

1 answer

4

To send the CR (Carriage Return) and LF (Line Feed) commands together with the command would only add the command \r and \n at the end of the command within the method to send a command through the COM port

string command = "myCommand";

port.write(string.format("{0}\r\n", command));

\r\n = CR + LF → Used as a newline character in Windows

    
10.01.2014 / 17:52