[Mono-bugs] [Bug 321988] System.IO.Ports.SerialPort ReadLine behaviour differs from MS .NET implementation

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Nov 4 23:54:54 EST 2007


https://bugzilla.novell.com/show_bug.cgi?id=321988#c3





--- Comment #3 from Michael Mattess <michaelmattess at rauland.com.au>  2007-11-04 21:54:53 MST ---
In comment #2 above I managed to not copy-paste the last line of the function,
so here 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()));
}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list