07-12-2015 07:10 PM
Hi,
I am very very new to LabVIEW and I would be interested to clarify a basic question associated with shift registers and wait time functions.
1) What is the purpose of shift register in a while loop as the user acquires continuously data at a certain frequency (Attached image) ?
2) What is the purpose of the waiting time 1 sec within the while loop ( Assumed that the samples are collected every 1 second) as the user specifies a frequency earlier in the task (sample clock)?
3) What is the purpose of the timeout in the read DAQmx function?
Thanks.
07-12-2015 07:44 PM
Instead of a While Loop, suppose you had multiple Read functions one after the other -- they'd all be connected by Error Lines and Task wires. When you collapse them into a While Loop, you "collapse" the connecting wires with a Shift Regster. The idea is that one goes out the right-hand Shift Regster appears on the left-hand Shift Register at the beginning of the next loop.
The purpose of the 1-second Wait would clock the loop at 1 Hz, but (as you note) the function might already be self-clocking, in which case the 1 second Wait may be superfluous.
I'm uncertain why one would have a TimeOut of 1 sec if the loop is supposed to run at 1 sec -- sounds like a Race Condition waiting to happen. It does make sense to set it to, say, 10 sec -- if no samples come in, something migth be wrong ...
Bob Schor
07-12-2015 07:58 PM
07-13-2015 12:40 AM
07-13-2015 08:32 AM
Mike -- is there a reason to not use Shift Registers here? It seems to me that (as I explained in my response) it "preserves" the logic of folding multiple sequential function calls into a loop (you are correct, of course, that you don't need to pass the Task and Error from one function to the next, but that makes logical sense). It might (or might not -- I haven't checked) be a tad faster or slower (actually, it is almost certainly faster or slower!) one way or the other, but we are probably talking nanoseconds, which pales beside "logical" (a.k.a. "good") Programming Style.
Bob "Learning from the Masters" Schor
07-13-2015 08:57 AM
@Bob_Schor wrote:
Mike -- is there a reason to not use Shift Registers here? It seems to me that (as I explained in my response) it "preserves" the logic of folding multiple sequential function calls into a loop (you are correct, of course, that you don't need to pass the Task and Error from one function to the next, but that makes logical sense). It might (or might not -- I haven't checked) be a tad faster or slower (actually, it is almost certainly faster or slower!) one way or the other, but we are probably talking nanoseconds, which pales beside "logical" (a.k.a. "good") Programming Style.
For a While loop, there should not be real difference. It might be slightly more memory efficient. But if you go to a FOR loop, it is a HUGE deal, especially if you are autoindexing on a loop. Try running a FOR loop 0 times. If you used tunnels, the default value comes out of the tunnel (in other words, you will lose your reference). A shift register will pass out the value you initialized the shift register to.
So it is a good habit to just use the shift registers to avoid that nasty bug.
07-13-2015 09:37 AM
07-19-2015 12:57 PM - edited 07-19-2015 12:58 PM
Thanks that worked.