LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clean up block diagram using SubVIs

Solved!
Go to solution

Hi guys and welcome to my first post!

 

I´m kinda new to labview, so please be a bit patient if i dont understand everything right away Smiley Happy

 

Im working on an existing program which is used to control a MCU over BabyLin on my front panel, while i have a visualization to see the live changes of the system. The program is working fine so far, however i´m trying to clean up the block diagram. This should be realised by subvis, right? I´ve read a lot about the block diagram size shouldnt expand my screen. Well, im at a size of approx. 3x2 screens ( 24" !!) after trying to use subvis and shorten all distances between structures. The only things remaining are huge amounts of local variables and references ( they were already existing before i got to know the program ) , mostly for the visualization. If i create a subvi out of a part containing locals, it will change them to references which doesnt make the program more readable ( and smaller ), and i guess i cant put a new subvi over the references + subvi.

 

Do you have any ideas what to do? I hope i didnt forget anything, otherwise feel free to ask.

 

Kind regards,

Leo

0 Kudos
Message 1 of 12
(4,884 Views)

Hi NauOrNever,

 

You should use the clean up fonction already integer in your  development environment.

 

There is a tutorial about it: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000x20uCAA&l=fr-FR

 

Best regards.

 

Sabri JATLAOUI - Certified LabVIEW Architect - Certified LabVIEW Developer
Message 2 of 12
(4,874 Views)
Replace all of your local variables and references with wires before trying to create subVIs.

A major thing that you forgot to do was attach your code.
Message 3 of 12
(4,867 Views)

If it ain't broke, don't fix it....at least until you know what you are doing.  If this is an exercise to learn more about Labview, please work from a backup copy and not the working version of the code. 

 

 

aputman
Message 4 of 12
(4,843 Views)

To get a handle on the structure for your Top Level code, write down (as though you were telling your Boss, or telling your Wife -- who knows, they might be the same Person!) what you are trying to do.  Keep it fairly general.  Did you specify a number of steps?  Then maybe the Top Level should be a State Machine, or a Queued Message Handler.  Did you describe something that runs at a constant speed, generating data that you have to handle "on the fly"?  Maybe it is a Producer/Consumer Design.  

 

Do you have a lot of initialization?  Put it in a sub-VI, bring the 20 wires out in a bundle (that's "Boss-Speak" for a Cluster).  Your main program should have a few loops, with values that persist (possibly changing) during the program running in Shift Registers near the top of the loop, with Arrays and Clusters used to keep related items "consolidated".

 

Don't be too embarrassed by the size of your routine -- I recently downloaded a 50-monitor Monster from the Forums (I didn't even try to figure it out), so 6 monitors is nothing!

 

Let "encapsulate function" and "hide the details" be your guide in thinking about creating sub-VIs.

 

Bob Schor

Message 5 of 12
(4,810 Views)
Solution
Accepted by topic author NauOrNever

@Bob_Schor wrote:

To get a handle on the structure for your Top Level code, write down (as though you were telling your Boss, or telling your Wife -- who knows, they might be the same Person!) what you are trying to do.  Keep it fairly general.  Did you specify a number of steps?  Then maybe the Top Level should be a State Machine, or a Queued Message Handler.  Did you describe something that runs at a constant speed, generating data that you have to handle "on the fly"?  Maybe it is a Producer/Consumer Design.  

 

Do you have a lot of initialization?  Put it in a sub-VI, bring the 20 wires out in a bundle (that's "Boss-Speak" for a Cluster).  Your main program should have a few loops, with values that persist (possibly changing) during the program running in Shift Registers near the top of the loop, with Arrays and Clusters used to keep related items "consolidated".

 

Don't be too embarrassed by the size of your routine -- I recently downloaded a 50-monitor Monster from the Forums (I didn't even try to figure it out), so 6 monitors is nothing!

 

Let "encapsulate function" and "hide the details" be your guide in thinking about creating sub-VIs.

 

Bob Schor


To expand on Bob's analogy, each talking point can be a SubVI.  In other words, group related code into subVIs.  The advantage of this is that it's much easier to troubleshoot because all errors will be localized to a subVI.  No more chasing errors around the block diagram.  I guess you can use your current VI as an example of what NOT to do on the block diagram.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 12
(4,775 Views)
Take little steps. Cleaning up bad code is am iterative process. Don't go crashing through the code, like Sherman marching through Georgia...

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 7 of 12
(4,763 Views)

@mikeporter wrote:
Take little steps. Cleaning up bad code is am iterative process. Don't go crashing through the code, like Sherman marching through Georgia...

Mike...

That's sound advice.  Messy code is often poorly written in other ways, too, and even a simple refactoring that would be harmless with well-written code may cause code to fail in subtle ways as the races in different race conditions start being won by different participants than had been the case in the past.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 12
(4,743 Views)
One of the things you will be doing during the refactoring is learning how the code works -- which is often very different from how it is supposed to work, and even different from how the original developer thinks it works.

Race conditions can be a huge problem, as well as logical errors that cancel each other out.

Oh, yes. Use bookmarks to annotate thing you know are wrong but don't have time to fix right now.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 9 of 12
(4,722 Views)

@mikeporter wrote:
One of the things you will be doing during the refactoring is learning how the code works -- which is often very different from how it is supposed to work, and even different from how the original developer thinks it works.

Race conditions can be a huge problem, as well as logical errors that cancel each other out.

Oh, yes. Use bookmarks to annotate thing you know are wrong but don't have time to fix right now.

Mike...

A word of caution before making changes to how the code works.  Unless the object was to actually fix the code in that area, it's a good idea to ask permission or at least let someone know of your intentions before doing so.  If this is test software, for instance, units that used to pass before may fail now, and vice versa, quite possibly leading to discrepancies between your company's test results and the customer's.  Above all, unless the object was to fix a problem, the software should work as it did before - whether or not it was working as intended!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 10 of 12
(4,685 Views)