LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sequence structure replacement

we have a VI with lots of sequence structures in a state machine(enclosed).

is it possible to replace these with event structures to make it more efficient?

Thanks

0 Kudos
Message 1 of 25
(4,011 Views)

Define "More efficient".  Do you want the program to run faster?  Take up less RAM?  Be easier to debug?  Take up less disk space?

 

Event structures are usually created to handle button presses.  I see exactly one button that's for exiting the program and that's not enough to warrant it.

 

You have a lot of "Wait (ms)" nodes in your code that don't appear to do anything meaningful.  If you just want the code to run faster, I'd set the wait period on all of them to zero and then run the VI and see if it all works fine.  A few devices out there can't handle repeated quick queries but nearly all of them should be fine if you query them the instant you get the previous response.  If you start getting errors or the program spins too fast then maybe add them back in one by one with lower values than they had before.  The communications wait between your VI and your device should be enough to ensure it doesn't take up all of your CPU time.

 

Removing all of the stacked structures and sequence structures would make your code far easier to read and maintain, but probably not improve your "efficiency" much compared to removing those delays.

0 Kudos
Message 2 of 25
(3,972 Views)
  • You are using LabVIEW 2010.  I'm not sure when NI "hid" the Stacked Frame, but it certainly is not visible on the Structures Palette in LabVIEW 2016. 
  • Have you heard about the Principle of Data Flow, the key idea that lies behind LabVIEW's programming paradigm?  Did you notice the Error In and Error Out terminals on most of the NI Functions?  They are there to be used, and automatically "sequence" functions for you.  Indeed, if you remove the two Wait functions in the first Stacked Sequence, you can remove the Frame Sequence inside it and the functions will run in exactly the same way.  Sequences are rarely required, and Stacked Sequences are almost always wrong (exceptions made for those with CLD or higher certification, of course).
  • What do you know about reading data using VISA protocols?  Generally if you are reading multiple records, you don't open and close the Communication Channel for each one.  You generally open once, in a loop read repetitively, then (when you exit the loop) close the Channel.
  • If you write your own sub-VIs (you can almost always tell a Newbie because there are no sub-VIs in their code), strive to use the 4-2-2-4 Connector Pattern (the default in more recent versions of LabVIEW) and wire Error In and Error Out to the lowest outside connectors, the same place they are in many NI functions.

Bob Schor

0 Kudos
Message 3 of 25
(3,960 Views)

There's no logic in replacing a sequence structure with an event structure. That's like replacing your car for a tree, because it's more 'efficient'.

 

Event structures are great for replacing polling of user controls, but I don't see that happening in your code.

 

One of the problems is the use of a state machine, while there's (almost) no state machine functionality in the code, it's mostly a sequence.

 

90% of those sequences serve no purpose. Forcing the update of two locals with a sequence structure makes no sense. Simply update them both, and get writ or the sequence.

 

As mentioned, the rest of the sequence structures will be redundant when driver code is put in SubVIs. Preferably as methods of a class, so refs and such can be private data. That might be a bridge too far for some, I think it's actually easier...

 

If you want to evolve what you have, so it becomes interactive, an event structure will start to make sense. I'd strongly recommend doing some courses and then refactoring before extending functionality.

Message 4 of 25
(3,938 Views)

This is not written by me.. I am supposed to improve the program..

 

I recently took the CLD exam, and i was told that too much sequence structure and local variables are not recommended.. but there are lots of sequence structure and local variables..

 

What do you guys think I can improve this program?

 

Thanks so much and have a nice day

0 Kudos
Message 5 of 25
(3,920 Views)

thanks so much!

 

I am trying to improve this old VI for our digital processor..

0 Kudos
Message 6 of 25
(3,919 Views)

after the CLD you should know that by yourself.

but since you asked ..

think of code maintainability first before you go into (speed-)optimization.

so no stacked sequences!

remove code duplicity.

 

your VI looks very simple, this shouldn't be hard.

 

regards

 

EDIT: also apply state machine pattern better


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 7 of 25
(3,911 Views)

Thanks...I did not do well in the CLD. I got all most all the points for style and documentation but did not get much for functionality. 

you mean remove all stack sequence completely or replace it with something else?

if I remove the structure, I will leave these local variables and wait in the case structure? does it make sense?

0 Kudos
Message 8 of 25
(3,903 Views)

took 5 minutes on your VI to get you started

 

compare with your old one,

 

definitely decide what you want to do with all the waittimes,

i think the ones in the case structure are only interesting for the VISA write + read

use data-flow instead of sequences, which means, you should add terminals to your subvis

 

and you could think about reducing the locals ... for example could you write values after the case-structure has executed.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 9 of 25
(3,897 Views)

Well a quick glance at your code and I can say that most (not all) of the flat sequence structures in there are superfluous and could be removed without affecting the program at all.

 

The rest could probably be removed if you used the Error Cluster to force sequential execution like you are supposed to do.

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 25
(3,880 Views)