LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize button in the mainVI with a cycle in subVI?

Solved!
Go to solution

1) wires?

2) global variable?

 

================ 

 

I would like to interrupt execution of some cycles in subVI by pressing the button in the mainVI. How to connect button  in the mainVI with a cycle in subVI?

1) wires?

It does not work if I connect button with the cycle via wires and connectors (from mainVI to subVI). This is because by the moment of pressing the button, subVI already requested the value (and it is remaing=FALSE until the subVI is ending).

 

2) global variable?

I got basically same result.

The position of the button is transferring from mainVI to subVI, but with the delay.

  

3) The only solution I have found so far is to remove subVI completely and paste their code into the mainVI.But this is not a good solution, since the code of subVI is executing several times in a different parts of the mainVI. 

 

Thanks 

 

0 Kudos
Message 1 of 9
(3,374 Views)
Solution
Accepted by topic author TAPAC

Solution: use a reference.

 

Create a reference to the button in the main vi (right click on button and select create - reference).  In your subvi, create a control reference on the front panel (Refnum palette - Control Refnum).  Connect refnum to a terminal.  In main block diagram, wire in the control reference to the subvi reference input that you just created.  In subvi block diagram, use property node to get the value of the control reference.  It will be a variant, but you can use Variant to Data to convert it to a boolean.

 

What happens is that the reference you are passing to the subvi is actually an address (pointer) to its location in memory where its value is stored.  So when you click on the button in main, the value at that address gets changed.  In subvi, the property node will read the value at the same address because that is the address you passed into the subvi.  So an instant change in main is read by the subvi.  In the same manner, you can display an indicator from the subvi in the main, and it will update without having to wait until the subvi ends.

 

- tbob

Inventor of the WORM Global
Message 2 of 9
(3,371 Views)
A notifier would work.  Be sure to send the notification in a thread separate from the thread driving the SubVI.
0 Kudos
Message 3 of 9
(3,370 Views)

I did everything as decribed

I expected that after pressing the STOP button in the main VI, the while loop in subVI ends. But it never ending.

Even if i press stop button before running the mainVI.

Did I made a mistake?

thanks

 

 

sync.PNG

0 Kudos
Message 4 of 9
(3,333 Views)

Hmmm... this should work.  Please attach your two vi's and I will try it here.  Your code looks OK.

 

- tbob

Inventor of the WORM Global
Message 5 of 9
(3,320 Views)

here are main and subvi

thanks 

Download All
0 Kudos
Message 6 of 9
(3,318 Views)

in case you need previous version

8.2

 

Download All
0 Kudos
Message 7 of 9
(3,313 Views)

I don't know how you did it, but in your subvi you created a property node giving the value of the control reference itself.  In other words, your property node gives the address of the stop button, not its value.  In your subvi, notice the color of the Value output.  It is blue-green, the color of a reference, not a variant, not a boolean.  What I did was to right click on the Ctl Refnum on the block diagram and selected Create - Property for Control Class - Value.  The output is a variant.  You must wire a boolean to the top of the Variant to data function.  Now it works.

 

 

I found out how you did it.  You went to the front panel Ctl Refnum and right clicked  there.  Don't do this.  Go to the block diagram Ctl Refnum and right click there.

 

Message Edited by tbob on 04-20-2010 02:32 PM
- tbob

Inventor of the WORM Global
Message 8 of 9
(3,303 Views)

THANK YOU

now it works

 

have selected: Create -> Property Nodes -> Value

Instead of:  Create -> Property for Control Class -> Value

 

0 Kudos
Message 9 of 9
(3,293 Views)