08-17-2009 05:17 PM
I am interfacing with a device that is pushing out a line of serial data once every millisecond terminated in LF and CR. I need to only read this data from the RS-232 serial port periodically. I read in a line of data, parse it, if a certain condition is met, then my program continues merrily on its way. However, until that condition is met, I would like the program to twiddle its thumbs.
In my first program incarnation, I simply read the serial port output incessantly using ComRdTrm based on the Carriage Return character. This reading was done within a while() loop that wouldn't release until the aforementioned condition was met. This method "worked" sort of although it ate up so much processor, I guess, that other GUI events such as a QUIT button callback would never register.
In an attempt to improve that behavior, I made a quick test button on my GUI that utilized InstallComCallback(). I utilized a large INPUT QUEUE value so that the callback function would only get hit every once in awhile (e.g. INPUT_QUEUE_SIZE = 8192). The callback seems to work in the test function. I guess my question (finally) is how do I keep the rest of my program waiting for the condition to be met before continuing on without eating up the processor? My original poor guess was to do something like:
InstallComCallback (dsrComPortNumber, eventMask, INPUT_QUEUE_SIZE, terminationByte, ComCallback, NULL);
while (COMWait)
{
Delay(5);
}
But this little gem never seemed to make the ComCallback. Hopefully an easy solution eludes me.
Thanks,
Matt
08-21-2009 03:16 PM
Matt,
What programming language are you using? Ideally I think we could use interrupts to program this but without knowing the text base language you are using it is harder to help.