LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Organising Block Diagram into Sub VIs

Hi,
 
As I am still new to Laview I have written a VI that is working to my requirements. However it is extremely messy and very large. I know I need to reduce it and organise it into sub vi's but I am not exactly sure how to do this and how I can get it to a point where I can then use it as a stand alone vi called from another vi (if that makes sense!)
 
I have attached the vi and apologise for the fact that it looks like one big mess!! I have finally managed to achieve what I need from the application but I am ashamed of how it looks and I would like to learn to create efficient modular code that is easy to follow.
 
Any suggestions would be gratefully recieved 🙂
 
Liz
0 Kudos
Message 1 of 10
(3,972 Views)

Hi Liz,

you can use only one of the constants and initialize all (all with the same type) shift registers with it. Then you can create a sub vi from your for loop which change some values. See the attached pictures, please.

Mike

Download All
0 Kudos
Message 2 of 10
(3,965 Views)

Thanks Mike,

Although I am not entirely certain I follow! Sorry. When you say I can use only one, how do I then initialize the rest from that?

Liz

 

0 Kudos
Message 3 of 10
(3,958 Views)

Hi Liz,

you can make it like this (see the picture please), the only difference is, that the array in the cluster has the same name, but you can change it to value. And then you can create a sub vi from the for loop, which change the values.

Mike



Message Edited by MikeS81 on 06-04-2008 12:38 PM
0 Kudos
Message 4 of 10
(3,953 Views)
oh yes sorry - have my stupid head on today obviously! Thanks Mike
0 Kudos
Message 5 of 10
(3,948 Views)
Liz,

Several comments which may help to improve your program:

1. Using Value property nodes is very slow. If you need to write to a control, a local variable is generally better.

2. A few of your event cases contain file I/O functions. Depending on the OS and the file size, these can be very slow, seconds or more. It is generally better to have time consuming functions outside the event structure. The guideline I use is: if a function can take longer than the time it would take the user to click something else, the function should be in a parallel loop.

More later. I have a meeting now.

Lynn
0 Kudos
Message 6 of 10
(3,916 Views)

Thanks Lynn, much appreciated. It seems that actually getting something to work was the easy part! This is just one part of a large application I am working on and having come from a .NET background where housekeeping is practically done for you there appears to be a lot to learn. I thought it would be a good idea to seperate all the aspects up and write a seperate vi for each but now I am stuggling to put them together and they are all too big individually anyway!

Liz 

0 Kudos
Message 7 of 10
(3,912 Views)
Liz,

Switching to LabVIEW from text-based languages requires some changes in thinking.

Most important is the data flow paradigm: Any node (function, subVI, Loop,..) can execute only when data is available at all its inputs. If multiple nodes have the input data criterion satisfied simultaneously, the program does not control which of them will execute first.

Next is that the wire is the variable.

Back to your program: I do not understand the data structure: Why are you using arrays of clusters which contain one array? A cluster is usually used to group unlike objects. I think you could use the arrays directly.

Any time you have repeated code, it is a candidate for conversion to a subVI. The obvious example is the for loops updating the arrays from Selected Tests.

Look at the style guides. Wiring from right to left and top to bottom with minimum numbers of bends, kinks, and reversals, and avoiding going behind other objects is much easier to read. The Load Button case is difficult to understand because of this. Also, I suspect that the Delete, Delete, Index process could be done better, but I did not attempt to figure out what is was doing.

Lynn
0 Kudos
Message 8 of 10
(3,901 Views)
Hi Liz
 
just a quick comment on housekeeping as you say and when to use subVIs or not:
 
When program it is good to have two things in mind, you program would aim to be 1 - highly cohesive and 2 - loosely coupled.
 
High cohesion - this means that you should have a sub VI or module that does one process or action. Try not to create a subVI that does multiple tasks, think of them as building bricks, each one should be separate though together they can build a larger structure. In this way you code will be clearer as you can follow the execution of it from stage to stage easily.
 
Loose coupling - this means that each subVI or module of your code should be self reliant. If some modules of your code are reliant on other modules or take data from them then a small change in one part of your program could domino into causing you errors throughout. Loose coupling will make you code far more maintainable.
 
It sounds like you are building a larger application but if you can keep these two style guidelines in mind as you work then your LabVIEW code should turn out to be a pleasant experience and more to the point so will your debugging and amending of the code at a later date.
 
best regards
 
Graham Green
Software Product Marketing
NI | Emerson
0 Kudos
Message 9 of 10
(3,844 Views)
Thank you , the advice is much appreciated 🙂
0 Kudos
Message 10 of 10
(3,824 Views)