LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using MainVI as front panel of controls for subVIs (running persistently)

Solved!
Go to solution

Hi all,

I have been writing some LabView code that controls several different instruments.

My general control paradigm has been as follows:

  • Each instrument is controlled by a different VI
  • These instrument VIs contain a connect/disconnect button.
    • When the connect button is pressed, the instrument settings are written to the instrument, and it runs
    • When the disconnect button is pressed, the instrument closes out and the subVI ends.
  • The mainVI allows users to set instrument controls, which are written to global variables, and referenced inside the subVIs.
    • (For example, the mainVI connect button is written to a global variable. Inside the subVI the global variable writes to the connect button)
  • While the subVI runs, the instrument readings are written to global variables in the subVI. The mainVI displays the instrument readings by reading the global variables that were written in the subVI.

However, since the subVI runs until disconnect is pressed, the mainVI waits for the subVI to finish, and the global variables are not updated. The mainVI user cannot update the disconnect global variable, while the subVI is running, so it runs continuously, and the mainVI user is locked out of control of the subVI.

This seems like a pretty simple/fundamental use case, so I’m sure there must be a clean solution to it that I am missing. I am clearly confused about the general “dataflow” and “synchronization between main and subVIs.

Can anyone suggest, or give me a topic to read up on, to allow me to use a mainVI/subVI scheme to write controls to instruments and display instrument readings?

0 Kudos
Message 1 of 11
(1,825 Views)

Hi Kruncy,

 


@CaptainKruncy wrote:

the mainVI waits for the subVI to finish, and the global variables are not updated.

I am clearly confused about the general “dataflow” and “synchronization between main and subVIs.


There are your two main problems:

  1. the main VI should not "wait for subVIs to finish" when the subVIs are needed to run in parallel (aka "THINK DATAFLOW!")…
  2. there are most often better ways to share/communicate data than to use global variables…

You need to work on both items.

Unfortunately you didn't attach any code so we cannot help you with specific suggestions!

Best regards,
GerdW


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

Hi,
Even though you have explained your problem nicely, it would be better if you could attach your vi (at least a simplified version).

Like you mentioned it is mostly because of synchronization issue. Ther are design pattern templates (producer/ consumer) and synchronization functions (queues/notifiers) available in LabVIEW to achieve what you're trying to do. Alternatively, you can use control references to pass into your sub-vi's to access your main vi FP elements from sub vi, but i would recommend you use the first approach.
Please refer it and attach a simplified version of your vi if possible.

bp
0 Kudos
Message 3 of 11
(1,780 Views)

@CaptainKruncy wrote:

However, since the subVI runs until disconnect is pressed, the mainVI waits for the subVI to finish, and the global variables are not updated. The mainVI user cannot update the disconnect global variable, while the subVI is running, so it runs continuously, and the mainVI user is locked out of control of the subVI.

This seems like a pretty simple/fundamental use case, so I’m sure there must be a clean solution to it that I am missing. I am clearly confused about the general “dataflow” and “synchronization between main and subVIs.

Can anyone suggest, or give me a topic to read up on, to allow me to use a mainVI/subVI scheme to write controls to instruments and display instrument readings?


1. Don't make a subvi that waits for a button

2. Use queue/event to send data to subvi

3. Show it in a subpanel so you can click it.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 11
(1,753 Views)

Thanks for the detailed and polite response!

 

I’ve simplified my original code to be easier to read and comment on in this forum.

 

Here is a screenshot of the simplified mainVI, where the inputs and outputs are controlled by global variables that are referenced inside the subVI.

 

(mainVI)

CaptainKruncy_0-1682014188468.png

(subVI)

CaptainKruncy_1-1682014197805.png

 

Attached are the simplified programs. They aren't quite functional, as I deleted a bunch of details to make the overall concept more transparent. They should clearly show my approach of updating the global variables in real time in the mainVI, and running the subVI persistently.

 

I know that my initial approach isn't correct. Thanks for any suggestions on how to approach the general dataflow of mainVI as a user GUI and subVI as instrument control.

 

Download All
0 Kudos
Message 5 of 11
(1,736 Views)

Thanks for the detailed and polite response!

 

I’ve simplified my original code to be easier to read and comment on in this forum.

 

Here is a screenshot of the simplified mainVI, where the inputs and outputs are controlled by global variables that are referenced inside the subVI.

 

(mainVI)

CaptainKruncy_0-1682014188468.png

(subVI)

CaptainKruncy_1-1682014197805.png

 

Attached are the simplified programs. They aren't quite functional, as I deleted a bunch of details to make the overall concept more transparent. They should clearly show my approach of updating the global variables in real time in the mainVI, and running the subVI persistently.

 

I know that my initial approach isn't correct. Thanks for any suggestions on how to approach the general dataflow of mainVI as a user GUI and subVI as instrument control.

 

Download All
0 Kudos
Message 6 of 11
(1,734 Views)

Hi all,

I failed at my first attempt to implement a sequence that used a mainVI as a GUI that allowed users to set controls to be passed to a subVI that controls an instrument.

 

Attached is a pared down version of my code. Details have been removed, but the general approach should be clear.

 

In this implementation, the subVI begins, and then the mainVI's global variables are not updated, as the mainVI waits for the subVI to complete. Instead, I would like for the mainVI user to be able to update the state of the subVI in real time, and conversely, I'd like the subVI to update the indicators with instrument readings in real time.

 

This is clearly a poor approach, due to me misunderstanding dataflow and synchronization in labview.

 

Do you have any suggestions to implement a mainVI GUI and subVI instrument control?

 

Screenshot of MainVI:

CaptainKruncy_0-1682017089198.png

Screenshot of SubVI:

CaptainKruncy_1-1682017123807.png

 

Download All
0 Kudos
Message 7 of 11
(1,713 Views)
Solution
Accepted by topic author CaptainKruncy

Generally running multiple asynchronous loops requires special care as it kind of conflicts with the data flow paradigm of LabVIEW. I recommend changing your subVI into Initialize, while loop {Read} and Close VI instead.

If you insist of keeping the current design, please refer to Read and Write Main VI Control/Indicator Value from a SubVI

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
0 Kudos
Message 8 of 11
(1,680 Views)

Hi,

Ther are many ways to solve your issue. Do you want to acquire data in a separate loop?  If it's a simple acquisition based on conditions, then use the state machine pattern. If there are other tasks going on, then use the producer and consumer/ queued message handler/ channel wire. There are templates and sample projects available in the LabVIEW (File>>New/ Create Project) that will help you get started.

attaching a screenshot of P/C data vi since it has nice comments which you might find useful. Good luck.

bharathp10_0-1682047654522.png

 

bp
Message 9 of 11
(1,686 Views)

@CaptainKruncy wrote:

 

In this implementation, the subVI begins, and then the mainVI's global variables are not updated, as the mainVI waits for the subVI to complete. Instead, I would like for the mainVI user to be able to update the state of the subVI in real time, and conversely, I'd like the subVI to update the indicators with instrument readings in real time.

 

This is clearly a poor approach, due to me misunderstanding dataflow and synchronization in labview.


I'd create a Queue or User Event and send data that way.

Something like this.

UserEventExample.png

You can expand on it by e.g. sending data down to the subvi via a queue and use the Event to send data back. A classic solution is to use a cluster of String and Variant as data, that was you can name your data and send any type.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 11
(1,660 Views)