LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port callback function was activated unexpectedly

My program uses a serial port callback. It is a LabWindows/CVI program compiled using Borland C++Builder. It runs under Windows 2000. The callback is intalled using:
InstallComCallback(comport, LWRS_RXFLAG, 0, '\r', Event_Char_Detect_Func, 0);

As my understanding, this callback should be activated only if Windows serial input buffer receives a serial stream contains the character "\r". But, sometimes this callback was activated, I believe, eventhough Windows didn't receive a "\r". More than this, everytime this case happens, the serial input buffer was empty.

I am wondering, how could this serial port callback was activated this way? I'll appreciate any answer.
0 Kudos
Message 1 of 2
(3,021 Views)
Hi,

As per the function help, CVI uses a Windows message internally to call the callback. Because of this, a callback can get called when there are no bytes in the input queue, even though there were bytes in the queue at the time the message was posted. This means that it's possible that there was a '\r' in the input queue when it was polled, and so Windows sends a message to call the callback. But before the callback actually ran, it could be that the queue was emptied. For this reason, it is always advised to check the size of the input queue before doing anything in the callback. Hope this helps!

Jeremy L.
National Instruments
Jeremy L.
National Instruments
0 Kudos
Message 2 of 2
(3,021 Views)