[Mono-dev] SerialPort auto-inserts carriage return

Petit Eric surfzoid at gmail.com
Sun Sep 14 12:52:25 EDT 2008

2008/9/13 mikaelwikman <mail at mikaelwikman.se>:
> Hi,
> Im using a System.IO.Ports.SerialPort to communicate with an embedded system
> currently being developed where i work. The ES uses a binary protocol, so
> the data is not ascii and do not use newlines.
> The strange thing is this; For every byte with the value 10 (linefeed) an
> extra byte with value 13 (carriage return) is inserted into the stream im
> reading from, totally messes up the protocol.
> So: <10> becomes <13><10>, and also <13><10> becomes <13><13><10>.
> I'm running Linux, the code has not been tested using .NET
> Some of my code:
>            SerialPort serialB = new SerialPort()
>            serialB.BaudRate = 115200;
>            serialB.DtrEnable = true;
>            serialB.PortName = "/dev/ttyUSB0";
>            serialB.ReadTimeout = 5;
>            (...)
>            byte[] data = new byte[serialB.BytesToRead];
>            serialB.Read(data, 0, serialB.BytesToRead);
> I'm thinking this is either a bug or there is some setting which turns this
> off. Appreciate any help, thanks!
There is really long time i used serial port, but from my memory there
is something like serialB.EndOfLine no ?
in this case yu just need to set it null
also with ASCII there was readline or read, so read normaly don't add
endline, en so after UTF8.getbyte(str)
Also for reading purpose i suggest you to use the serial port event,
data receveid (need callback of async task)

> --
> View this message in context: http://www.nabble.com/SerialPort-auto-inserts-carriage-return-tp19468589p19468589.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



Small Eric Quotations of the days:
If one day one reproaches you that your work is not a work of
professional, say you that:
Amateurs built the arch of Noah, and professionals the Titanic.

Few people are done for independence, it is the privilege of the powerful ones.

No key was wounded during the drafting of this message.

More information about the Mono-devel-list mailing list