I am making a C program that communicates with a serial port. I want the reading & writing operations to take place independently. Is it possible for an interrupt to be issued by windows when it receives some input on the serial port? I believe it is possible using overlapped I/O by having separate threads for reading & writing. however, since this is the first time I have ever heard of multi-threaded programming, I am extremely confused. Please help me
I'm unsure what you mean by "possible for an interrupt to be issued by Windows". Under the hood, the serial port will raise an interrupt. Windows will then translate this into a response to WaitCommEvent.
WaitCommEvent takes an event mask and an OVERLAPPED structure. You can -- as far as I recall: it's been a while since I did any serial programming in Windows -- associate different events with different OVERLAPPED structures (i.e. different event handles).
Alternatively, I think that you can issue WaitCommEvent from different threads with different event masks...
- Edited by Roger Lipscombe Tuesday, June 17, 2008 1:47 PM Clarification
I am waiting infinitely for an input to be received on the serial port. At the same time, I want the user to be able to write some commands during this infinite wait. If I receive some input, I want to be notified of it & process it. Otherwise, the control should remain with the user. I am presently using the following code snippet(Will I have to issue read & write in separate threads to achieve my objective?):