04-10-2006 11:24 AM
04-10-2006 11:30 AM
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
04-10-2006 11:36 AM
04-10-2006 12:00 PM
04-10-2006 01:08 PM
Quick FYI: If you go to the subvi in question and select File-->VI Properties-->Execution Options and set the vi to be "Reentrant", then each instance you put on your block diagram(s) will be distinct from one another.
In regular, non-reentrant mode, all instances are forced to share the same shift register data. In re-entrant mode, all instances are forced to have distinct copies of the shift register and the static data cannot be shared.
-Kevin P.
04-10-2006 01:17 PM
04-11-2006 01:06 AM
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
04-11-2006 12:30 PM - edited 04-11-2006 12:30 PM
You should always consider initializing shift registers. Keep in mind that if you just opened a VI that contains uninitialized shift registers, it won't remember the data from the last time it was run (because it has been unloaded from memory since then), so it's more likely the values in that shift register are garbage. That could be even more dangerous, since how LabVIEW interprets that data could cause very strange and erratic behavior in your application.
Here's my solution that works for Functional Globals and general shift registers: Consider initializing them the first time the VI is called inside the While Loop, as demonstrated below:


The First Call VI outputs a true the first time that instance of it is called, and false every other time. For Functional Globals you could alternatively have a dedicated Initialize case to perform this function. The advantage of the technique listed above is that you are guaranteed initialization on the first call, regardless of whether the client programmer remembers to call an initialization case.
Message Edited by Jarrod S. on 04-11-200612:33 PM
Message Edited by Jarrod S. on 04-11-2006 12:33 PM
04-11-2006 12:37 PM
@jarrod S. wrote:Keep in mind that if you just opened a VI that contains uninitialized shift registers, it won't remember the data from the last time it was run (because it has been unloaded from memory since then), so it's more likely the values in that shift register are garbage. That could be even more dangerous, since how LabVIEW interprets that data could cause very strange and erratic behavior in your application.
04-11-2006 12:42 PM
Ok, I may have spoken too soon (I always do that 🙂 ). Some quick tests seem to indicate that shift registers are initialized to default values when the VI is first opened.
I'll try to think if there's a bona fide exception to this. In any case, the technique listed above is still valuable in many situations, especially functional globals.