LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why are sequences so bad?

OK, Am I the only one who beleives that sequences are OK and even a good thing?
0 Kudos
Message 1 of 22
(4,028 Views)
There is no reason not to use sequences especially when you want, well, a sequence of events to happen. That is what they are for and I don't really see an easy replacement. The only downside I've every seen with them is that they must run from start to finish but again that is kinda the point.
0 Kudos
Message 2 of 22
(4,028 Views)
LabVIEW is a DATAFLOW programming language. Therefore you should use DATAFLOW to determine the sequence of events. Make sure all VI's have an error in/error out. (the ones built in to LV are attroctious for not having this unforunatly). So for instance instead of:
Sequence
1) A
2) B
3) C

Use error in/error out to string them together:
A-B-C

All the code is visible on screen at once, and there is no ambiguity as to the order of events.

Allow me to point out though that if one VI doesn't have error in/error out, or any other pass through data mechanism, you may need to use a SINGLE frame sequence structure. So for instance you might put B in a sequence structure and wire the error from A into the sequence and out the other side into C.
This is acceptable (through if you can, modify or wrap B so that it does accept error in/out).
0 Kudos
Message 4 of 22
(4,028 Views)
No, sequences are not always bad... only when there is more than one frame 🙂

Multi frame sequence structures allow you to 'shortcut' the data flow paradigm. It's easy to view the data flowing from left to right through wires, but when you have to keep jumping back and forth through sequence frames to figure out how the data is flowing, it's just not as intuitive.

I have unrolled several sequence structures in my day, and always found that the code became more readable (less of it is hidden at any one time, and the data flow is easily seen). Often times, once I can see the clear picture of what the code is doing, I can speed it up significantly.

People generaly use sequence structures when they first come from text based languages. They are u
sed to the order of lines dictating program execution order. This is what I did when moving to LV after doing years of C, Java, C++, Assembly. I used sequences myself because I thought they made more sense, until I got comfortable with the dataflow paradigm. Think of it this way:

Sequences are to LabVIEW like
GOTO is to C

remember your programming instructor said 'never use GOTO!', and he had a good reason for it!

Learn, love, and live dataflow and you'll be a happier person. I'm going to get my PHD in Visual Programming because I'm so amazed at how much better it is than textual programing.
0 Kudos
Message 3 of 22
(4,028 Views)
I totally agree with tj's statements about sequences. Multiple sequences serve no purpose except to make a program hader to read, harder to debug, and harder to modify. There's still a few LabVIEW functions that don't error in/error out clusters and putting a single sequence around these is the only acceptable use in my opinion.
0 Kudos
Message 5 of 22
(4,028 Views)
As a beginner LV'er I've gotten confused over the ways to control data flow. Something I've seen stump C++ and VB programmers to the point they refuse to use LV.

I've seen programs written and the claimed method of dataflow was as bizzare and hard to follow as the sequences!

So I ask the experts here...what is a good way to ensure dataflow? Using the error in/out wont work for many VI's. I tied some case/loops together just passing useless data...it worked but that cant be a good way.

I'm looking to turn on a set of relays using the digital I/O ...THEN...taking an analog reading. I can't have the analog portion starting at the same time...digital has to go first. I have the digital portion in a CASE...the analog in a loop...now to tie them together.


I'm looking for examples that showcase this issue, if anyone knows of any please direct me there.:)

Thanks!
JM
0 Kudos
Message 6 of 22
(4,028 Views)
Why is error in/error out unsuitable in all cases?

Pass error through your digital I/O VI's then through the analog reading VI's. The times when I don't have error in/out for a VI that are make are for things like 'trim whitespace from string'. Of course, such VI's never need to occur in a specific order (unless you are using local variables and have race conditions... but that's another topic all together).

I dont quite follow your case w/ digital IO, loop with analog IO scenerio. Does the case occur before the loop? If so just pass error out of the case and into the loop, then the order is fixed.
0 Kudos
Message 8 of 22
(4,028 Views)
"grey" wrote in message
news:50650000000500000096850000-1023576873000@exchange.ni.com...
> So I ask the experts here...what is a good way to ensure dataflow?
> Using the error in/out wont work for many VI's. I tied some case/loops
> together just passing useless data...it worked but that cant be a good
> way.

Why not to use sequences? One big reason, efficiency, and one little reason,
readability.

The sequence removes possible parallelism from your computation enforcing a
"join" once all work is completed before moving on. Rarely is the sequence
necessary, so performance will suffer. There is simply no reason to do A+B=C
followed by D+E=F because they are independant and LV likely could have
scheduled them more efficiently on its own! You're enforcing an artificial
dependancy with that sequence structure.

Also a big sequence results in lots of local variables, inputs, and outputs
being generated in different frames. It turns into an unreadable mess. It's
almost certain that you can wire a neater, more readable data-flow dependant
diagram.

What to do instead: an item on the block diagram will not start executing
until all its inputs are ready. All your diagrams should already be
conforming to the LV standards guides with error-in/error-out to handle
error conditions right? In that case the error flow will enforce ordering
because your VI will not execute until (or unless!) the preceeding VIs have
succeeded. If NI forgot the error terminals then create your own SubVI which
runs the functions only when there is no error condition; easy fix and
handles the error. Why take the measurement if there was a previous error?
More likely you want to do a different function.

As another poster suggested, some VIs come without error-in/error-out
terimals. However since mathematical, boolean, and string functions are
NEVER order dependant then who cares. When would you want sequences? When
there is a dependancy that cannot be detected by pure dataflow; when you're
using local variables, global variables, initializing property nodes, or
some physical systems. For example, "set the properties for all frontpanel
controls, THEN start executing".

In the specific case mentioned, do the digital I/O, wire along error
cluster, and then if the digital I/O succeeded the analog portion will
start. You can exploit some parallelism by allowing each to setup in
parallel, starting the digital-read if both setups succeeded, then starting
the analog-read, then executing the rest of the program. Right?

Good luck!

-joey
0 Kudos
Message 9 of 22
(4,028 Views)
Thanks TJ and Joe.

Please remember I havent looked at LV in years so I'm real rusty. I see how using the error out would work fine. But one program I was picking apart today used VI's that didnt have any error out to use. Thats why I was wondering how you do it using the basic VI's.

I have to be very careful that the digital portion that will control the relays are done in a certain order and the analog reads are done at a certain time.

>>If NI forgot the error terminals then create your own SubVI which runs the functions only when there is no error condition;<<<

Hmmm...abit confused. If I use this same program..the one with easy Digital Port Write vi...how do I know when there is an error..or no error to run my SubVi?

Sorry t
o be a pain...:)
THanks!!
Grey
0 Kudos
Message 10 of 22
(4,028 Views)
Hold on Y'all,

One of my colegues found an excelent use for multiple frame sequence structures.

In frame "0" you put all of your code. In frame "1" you can insert bitmapped diarams and other documentation that help explain your code. I find it very handy being able to flip to the other frame to remind myself which state was responcible for handling some action. These diagrams are typically your normal state diagram type (you know, bubbles with arrows, etc.)

If I could figure out how to embed these pictures in the VI info, I would probably put it there, but until then, the second frame is a great place to drop your diagrams.

Aside from that, I agree, no sequence should have more than one frame.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 22
(4,028 Views)