[Mono-dev] Patch for System.IO.Ports.SerialPort ReadLine function
Miguel de Icaza
miguel at novell.com
Mon Nov 5 09:47:43 EST 2007
Hello Michael,
As suggested by Alp in the bug (321988), I wrote a state-driven
version of the ReadLine routine for serial ports. It should be more
efficient. Would you mind testing it?
public string ReadLine ()
{
CheckOpen ();
List<byte> bytes_read = new List<byte>();
byte [] buff = new byte [1];
int nl_state = 0;
int nl_final = new_line.Length;
while (true){
int n = stream.Read (buff, 0, 1);
if (n == -1)
break;
if (buff [0] == new_line [nl_state]){
if (++nl_state == nl_final)
break;
} else
nl_state = 0;
bytes_read.Add (buff [0]);
}
return new String (encoding.GetChars (bytes_read.ToArray ()));
}
}
More information about the Mono-devel-list
mailing list