[Mono-dev] Patch for System.IO.Ports.SerialPort ReadLine function

Michael Mattess MichaelMattess at rauland.com.au
Sun Nov 4 23:59:59 EST 2007


Hi

In my last email I managed to not copy-paste the last line of the
function so there is the complete function:

 

 public string ReadLine (){

    CheckOpen();

    List<byte> bytes_read = new List<byte>();

    byte[] buff = new byte[1];

    int new_line_offset = 0;

 

    while(true) {

        //int n = stream.Read(buff, 0, 1);

        int n = FackeRead(buff);

 

        if(n == -1) {

            break;

        }

 

        bytes_read.Add(buff[0]);

 

 

        if(bytes_read.Count >= new_line.Length) {

            bool isNewLine = true;

 

            //check if we have read a NewLine string.

            for(int i = 0; i < new_line.Length; i++) {

                if(bytes_read[new_line_offset + i] != new_line[i]) {

                    isNewLine = false;

                    break;

                }

            }

 

            if(isNewLine) {

                //Remove the NewLine string from the read line.

                bytes_read.RemoveRange(new_line_offset,
new_line.Length);

                break;

            }

 

            new_line_offset++;

        }

    }

 

    return new String(encoding.GetChars(bytes_read.ToArray()));

}

 

 

Regards,

Michael Mattess

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071105/7b6d8af9/attachment.html 


More information about the Mono-devel-list mailing list