04-19-2023 07:39 PM
Hi all,
I have been writing some LabView code that controls several different instruments.
My general control paradigm has been as follows:
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?
Solved! Go to Solution.
04-20-2023 12:30 AM - edited 04-20-2023 12:32 AM
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:
You need to work on both items.
Unfortunately you didn't attach any code so we cannot help you with specific suggestions!
04-20-2023 12:30 AM
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.
04-20-2023 06:33 AM
@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.
04-20-2023 01:13 PM
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)
(subVI)
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.
04-20-2023 01:15 PM
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)
(subVI)
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.
04-20-2023 02:00 PM
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:
Screenshot of SubVI:
04-20-2023 08:25 PM
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
04-20-2023 10:28 PM
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.
04-21-2023 03:41 AM
@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.
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.