[Mono-bugs] [Bug 675109] New: Reading from SerialPort misses first byte of a series

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Feb 25 11:35:32 EST 2011


https://bugzilla.novell.com/show_bug.cgi?id=675109

https://bugzilla.novell.com/show_bug.cgi?id=675109#c0


           Summary: Reading from SerialPort misses first byte of a series
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: i386
        OS/Version: Windows XP
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: wdehoog at exalondelft.nl
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


My application has a thread that reads data from a serial port in an endless
loop waiting for bytes. The bytes will come in chunks.

When a chunck arrives the first byte of a chunk is not reported. I think this
is caused by the way the overlapped reading is implemented in
WinSerialStream.cs.

A read is done using ReadFile with an overlapped structure. When ReadFile fails
GetOverlappedResult is used to check if the operation is done.

After some internet searching I modified the code by adding a
WaitForSingleObject (on the read_overlapped event) before the call to
GetOverlappedResult and the problem was gone. Read gives me all the bytes. 

Unfortunately I do not understand why this works better. Maybe
GetOverlappedResult does end too soon and the next time Read is called a new
ReadFile is started so a previous overlapped result is ignored resulting in the
first byte being discarded.

This all happens when using a USB serial port (FTDI chip). I cannot try it with
another type of serial port.

-- 
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