08-27-2024 05:23 PM - edited 08-27-2024 05:24 PM
Hi everyone,
Fairly new at LabView and I am designing a Vi that takes a current reading and translates that measurement into a PSI reading. I made the Vi and it works as intended, but when I make it into a SubVi and connect everything, I don't get an output to the main vi. What's interesting is that when I run the main Vi and look at the front panel of the SubVi, the values there are changing. Been stuck on this for hours and can't figure it out. I saw some posts on using references but others are discouraging the usage of them. Some input would be great.
Thank you!
Main Vi
SubVi
Untitled 1.vi (main)
prsi-transmitter.vi (subvi)
Solved! Go to Solution.
08-27-2024 05:48 PM
The outputs from a subVI only output when the subVI finishes running. If you're just sitting there as the subVI spins through its While loop forever, nothing gets output to the main VI.
Whatever you read about references being a bad idea is correct. Not because it doesn't work, but because it's not flexible or scalable, i.e. you can get it to work on this project but as soon as you want to copy this code to use somewhere else or modify it to work differently it will cause problems. Depending on how it's done it can also slow down your program a fair amount as the LabVIEW user interface loop is slow in some circumstances.
If you were to do it properly I would recommend a Notifier-based messaging system, but that's not your only option and may or may not be best for whatever your program gets expanded to later.
08-27-2024 06:37 PM
Ok gotcha. I'm also reading about using global variables and functional global variables. But there are so many differing opinions on which to use. This system I am building is going be using at least 5 pressure transmitters (as well as a BUNCH of other sensors and water valve controls). So I am trying to make the sub-vis as compact, efficient, and reusable as possible. Based on this information, do you have any more comments to add? Thanks for responding by the way.
08-28-2024 12:46 AM
Hi yup,
@yup860 wrote:
Ok gotcha. I'm also reading about using global variables and functional global variables. But there are so many differing opinions on which to use.
Don't use globals for data exchange (more than one direction of dataflow)…
@yup860 wrote:
Based on this information, do you have any more comments to add?
Based on the images in your first message I recommend to get rid of the (mostly useless) MainVI and only use the subVI…
Other recommendation: don't put any (quite endless) loop in your subVI. Place the loop in the MainVI and split your subVI into 3 VIs: init, DAQ, cleanup. Call those 3 new subVIs from a statemachine in your new MainVI…
08-28-2024 11:31 AM - edited 08-28-2024 11:31 AM
My thinking might be a bit wrong, but this is what I'm imagining. I'm going to have a lot of these PSI sensors so I need to make a subvi so that I don't have the copy and paste the code a bunch of times in the main vi. This project at the end is going to have A LOT more stuff in it. Is it bad practice to make the who psi vi into its own subvi and expect it to function properly?