05-29-2020 10:18 AM
Dear all,
I'm trying to send RS232 commands periodically.
I saw that timed loop can help me to do the job.
Then, I created a simple example to test and learn how to use it.
I put the example here. It consists on a timed loop with n itérations and a supplementary for loop with m itérations.
I set the timing to one second. Then, I expect a total time of execution of 20s but when I run the VI, it takes 19s.
I thought that I forgot an iteration but it seems not.
Could you help me please?
Finally, do you have clear examples on the use of timed loop to share ?
I found that it is possible also to start the loop with a DAQmx trigger but this is not obviously explained in the tutorials.
Best regards.
05-29-2020 10:44 AM
Generally, Timed Loops do not belong in a Windows system. They eliminate any chance of parallelism inside of the loop, eliminate a lot of potential optimizations, and they run in a thread priority that Windows is not really made for. Just use a simple Wait function in a FOR loop and you will get the same timing accuracy.
Now if you move to a Real Time system (RT), then the Timed Loop becomes important because it helps with determinism.
05-29-2020 10:53 AM
It sounds easier!
OK, I will generate an example to be sure that I understand properly what you suggested with a For loop where I wait the time I need to wait.
Maybe it is important to account for the time to execute the RS232 transfer so I can add a "tick count" before and after the RS232 command to subtract this time to the expected time.
Thanks.
05-29-2020 11:51 AM
Your Expected time (ms) computation is wrong. If, for example, the timed loop executes three times, the waiting will be done 2 times. So if dt is 1s, execution time will be 2 seconds. The timed loop will wait after each iteration the needed time to keep the configured period except for the last iteration. There is no need for waiting if the loop stopped.
05-30-2020 12:13 PM
Is it what you suggested me to do?