LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

rs-232 ComCallback loops, how to stop?

Hi,
I have to say that I am relatively new to the rs-232 business.
My application is supposed to receive and process data from an instrument via rs-232.
The instrument transmits an ASCII data set when a button is pressed on the instrument.
I want my application to wait at runtime until data is received and then process it.
What I am doing is installing a ComCallback -   
InstallComCallback  (comport, LWRS_RXCHAR, 0, (int)gEventChar[0], EventCharDetectFuncCB, &g_MeasurementBuf);

The ComCallback is invoked on any character received.
I now want my application to wait with the processing of the data until the entire measurement is received,
I've tried stuff like:
    do
    {  
        Delay (1);
        inQLenLast = inQLen;
        inQLen = GetInQLen (comport);
      } while (inQLen != inQLenLast);
inside the CallBack to prevent it from being invoked more than once for each data set, without success. The CallBack is executed more than once each time a measurement is sent from the instrument. Is there a standard way for those sort of problems?
Any help would be greatly appreciated!
Thanks

0 Kudos
Message 1 of 6
(3,699 Views)
Is the data set that is received uniform?  Does it have the same number of bytes or end with carriage return and/or line feed?
If so, you can set these as the flag on the comcallback.
Otherwise, you will need to knoe something about how to tell the start of msg2 from the end of msg1, etc.
If the button pushes are guaranteed to be many seconds apart, you can just read buffer until it is empty and then process the enitre message.  You may want to pause a little after receiving the first byte if you still use byte-receipt as your callback trigger.


Message Edited by scomack on 05-29-2008 07:55 AM
0 Kudos
Message 2 of 6
(3,690 Views)
DocEye,
 
You can use the LWRS_RECEIVE callback flag instead.  It won't generate another callback until the receive buffer falls below the 'threshold' number of bytes.  I assume that if you set the threshold to '1' you will get one callback and then no more until the buffer is emptied. 
 
As mentioned in the above post though, it is a good idea to set your callbacks to happen on as much information as you can.  If all your receive messages/buffers/etc., are more then 'N' characters, set your threshold to 'N'.  Or use a delimiator (new line, carriage return, etc, ) and use the LWRS_RXFLAG if you can.
 
Greg
0 Kudos
Message 3 of 6
(3,673 Views)
Unfortunately the data sets are not consistent or end with the same character. Thanks to you guys offering many solutions its all solved anyway! LWRS_RECEIVE with threshold = 1 works and so does reading the data set and appending to a string until the buffer is empty.
Thanks for your help!

0 Kudos
Message 4 of 6
(3,661 Views)

Hello 

me too I have a problem with that kind of application. I use multithreading communication between my evalboard (stm32F4) and NIcvi (my PC equipped with  corei3 processors ) I am not using a high baud rate (9600) but the communication is always faster than the cvi code execution. I wonder, if there is someone who can help me in improving execution time and thinks in advance. (the code is not complicated I have just to verify a checksum of every received packet ).

0 Kudos
Message 5 of 6
(3,196 Views)

hadjrami,

  1.  Don't hijack other's threads, start your own topic instead
  2.  Don't swamp the forum with identical posts
0 Kudos
Message 6 of 6
(3,191 Views)