LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to delay 5ms between comm port transmits

I need to delay 5~10 ms between comm port transmit msgs while communicating with an embedded system. Using Delay() function, the msgs are transmitted at intervals of old PC timer of 65ms. Any suggestion?
0 Kudos
Message 1 of 4
(3,378 Views)
CVI normally should have better performances that 55 ms resolution on timer, unless you have set the useDefaultTimer configuration option to True.

To improve the performances of your system, you could investigate on other aspects of serial communication; starting from version 5.5 there is the possibility to override the output buffer and to write directly to the port: this is obtained by setting to a negative value the Output Queue Size parameter in OpenComConfig.

I'm afraid there are no more chances of obtaining a short and stable pacing in windows environment unless you use a DAQ card with a timer for timing your application.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,378 Views)
Thanks for the feedback. After checking into it a bit, I was able to get better resolution than 55mS. However, using the Delay() function set to 5mS yeilded results ranging from 0 to 25mS. Your suggestion about the output buffer sounds very interesting. This may explain the 0mS delay(lack of delay), the buffer was loaded and then delayed in "Windows time". I must say, Windows sucks for engineering use. Sorry, just a small rant.
0 Kudos
Message 3 of 4
(3,378 Views)
Here are three more ideas: use flow control, the Timer() function, or an asynchronous timer.
Do you have any control over the embedded application? Can you implement either hardware or software (XON/XOFF) flow control?
To make sure you have a minimum delay, you could use the Timer function after your Delay function call. That will help you avoid a delay that's too short, but not one that's too long.
An asynchronous timer may help, since the timer runs in a different thread (but its callback is still affected by some windows stuff). In CVI 6.0, the general help for asynchronous timer is under "Asychronous" (misspelled). There is also an async timer example that ships with CVI (found in the CVI help under "Asynchronous" correctly spelled).
Call NewAsyncTimer to start
the timer and assign a callback function.
Call SetAsyncTimerAttribute to set the timer interval to 5 mS.
Use a global flag with three states: e.g.: 0 = waiting after new transmission; 1 = waiting, timer event received; 2 = ready for new transmission.
Immediately after transmitting, set flag = 0.
In the timer callback, increment the flag. On the first callback, flag will be incremented to 1.
In the main routine, run a loop waiting for flag >= 2.
In the next timer callback (5 mS later), flag will be incremented to 2.
In your main routine, when the flag >= 2, set the flag=0 and continue.
0 Kudos
Message 4 of 4
(3,378 Views)