LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Weekly Nugget 06/12/2006

Today I'll talk about something you may not know regarding Flat Sequence Structures.  Check out these two code screenshots:
 
          
 
They look like they do the same thing, right?  Wrong!  One little-known fact about Flat Sequence Structures is that individual frames will execute if they don't have any outside data flow dependencies.  So in the first example, the entire Flat Sequence Structure must wait until the While Loop ends until it can execute.  But in the second example, the first frame of the Flat Sequence Structure will actually run independent of the While Loop, while the second frame must wait until the loop is done.  I remember spending a lot of time debugging some code back in LabVIEW 7.0 that was not behaving as I expected, and this peculiar behavior of the Flat Sequence Structure was the culprit.
 
Why does it behave this way, you may ask?  Well, during development of the Flat Sequence Structure, LabVIEW R&D decided that this kind of wiring scheme should be supported:
 
 
...and in order for this to be supported, the first frame of the Flat Sequence Structure obviously must execute before the third frame has all its inputs available (since the first frame is *supplying* the third frame with its input).
 
-D

P.S. - Check out past nuggets here.

Message Edited by Darren on 06-12-2006 11:42 AM

Message 1 of 14
(16,614 Views)

That's nice to know. Is it mentioned in the help for the sequence structure? (Not that I'd expect anyone to go read the help for the sequence structure if the code wasn't working... Smiley Wink


___________________
Try to take over the world!
0 Kudos
Message 2 of 14
(16,598 Views)

Yes, the help does mention this fact.  Here's an excerpt from the on-line help for the Flat Sequence Structure:

"Data flow for the Flat Sequence structure differs from data flow for other structures. Frames in a Flat Sequence structure execute from left to right and when all data values wired to a frame are available. The data leave each frame as the frame finishes executing."

But in my defense, when I encountered this behavior, I was using a very early pre-release version of LabVIEW 7.0...I'm guessing the help hadn't been written yet.  😉

-D

0 Kudos
Message 3 of 14
(16,590 Views)
I'm curious: why did R&D feel that the wiring scheme you showed in your third picture need to be supported? This seems to be counterintuitive to the basic idea of a sequence structure.

I didn't know about this "feature", and I'm not sure what to think of it. It would seem to me to be a potential source of more errors, as your experience indicated. I guess, though, it doesn't really matter whether you like it or not. If you don't like it, don't use it. You just need to be aware of it.
Message 4 of 14
(16,579 Views)

I wasn't part of the original decision making process on the Flat Sequence Structure, but I can see how it would be rather restrictive if only certain wires could enter non-initial frames of a Flat Sequence structure.  I haven't ever run into a case where I would need the behavior illustrated in my third screenshot above, but there is the possibility that I will need it someday in the future, and I'm glad it's there just in case. 

-D

0 Kudos
Message 5 of 14
(16,571 Views)

At first thought, this sounds like a "poor man's" rendevou

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 14
(16,568 Views)
It works pretty well as a simple rendezvous.

I've used this to ensure that all of my state machine states are cleaned up before the queue is destroyed (see attached image).

Was the flat sequence really necessary?  Well, no, but it's pretty clean looking.

Joe Z.
0 Kudos
Message 7 of 14
(16,425 Views)
What am i missing (see attachment) where the second frame waits for the first. is this only applicable for non UI-vis?

Ton (or did i not understand what Warren said)

Message Edited by TonP on 06-14-2006 09:30 PM

Message Edited by TonP on 06-14-2006 09:35 PM

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Download All
0 Kudos
Message 8 of 14
(16,401 Views)
Interestingly, I run ito this behavior a few months where I had two "three-frame sequences" for benchmarking (tick..code..tick in each). I was puzzled for a while that the first tick in each sequence started running immediately even though I "sequenced" the two seqeunces by wiring and output from the last frame of one sequence to the middle frame of the second sequence. Moving the wire to the first sequence cured it. 😄
 
Reading the online help somehow would not have helped much illuminating this specific behavior, the description is too condensed for me.
Message 9 of 14
(16,391 Views)


@TonP wrote:
What am i missing (see attachment) where the second frame waits for the first. is this only applicable for non UI-vis?

Ton (or did i not understand what Warren said)

 

In your example, the frames execute sequentially of course. Darrens nugget discusses how individual sequence frames execute in relation to other parts of the code. In the example:

Frame 1 and the while loop can execute simultaneously because there is no data dependency. Frame 2 must wait until both frame 1 AND the while loop have completed.

Message 10 of 14
(16,358 Views)