04-19-2010 05:55 PM
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
Solved! Go to Solution.
04-19-2010 06:03 PM
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.
04-19-2010 06:04 PM
04-20-2010 03:45 PM
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
04-20-2010 04:01 PM
Hmmm... this should work. Please attach your two vi's and I will try it here. Your code looks OK.
04-20-2010 04:05 PM
here are main and subvi
thanks
04-20-2010 04:14 PM
in case you need previous version
8.2
04-20-2010 04:30 PM - edited 04-20-2010 04:32 PM
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.
04-20-2010 04:47 PM
THANK YOU
now it works
I have selected: Create -> Property Nodes -> Value
Instead of: Create -> Property for Control Class -> Value