LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write/read in the same loop

Hello,
 
I misunderstand the timing inside the for loop. Look at my example. The problem is that the reading value is always one turn behind the writing value. If I put a sequence structure on the writing property node everything is alright. Am I dreaming or the Write property node takes the old value on the iteration 0 and when I put a sequence structure on the Write2 property node I force him to wait before doing the iteration.
 
Can someone explain me how it really works ?
 
Thanks
0 Kudos
Message 1 of 7
(3,025 Views)
The problem you have is that the property node where you write the iteration value is in a race condition with the for loop.  Since there is no data dependency or any other method that forces one operation to happen before the other, the order of execution depends on unpredictable factors.
 
Try taking the output of the property node (the error cluster) and wiring it to the for loop.  You don't have to use the value, just wire it to the for loop, so that the write is forced to execute before the for loop.  This will fix your problem (assuming that you want the iteration value to be written before the for loop executes.)  
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 2 of 7
(3,021 Views)
Also, the sequence structure in the second for loop is unnecessary because you already have a wire going from one to the other and that forces the order of execution.
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 3 of 7
(3,014 Views)
Try using the Highlight execution button (Yellow bulb on the menu of the block diagram) and running your code.  You will see dataflow at work.  Also, the inner property node where you read the "Write" value is unnecessary since you could take a wire from the "i" of the outer loop and wire it in.
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 4 of 7
(3,010 Views)
Thanks for your answer, it works,
 
Have you ever find a document which explain execution's order of Labview stuff ?
 
 
0 Kudos
Message 5 of 7
(3,009 Views)
Doyon,
 
In general, LabVIEW executes left to right, as you already know.  However, this left-right execution isn't dependent on relative position on the block diagram but rather on data flow left-right.  Hence, your writing to the Write node and your inner For loop began execution at the same time because neither operation had to wait on previous data; tying the error cluster to the inner For loop means that the inner For loop cannot begin until it receives the output of the write command, guaranteeing the proper sequence of events.
 
Highlight Execution is a powerful tool to check for race conditions or to see if something is executing differently than the expected order.  If you have a long VI and you only want to see a specific part of it execute, right-click a wire leading into an area of interest and Insert Breakpoint.  You can then run the VI full speed, but it will pause when it comes to the breakpoint.  From there you can continue with highlight execution or go through steps one-by-one with the Single Stepping controls.
 
There are several places to look for general execution order help.  Go into LabVIEW Help, select the Index tab, and then type in "execution."  See "execution flow" under that topic.   Also look at LabVIEW Help and Find Examples on queues, notifications, registering events, semaphores, and sequence structures.  A search for "execution order" in the forums will also bring up a lot of related discussion forum postings that have been answered.
 
Hope that helps.
David C
Applications Engineering
0 Kudos
Message 6 of 7
(2,990 Views)
Another good topic in the on-line help is 'dataflow programming model'.
0 Kudos
Message 7 of 7
(2,984 Views)