07-11-2020 05:46 AM
I need the current time assignment to be executed before case structure (see screenshot). Get Date/Time VI doesn't have error output. So I use date/time output and wire it to the CASE structure. Is it sufficient to ensure execution order (if the value of date/time isn't used in case structure) ?
Solved! Go to Solution.
07-11-2020 06:00 AM - edited 07-11-2020 06:06 AM
Apply this rule as literally as you can:
"Remember that a node executes only when data is available at all of its input terminals and supplies data to the output terminals only when the node finishes execution." One thing it doesn't mention is that a structure is considered a node when it comes to dataflow.
Now you should be able to tell me if this will work or not. (But if you can't, I can walk you through applying that rule, so don't think I'm leaving you out in the cold. I just think it would me more satisfying for you if you could figure it out yourself.)
FYI, this is where I got the quote from, and it may help you understand dataflow better: https://www.ni.com/getting-started/labview-basics/dataflow#:~:text=Video%3A%20Dataflow%20Programming....
07-11-2020 06:41 AM
Bill, I know this rule, it's an elementary LV knowledge.
But I think now that the assignment date/time to global variable is "independent" so it can happen even after execution of case structure. The only execution order I can be sure of is: Get Time/Date -> case structure.
So solution is to use flat sequence for example.
Am I right?
07-11-2020 09:09 AM
Hi, You can use flat sequence to ensure the execution order of Get Data and time function before the case structure.
Best Regard.
07-11-2020 10:18 AM - edited 07-11-2020 10:27 AM
I don't know this for a fact, but I believe the way you drew it, the local variable assignment is getting done before the execution of the case structure.
If you go with the 2 rules that Bill listed.
1. A node (or structure) doesn't execute until it has all its inputs.
2. A structure doesn't complete and provide output until all the code inside of it completes
you can carry that a step further and consider the wire of the timestamp a sort of structure itself with many branches, and it isn't going to execute any code beyond a branch until it has provided the data to the ends of all of its branches.
That is my belief, and if I'm wrong, please someone correct me. I've wondering this same thing from a long time ago, but I've never seen LabVIEW behave otherwise, but then again, I haven't had that many situations where it mattered. To be truly sure it executes the way you want, do what Emna said and apply a single frame flat sequence around the writing of the global variable.
PS:. You have an image in your signature line that is not showing up. It just says File Not Found.
07-11-2020 10:32 AM
@billko wrote:
Apply this rule as literally as you can:
"Remember that a node executes only when data is available at all of its input terminals and supplies data to the output terminals only when the node finishes execution." One thing it doesn't mention is that a structure is considered a node when it comes to dataflow.
...
Actually, a structure is a type of node: Generic.GObject.Node.Structure
07-11-2020 10:35 AM
@RavensFan wrote:
I don't know this for a fact, but I believe the way you drew it, the local variable assignment is getting done before the execution of the case structure.
...
Not true. The order is indeterminant.
07-11-2020 10:38 AM - edited 07-11-2020 10:45 AM
Writing to the global variable and executing the case structure occurs in parallel and there is no way to tell what happens first. Both depend on the timestamp and must wait before the timestamp is obtained.
(Reading the boolean and getting the timestamp also occurs in parallel, but only the case structure depends on the boolean.)
While the case structure does not "use" the timestamp value, it will still wait because that wire is a strong clue to the compiler about desired execution order and will not be eliminated as dead code.
Another example:
07-11-2020 04:29 PM
@petrnowak wrote:
Bill, I know this rule, it's an elementary LV knowledge.
But I think now that the assignment date/time to global variable is "independent" so it can happen even after execution of case structure. The only execution order I can be sure of is: Get Time/Date -> case structure.
So solution is to use flat sequence for example.
Am I right?
What I am saying is that you can definitely tell if it's going to do what you expect it to do any applying that rule. If you can't, you haven't tried hard enough. In this case, it seems that you were just too tentative about your conclusion. But don't worry, you were right - you need a flat sequence structure around the writing to the global to make sure the global is updated before the case structure is executed.
07-11-2020 04:34 PM
Every time I think I cannot determine what is going to happen (because i'm not sure, not because the code is ambiguous), I force myself to repeat that rule to myself for every node I come across. Eventually, you understand how it wants to run. And it's not always the way you want it to run! 😉