LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control Front panel items from subVI (Best practice)

Hi community,

 

I am working on an measurement software with medium complexity. What I have realized (and what I have realized in numerous projects of mine in the past) that my subVIs need to read/write the front panel items. For example: I have a stop button on the front panel and I'd like to continously check its state in my measurement VI, so I can stop the measurement right when the user presses the stop button. For this I create a control reference of the Stop button and wire it to the subVI from my main app.

 

This is a simple a neat solution... BUT...

 

This solution is getting more and more convoluted when your subVI needs to read/write several front panel items. In this case I can create a reference for each one of them but then my block diagram will be packed with references (not to mention that it decreases the number of available connectors on the subVI). To get even worse I often need to write subVIs reading/writing the same UI element which means I need to create lots of references for the same control or indicator.

 

To get even worse what if I need to use that control reference in the subVI of a subVI of a subVI. I guess if you understood the issue above you also understand why this is very uncomfortable.

 

So... what I normally do is creating a typdef of a cluster of control references. Then I create a single process shared variable with this type and at the beginning of my application as it is shown below:

x.png

 

So from this point I can call this variable in any of my subVIs and get the reference of my UI elements. This has lots of benefits but also has disadvantages:

 

  1. Breaks the dataflow model
  2. Decreases the number of inputs of the subVI. Which could be a great thing, but now many of my subVIs have only an error in and an error out, so its hard to guess whats going on in the VI just by look, as it has no inputs
  3. it is incovenient to use because I have to put down the variable, then an cluster unbundle by name, and then a property node to read/write the control

 

I am wondering what is the best practice here if any. How do you guys approach the problem in you applications?

 

thanks!

 

 

 

 

 

0 Kudos
Message 1 of 10
(4,661 Views)

Hi 1984,

 

I dislike linking my interface with my 'workers'.

I always tend to approach an MVC architecture. And to do so I mainly use User events to communicate between all my threads.

This way you can create some 'standard' events that your 'worker' (VI doing acquisitions) can send but this kind of VI can also listen to 'UI generic' events. Events are the links between my threads, and on a specific event I can choose to update a control / or stop a loop for example.

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
Message 2 of 10
(4,650 Views)

Use a queue (or a notifier) to transfer the data between the different VIs and subVIs.

157+ CLDs & 9 CLA Trained
LabVIEW Training resources
Message 3 of 10
(4,615 Views)

How would that be better than what I have?

0 Kudos
Message 4 of 10
(4,607 Views)

The really big issue with using control references is that is it HORRIBLY SLOW.  Everytime you read/write a property node with a control reference, you are forcing a thread swap to the UI thread.  The thread swap itself is a performance hit.  But by running the UI thread, you are also forcing a redraw of the front panel.  Plus you have way too much coupling between your different modules.

 

The idea with decoupling modules is that your DAQ loop doesn't care one bit who else is running.  I like using Queues to allow somebody out there to send commands to that loop.  You can timeout on the queue if you want something to happen every so often.  So in your stop button case, you just use a queue to send a command to the DAQ loop to stop when the stop button was pressed.  What this does is it makes things a lot more reusable and easier to troubleshoot.  You can run something with just the DAQ loop and debug it without having to also have the rest of the system running.  Passing data around with Queues, Notifiers, and User Events are the key to making the decoupling work well.

 

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 10
(4,588 Views)

No typedef modification each time a new control has to be updated. No direct link (your ref in your case) between your 'workers' and your HMIs.

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 6 of 10
(4,584 Views)

Does your suggestion refer to the producer/consumer design pattern?

0 Kudos
Message 7 of 10
(4,569 Views)
Have a look on this example, very very useful :
http://www.ni.com/white-paper/14116/en/
Message 8 of 10
(4,552 Views)

@1984 wrote:

Does your suggestion refer to the producer/consumer design pattern?


My suggestion takes some of the ideas from the Producer/Consumer, but it isn't really.  Queued Message Handler is more of the setup I like to use.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 10
(4,528 Views)

Thanks everyone who replied with an idea.

0 Kudos
Message 10 of 10
(4,445 Views)