08-12-2009 09:39 AM
I want the "Index" control to be automatically incremented when the OK button is pressed. This works fine. However, the Index control gets automatically incremented every time the VI is started and when the Stop button is pressed. Even if the Case Structure is wired with a False constant (meaning it should never be executed), the Index control is still incremented.
Is there a bug when using local variables inside case structures in the Simulation Loop? This does not occur when using a While loop.
Solved! Go to Solution.
08-12-2009 08:21 PM - edited 08-12-2009 08:21 PM
I think since a Simulation Loop doesnt have shift registers, you will need to use a feedback node.
I have NO experience using simulation loops, I'm just trying to help out.
See the attached example to see what I am talking about.
08-13-2009 07:54 AM
Your VI works for indicators. Howveer, in my situation I need to increment a control. I want users to be able to increment the "Index" control manually and everytime the "OK Button" is clicked.
Thanks
08-13-2009 09:03 AM
Oh, then you may either use a local variable or a property node.
I was just trying to avoid using locals, but in this case, you could probably use them.
08-13-2009 11:13 AM
If I use a local variable outside the case structure, it continuously keeps updating the numeric control and I cannot manually increment or decrement it anymore. If I place the local variable inside the case structure, then it automatically increments the control whenever the VI is started or when the Stop button is clicked.
I think there's a bug in the Simulation module: it always executes the case structure when a local variable of a control is inside.
Ideally I want my Simulation Loop based program to behave like the VI attached and pictured below.
10-05-2010 03:21 PM
I'm a little late on this, but better late than never.
Short story:
Put your case structure in a regular subVI. You might also want to change the "SubVI Node Setup" to execute only on continuous steps (without including minor time steps).
OR
Replace the case structure with a Select node. Wire the incremented index value in the true case and the old index value in the false case.
Long story: It's not a bug so much as quirky behavior of a Simulation loop that should probably be documented better for power users. The complexity of what is actually happening when you run a Simulation loop is hidden from the user. I believe that each diagram of a case structure must be executed on the first and last steps so that simulation blocks get properly initialized and finalized. This works fine for native simulation blocks, but causes problems when you start introducing persistent "states" that the Simulation is unaware of (your global).
Hope this helps!