From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How Big Should The Main Vi Be?

I am fairly new with Labview working on a project which was handed over to me. Well the main VI had over 8000 nodes, which I now cut down to about 3500 nodes. I am reading through a book (The Labview Style Book). It suggest the Modular Index should be higher than 3.0.

 

Modularity Index = (# user VIs / total # of nodes) x 100

 

I am currently at 1.5 🙂

 

And I do not see any possible places to reduce the nodes.

 

Thus I have a question, is it possible to run parrallel loops which I have in my main VI in different VI's? I have a few stations that has to work in parrallel to each other and I mainly use state machines. Or what is the best method to do this?

 

Or is it possible to start a measurement from a DAQ card and only get the results once it is finished?

 

I also have a loop mainly for my manual operation, using events when a button is click. Is it possible to use an On Event structure in a subVI for buttons pressed on the Main VI?

 

Values I am using in most of my loops, I do not use locals as I read it is not a good idea. By what I use is I write information to cluster control and then read it again at a different place in my program and subVI's. Is this the best method to do this?

 

 

One last thing for now, as I do have a million questions 🙂

I am communication with a Siemens PLC using a DP Dp Coupler and sometimes signals do not get send from the NI machine to the PLC and vice versa, I know the problem does not occur at the PLC side. So my question is what is the best method to send receive signals between the machines?

 

Thanks, and any help in my questions would be greatly appreciated

 

Regards

 

Message 1 of 11
(2,989 Views)

You definitely are on right path. SubVis are you best friends. To your question:

-------------------------------------------------------------------------------------

Thus I have a question, is it possible to run parrallel loops which I have in my main VI in different VI's? I have a few stations that has to work in parrallel to each other and I mainly use state machines. Or what is the best method to do this?

-------------------------------------------------------------------------------------

 

As I understand you want stations running in parallel. There can be different ways to do it. State machines that you mentioned or another design pattern is producer consumer. For state machine here is a blog that describes it pretty well.

The basic concept of producer consumer can be found here.

 

*************************************************
CLD
*************************************************
0 Kudos
Message 2 of 11
(2,954 Views)

Oh the blog on state machine can also be found here or you can see the last tweet per the previous link.

*************************************************
CLD
*************************************************
0 Kudos
Message 3 of 11
(2,952 Views)

It definitely sounds like you are going about things the right way. Regarding your question about whether parallel loops can be placed in subVIs and included on the main block diagram as simple subVI calls, the answer is yes. This is perfectly acceptable. Depending on your situation if you are running several of the same devices in parallel you may consider dynamically spawning the tasks to handle each device. If you simply place 4 loops for 4 devices on the block diagram (or 4 copies of the same VI) your application will be limited to only 4 devices running at one time. If you dynamically call the VI your application can support any number of devices at the same time.

 

You can pass data from a subVI running a while loop without waiting for it to complete. You can use queues, notifiers, LVOOP objects or action engines (functional globals). I generally like to use queues.

 

You can use multiple event structures in your code but I would recommend against using them in subVIs to handle UI tasks. You should try to keep all the UI processing in a single event structure. Using queues you can pass data between different subVIs and queues are similar to events in that you can wait on a queue and that task will not consume any processing time until an element is placed in the queue. You can also use user defined events with event structures. However, as I suggested you should avoid processing UI events (buttons presses and the like) all over your code. It will make it much more difficult to maintain and debug.

 

As for data within a subVI or state machine you don't have to use any controls or indicators. You can pass the data through the state machine via shift registers. Use the controls/indicators if a user will be interacting with that data or if you will be passing it out of the VI via the connector pain. If you are simply looking for some place to put the data while you are working on it shift registers work very well for this. Unlike text based languages you do not need to declare variables. The wires are the values. They are the "storage" for your data in the code itself.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 4 of 11
(2,941 Views)

To Paraphrase Einstein:

 

Q: How Big Should The Main Vi Be?

Ans: As big as necessary, but no bigger.

0 Kudos
Message 5 of 11
(2,934 Views)
Thanks for all of your reply's, I guess I would have to do some research on how producer consumer work, etc
0 Kudos
Message 6 of 11
(2,904 Views)

@hein123 wrote:

Thus I have a question, is it possible to run parrallel loops which I have in my main VI in different VI's? I have a few stations that has to work in parrallel to each other and I mainly use state machines. Or what is the best method to do this?

 


Assuming the stations are identical and can work from their own VI i'd spawn them through VI server as separate processes. Then they'll be self relienat and the queues already mentioned (and Action Engines) a natural way of transferring data.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 11
(2,871 Views)

 

@Mark Yedinak wrote:

 

> You can pass data from a subVI running a while loop without waiting for it to complete. You can use queues, notifiers, LVOOP objects or action engines (functional globals). I generally like to use queues.

For LVOOP you must be talking about by reference right?

 

> If you are simply looking for some place to put the data while you are working on it shift registers work very well for this

I have really started to like using feedback nodes instead of shift registers whenever possible.

=====================
LabVIEW 2012


0 Kudos
Message 8 of 11
(2,865 Views)

@hein123 wrote:

Thus I have a question, is it possible to run parrallel loops which I have in my main VI in different VI's? I have a few stations that has to work in parrallel to each other and I mainly use state machines. Or what is the best method to do this?

 


Assuming the stations are identical and can work from their own VI i'd spawn them through VI server as separate processes. Then they'll be self relienat and the queues already mentioned (and Action Engines) a natural way of transferring data.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 11
(2,862 Views)

@SteveChandler wrote:

 

@Mark Yedinak wrote:

 

> You can pass data from a subVI running a while loop without waiting for it to complete. You can use queues, notifiers, LVOOP objects or action engines (functional globals). I generally like to use queues.

For LVOOP you must be talking about by reference right?

 


In my current project we actually create an object containing the information we want to transfer in some cases. (Made in G# with event callbacks creating an event with an object as argument)

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 11
(2,860 Views)