Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

InstallComCallBack usage

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 

 

0 Kudos
Message 1 of 2
(3,157 Views)

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.

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 2 of 2
(3,116 Views)