Re: Serial port monitoring
"Kahlua" <kahlua@right.here> wrote in message
news:gV2uj.7748$wK4.308@trndny01...
In my earlier days of "Turbo C" when I wrote an aplication that uses the
serial port I did something like this.
1st I would initialize the comport and open it, of course (Com1)
I would then have a loop that checks for char in serial buffer.
I would read the char and depending on its value I would jump to other
parts of the program
Then I would return to the loop which just sits there looking for chars in
serial buffer.
As far as I know this is obviosly not desireable in VC++
So, my app has to be able to "watch for char in serial buffer" while also
able to react to buttons clicked on screen.
If a char enters the serail buffer I want to be able to retrieve it and
check its value.
Everything is done within my app.
Like a large loop running.
With a Windows program you can't poll the port because your program can be
suspended for hundreds of milliseconds, so your loop would miss characters.
The built in serial port device driver handles inputting and queues the
input to a buffer for you.
You also have to avoid a loop continuously running, because that steals all
the CPU time from other programs. MFC runs your message handlers when you
have an incoming message, but at all other times your main thread is
suspended. So the ideal way to handle serial input is to input it in
another thread (you will often get more than one character) and transfer the
received data to your main thread by posting a message to it. I don't know
if your COMDrv++ library does that for you. If not, you will have to do
that yourself.
There is a sample program and article in MSDN named MTTTY that shows how to
do it.
--
Scott McPhillips [VC++ MVP]