LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Only one reference to a control is working

Solved!
Go to solution

Consider for example the following code, which is working as expected: Everytime the button is clicked, the LED is changing its state.

 

baseline_working.PNG

 

Now I wrap the functionality into a sub-vi and use references to the controls:

 

subvi.PNG

 

And here is the corresponding test fixture:

test_subvi.PNG

 

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

Download All
0 Kudos
Message 1 of 6
(2,863 Views)
Solution
Accepted by topic author Michael2018

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

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(2,859 Views)
Solution
Accepted by topic author Michael2018

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.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 3 of 6
(2,832 Views)

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.

 

0 Kudos
Message 4 of 6
(2,828 Views)

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.

 

 

0 Kudos
Message 5 of 6
(2,813 Views)

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.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 6
(2,809 Views)