LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Update control in VI with SubVI calculation and vice versa

I've been attempting to make a paint mixer, which can take two user inputs for colors and provides the mixed color as the output. I'm successful in mixing the colors but struggling with making the mixed color brightness adjustable. The brightness of the color correlates with the K value (0-1, with 1 being black), but I can't seem to get the correct value for K given the color. What I want is for the K value (along with the other CMY values) to be calculated each time a new color or color part is picked. With this new calculation, the Brightness slider should correspond to the new K so that the user knows the K value. The user should also be able to adjust the K value for the color using the Brightness slider, and the new Final Color shown with the K value updated. I've been able to achieve almost all of this, except that the Brightness slider does not update on the front panel, making the Final Color not appear until the slider is adjusted to the shown K value. I've tried using property nodes and control references, but still can't achieve this functionality. Is what I'm trying to do even possible? Any advice would be greatly appreciated.

0 Kudos
Message 1 of 4
(679 Views)

You are about to discover the "magic" and power of Data Flow, the principle behind LabVIEW.

 

You want to have two While Loops -- one contains only the Event Structure, the other contains the "State Machine" that does "one thing" whenever the Event Structure detects a new State.

 

Here's what you want to do -- create a Producer/Consumer Design.  The "Producer" is an Event Loop, a While surrounding an Event Structure that "fires" its Event whenever State changes (and maybe also fires an Event when "Stop" is pressed).  Below it, you create the "Consumer", another While Loop that surrounds a Case Statement that is driven by the (newly-changed) State.

 

So you push a Front Panel Button (I haven't looked at how you designed your Front Panel) and fire an Event

in the Event Loop that says "Now Do This".  You use a Queue (or, perhaps, an Asynchronous Channel Wire, my preferred method) to send what "This" is to the Consumer Loop, where "This" is dequeued (or output from a Channel Reader) and wired to the Case "selector" where you execute whatever code you need to do this "State".

 

Note that if you do not press a button, then nothing happens!  The Producer (the Event Loop) is waiting for a "Change" Event, and you didn't generate one.  The Consumer (the State Machine) is waiting for the Producer to send the next State, but the Producer isn't sending, so the Consumer just waits.

 

Note that you now have a neat way of stopping everything.  Add a "Stop" State to your State Machine.  When you push the (separate) Stop Boolean control, your Producer does two things -- it puts the "Stop" State on the "wire" (Channel Wire or Queue) to the State Machine, and also wires a True to stop the Event Loop.  In the Consumer, you (of course) need to add a "Stop" State, whose only responsibility is to stop the Consumer Loop.

 

So you push "Stop".  The Producer (Event) Loop "sees" the Stop, sends it to the Consumer, and stops itself.  The Consumer gets the Stop Message, and stops itself.  Two loops, both stopped at the press of a Button.

 

Bob Schor

 

 

 

 

Message 2 of 4
(664 Views)

I appreciate your thorough response, but it's not exactly the solution I need. I'm trying to link an indicator value in a SubVI (K) to a control value in the main VI (Brightness slider). When two colors get mixed, the K value that's calculated in the SubVI adjusts the Brightness slider automatically and shows the correct color. But, I also want the user to be able to adjust the Brightness slider in the main VI, adjusting the color that's shown and updating the K value automatically. I've only been able to achieve one or the other, and I'm not sure if it's a wiring issue or if linking a control and indicator in this way is not possible.

0 Kudos
Message 3 of 4
(602 Views)

Well, I suspect it is possible to do what you want to do, but I confess that I don't understand it well enough to try to come up with an algorithm to do so.  Perhaps if you compressed your LabVIEW Project, along with some representative data so that we could actually try all of your code, and get a better understanding of your goal(s).  Certainly LabVIEW should be able to do manipulation of data based on interacting with Controls on the Front Panel ...

 

Bob Schor

0 Kudos
Message 4 of 4
(589 Views)