09-06-2018 11:38 PM - edited 09-06-2018 11:43 PM
Refer the data flow plan between the Main and Sub of a large machine code. I have just shown one Sub.VI. In reality there will be at least 20 odd sub.vi s. When the code starts it starts with the main and from the menu there, the user chooses the required sub.vi. The sub.vi loads and the main.vi then runs in the background ( FP is closed ). I would like to know what is the best option to pass data between the main and sub. Actually it is a bi directional flow as you can see from the image below. The options that we are used to is Globals / Functional Globals / Queue. Anyother method that is more efficient ? The data rates are not very high - maximum we touch 10millisecond. In this scheme the DAQMX tasks reside only with the MAIN.VI. It fetches the AI and DI signals , does some smoothing like moving Average and passes the arrays to SUB. The SUB in turn handles the inputs , takes some decisions and passes back the required AO and DO signals to the MAIN which then writes it to the relevant task.
09-06-2018 11:50 PM
If this was my project, I'd use Queues.
You can also look at Channel Wires which are a relatively new addition to LabVIEW. But I have not had a reason to try them out myself.
09-06-2018 11:53 PM
@RavensFan wrote:
If this was my project, I'd use Queues.
You can also look at Channel Wires which are a relatively new addition to LabVIEW. But I have not had a reason to try them out myself.
A big yes to that. How about shared variables ... been wanting to toy around with them but somehow think they are meant for a network environment.
09-07-2018 01:17 AM
STOP RIGHT THERE. Don't use variables of any kind to shuttle data back and forth between anything in LabVIEW. Just don't.
09-07-2018 02:46 AM
@billko wrote:
STOP RIGHT THERE. Don't use variables of any kind to shuttle data back and forth between anything in LabVIEW. Just don't.
OK will not.
Appears there is some other way to move the data around ...
Would you please let me know how else the data reaches where it is supposed to ?
09-07-2018 03:29 AM
This seems like a prime candidate for Queue or Events. The Channel @Altenbach mentions is basically some wrapped up queue functions and will work well.
It depends on some factors that you don't mention, like if the sub-vi needs to handle all data or if it's more of a UI that can miss some and it's ok, but i'll assume you want to handle all, in which case the aforementioned method are the best.
/Y
09-07-2018 10:16 AM
@MogaRaghu wrote:
@billko wrote:
STOP RIGHT THERE. Don't use variables of any kind to shuttle data back and forth between anything in LabVIEW. Just don't.
OK will not.
Appears there is some other way to move the data around ...
Would you please let me know how else the data reaches where it is supposed to ?
Across a network? I just TCP/IP with the STM library. Another option is to use Network Streams. This creates a message based communication which I have found to be A LOT more reliable and faster than using Network Published Shared Variables.
Within an application? Well, that depends on a lot of factors. If you just want to know the latest value of something with no regard of when it was updated and only one place is updating it, then a simple Global Variable will do the job quite well. But for the other 99% of the situations, I use Queues and User Events to send messages and streamed data around.
09-08-2018 10:14 AM
@crossrulz wrote:
@MogaRaghu wrote:
@billko wrote:
STOP RIGHT THERE. Don't use variables of any kind to shuttle data back and forth between anything in LabVIEW. Just don't.
OK will not.
Appears there is some other way to move the data around ...
Would you please let me know how else the data reaches where it is supposed to ?
Across a network? I just TCP/IP with the STM library. Another option is to use Network Streams. This creates a message based communication which I have found to be A LOT more reliable and faster than using Network Published Shared Variables.
Within an application? Well, that depends on a lot of factors. If you just want to know the latest value of something with no regard of when it was updated and only one place is updating it, then a simple Global Variable will do the job quite well. But for the other 99% of the situations, I use Queues and User Events to send messages and streamed data around.
Thanks. So based on the general pointers, decided to stick around with the familiar Queues.
Of course @billko asked me not to do this, but till he says what else should be done, I guess I will go ahead and use Queues.
09-08-2018 11:20 AM - edited 09-08-2018 11:22 AM
Billko was saying no to shared variables.
They are lossey, like notifies or Global variables, they maintain only last value. If you need lossless data streams queues work well and are blindingly fast within an application space. User Events also make a powerful intra application data pipe.
Don't be afraid of Action Engines either!
Small critique of your diagram. Main should not be doing anything except user interaction and firing control events to worker loops is a common practice.
Worker loops like AI and DI queued message handlers with an event structure subscribed to the user events it needs like config, start, pause, exit ... and a state machine serving up incomming data via queue, notifier, or Action Engine (depending on how many data customers there are and if it is determined statically or dynamically) are good enough for most non RT applications. Similar workers for AO and DO Tasks. Taking in data controlling the outputs and serving up status via notifier for the UI (Main.vi) is great too for most cases.
I believe DQMH uses that approach . .. check it out.
For really complex projects you might want to also have the UI separate from main so main can launch whatever UI vi is best for this system state.
09-08-2018 09:25 PM
@crossrulz wrote:
@MogaRaghu wrote:
@billko wrote:
STOP RIGHT THERE. Don't use variables of any kind to shuttle data back and forth between anything in LabVIEW. Just don't.
OK will not.
Appears there is some other way to move the data around ...
Would you please let me know how else the data reaches where it is supposed to ?
Across a network? I just TCP/IP with the STM library. Another option is to use Network Streams. This creates a message based communication which I have found to be A LOT more reliable and faster than using Network Published Shared Variables.
Within an application? Well, that depends on a lot of factors. If you just want to know the latest value of something with no regard of when it was updated and only one place is updating it, then a simple Global Variable will do the job quite well. But for the other 99% of the situations, I use Queues and User Events to send messages and streamed data around.
I knew someone would bring up using globals in just that way - I use them a lot that way myself - but I don't really consider that "shuttling values back and forth". I rarely update a global after its first initialization because I use them mostly to hold values read in from some kind of configuration file. I like globals mainly from a development perspective because you don't have to go rooting around in all your subVIs trying to figure out where that constant you need to change is located. Plus, if a parameter changes, you only need to change the config file. If the config file isn't part of the software release, you don't have to release another software build.
On the other hand, using globals to bring in "live" values are a dangerous thing if you aren't very careful.