Can I use WaitForSingleObject in place of WaitCommEvent and if so how,
because I can't get it to work,
One of my apps involves up to 40 RS-232 serial ports and it looks like I
need to use something like
WaitForMultipleObjects to tell me when one of the serial lines becomes
active or an event has occured on one of them.
Being an old Unix developer I could use a function called 'select' which
would work for serial port file descriptors and socket descriptors, however
select doesn't work in the same fashion for NT4, I was also wondering if
there is a way I could
block on a set of descriptors that included SOCKET handles, and RS-232
handles within the same thread for NT4?
Thanks in advance,
I have written a server app that does exactly what you describe. It puts each
client in a CWinThread derived class and uses (M)WFMO on the wait handle which
can be either a serial port or a socket. The tricky parts are:
In your serial port pool, you must open all the ports overlapped, SetCommMask(
EV_RXCHAR ), and WFMO. At this point, I toss a message to the main window which
then calls an accept-like function (my listening port pool is in a thread). The
OVERLAPPED struct *must* be passed with the serial port... DO NOT modify it!
Now you can create a thread and pass in your port info, etc. When you are
ready, use WaitCommEvent() and (M)WFMO.
The same thing can be done with sockets, but it requires WinSock 2.0. Check
WSAEventSelect().
I spent may hours cursing and gnashing my teeth to get this working properly,
don't despair if it takes a while.