From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
12-04-2014 07:10 AM
Hi, I'm a new user who is confused about transferring a value from within a while loop to another code out of it so that both codes can run parallelly.
In the time switch VI I have programmed an automated switch to turn on/off at a desired timing. The output, either 0 or 1, will be the input for "Amplitude" in the func gen VI. I have tried combining both VIs, placing time switch while loop within the func gen loop, but the function generator would not run because it could not read any input for Amplitude.
Thanks.
12-04-2014 07:23 AM
If you only care about the latest value, just use a global variable.
12-04-2014 08:31 AM
There are many ways to pass data between two loops. Some of the more common are:
There are other data passing mechanisms, but they have fairly specialized use cases that do not come up very often. I would recommend option 3, the queue. A global or local might get you partially there quickly, but the lack of timing and synchronization will probably cause you issues in the future.
12-04-2014 09:25 AM
As option, i would also add FGV/AE as it is very useful to know the concept.
Norbert
12-05-2014 08:34 AM
I agree that the functional global / action engine design pattern is useful to know, but have come to not use it very often. It is good for data encapsulation, but not messaging (which was the original question). It is also very easy for new users to misuse and create race conditions and inefficient code. Generally, I have found that if you have a problem that can be solved with functional globals, you can get a better solution using actors1 (not necessarily Actor Framework). Functional globals are great for quick solutions, but actors give you a more maintainable, scalable, long-term solution. LabVIEW lends itself to the actor model of software development, since it is inherently concurrent / parallel.
1 An actor is a free-running piece of code that has communication lines and responsibilities. In UNIX based operating systems, they are often called daemons. In LabVIEW, actors are usually implemented as a free-running, top-level VI which uses queues or events for commands and responds with queues or events. However, they can just as easily be another free running loop in the same VI (also using queues and/or events).