Using SerialPort.ReadLine Properties

I have a little question to ask.

I need to read data from a serial port. The data comes in rows (I mean data + input) Should I set the serialPort property of the new row, as shown below?

SerialPort sp = new SerialPort(); sp.NewLine = "\r"; sp.ReadLine(); 

What is the value of the newline property? Best wishes...

+2
source share
2 answers

It depends on the protocol you are using. This means that it is the subject of an agreement for sending and receiving parts.

If the other side uses .NET for windows, most likely the new wold line will be Environment.NewLine, and you can skip setting it because it is the default value for windows.

In general, the default default line strings are:
for windows '\ r \ n'
for mac '\ r'
for linux '\ n'
user controller - no matter what controller developer put it there

Thus, if you are writing software to get something from linux, you can expect '\ n' as the value of NewLine, etc.

If you have a data exchange with some kind of controller (exchange with some device), the NewLine line may be WHATEVER, installed by the device software developer.

If you develop this protocol and do not hesitate to install NewLine or not, I can offer you to establish whether you think your application can work in a multi-platform environment (sender IE on windows, recipient on linux).

+2
source

You tried

  sp.NewLine = Environment.NewLine; 
0
source

All Articles