[Mono-dev] SerialPort auto-inserts carriage return
Mikael Wikman
mail at mikaelwikman.se
Sun Sep 14 17:29:14 EDT 2008
Hi Petit. Thanks for your reply!
I cant find EndOfLine for SerialPort nor the stream. However, there's a
NewLine property. As defined by MSDN "Gets or sets the value used to
interpret the end of a call to the
ReadLine<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.readline.aspx>and
WriteLine<http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.writeline.aspx>methods.
",
i don't think that's what i want.
I tested this with .NET yesterday and it behaves the same, so this is not
Mono-specific. I guess i could just remove any CR followed by LF, but then i
would have ugly code and be no smarter tomorrow.
As you say, read shouldn't normally add newline. Yet it does.
DataReceived event is not yet implemented for Mono (
http://www.mono-project.com/HowToSystemIOPorts).
On Sun, Sep 14, 2008 at 6:52 PM, Petit Eric <surfzoid at gmail.com> wrote:
> 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
> >
>
>
>
> --
>
> Cordially.
>
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080914/9cd903c1/attachment-0001.html
More information about the Mono-devel-list
mailing list