02-22-2018 03:56 AM
Consider for example the following code, which is working as expected: Everytime the button is clicked, the LED is changing its state.
Now I wrap the functionality into a sub-vi and use references to the controls:
And here is the corresponding test fixture:
The version with the sub-vi is working only if I use just one instance of the sub vi. As soon as I use two (or more), only one of them is responding to mouse clicks.
Can anyone help me how to fix this?
Thanks a lot,
Michael
Solved! Go to Solution.
02-22-2018 04:03 AM
Hi Michael,
you need to learn several things:
- reentrancy of VIs used with several instances in parallel
- using only one event structure per VI (most often using more than one event structure per VI shows bad VI design)
- using array of references to register events
- using the reference output of the event node
02-22-2018 06:43 AM - edited 02-22-2018 06:44 AM
Only one instance of a subVI can run, unless you declared the subvi reentrant in the VI properties, categories Execution.
If you did not do this, the first instance of the subVI blocks the execution of the other instance, since the subVI never stops.
This is the main problem in your implementation, although not the only one as pointed out by GerdW.
But I guess you are only doing some experiments in LabVIEW coding and not planning to actually write a program this way.
02-22-2018 06:44 AM
Thanks a lot.
Reentrancy was the problem here. By default the vi is configured as non-reentrant. Go to File -> vi-properties -> Execution and select one of the reentrant execution settings.
02-22-2018 07:33 AM
Hello GerdW and pincpanther,
Thank you for your help.
Actually I am looking for a design pattern, where i can have a larger number of identical sets of controls on the front panel, which offer a little bit complex functionality:
- a numeric control holding a target value
- "+" and "-" buttons to change the value (increase/decrease while holding down the mouse button).
- adjustable increment and speed.
I already tried a XControl, but didn't find a solution. So my idea was (as boiled down in this example) to wrap the functionality in a user control and pass references of the gui elements. So I have as little repetitions a possible.
02-22-2018 07:43 AM
As already sketched by GerdW, since your controls are identical, you can register the Value Change event on an array of references. The event node has a Control Reference output that can be used to identify the changed control and do the proper action.
In your example, a second array of indicator references will give you the ability to switch on the proper boolean.