I'm trying to put together a proof of concept for reading/writing to a serial port and I am having problems with design/concept. I don't want to poll, so I'm trying to use Overlapped I/O. In this case, it's not a multi-threaded application - it just uses efficient waits.
- Open port (with OVERLAPPED)
- SetCommState (set port baud, parity, CTS/RTS, etc)
- SetCommMask (EV_BREAK, EV_CTS, EV_DSR,..., EV_RXCHAR, EV_RXFLAG, EV_TXEMPTY)
- Create OVERLAPPED structures and Events
- WriteFile (to port)
- WaitCommEvent (due to write)
- WaitCommEvent (due to read)
- ReadFile (from port)
- Check read buffer
The MSDN example is kind of lame (Monitoring Communications Events). I'm currently using two events, but the ReadFile
step is failing with ERROR_INVALID_PARAMETER
.
In the steps above, do I need one or two overlapped structures? If one OVERLAPPED
structure, are the steps WriteFile
, WaitCommEvent
(for write), reset event, WaitCommEvent
(for read), ReadFile
?
ReadFile()
, how do you expect to get help figuring out why it is complaining about them? – Remy Lebeau