Understanding LabVIEW Programming Patterns and Frameworks
Understanding LabVIEW Programming Patterns and Frameworks
bit.ly/dnattlvtroubleshooting
• Link to video recordings on YouTube
• Link to download slides and demos
• Slides contain links to additional resources
• Links to other presentations in the series
ni.com
Introduction to LabVIEW Design Patterns
and Frameworks
Some of the content in this section was borrowed from a design patterns presentation by
Andreas Kreiseder
ni.com
LabVIEW Design Patterns and Frameworks
State Machine
Execute a sequence of events. The order is determined programmatically,
which means code can be skipped or executed multiple times in a row.
LabVIEW Design Patterns and Frameworks
Available as a project template: File > Create Project > Simple State Machine
LabVIEW Design Patterns and Frameworks
Producer / Consumer
In this pattern, one loop generates data that is consumed by another loop. The
communication mechanism between loops is usually a queue.
This pattern requires that the consumer process the data faster than the
producer generates it. Otherwise the queue grows without bound, or the
producer loop gets throttled by a maximum queue size.
Producer / Consumer
LabVIEW Design Patterns and Frameworks
LabVIEW Frameworks
What is a Framework?
Definition: A starting point for an application. Based on one or more design
patterns, and usually including tooling to improve developer experience.
Error Generation
Error Propagation } The focus of this section
Error Response
Error Display
Error Logging
Best Practices for Error Generation and Propagation
Error Generation - the creation of an error value at the point that something
goes wrong in your LabVIEW code.
Error Propagation - the act of moving an error value through your LabVIEW code.
• There are many aspects to error propagation:
• Forking an error wire to parallel code paths
• Merging errors from parallel code paths
• Skipping execution of some nodes when an error occurs
• etc.
• There are many tools to facilitate error propagation:
• Case Structure
• Merge Errors function
• Shift registers
• etc.
•
But there is one overarching rule for error propagation…
Best Practices for Error Generation and Propagation in LabVIEW
What if you want your loop iterations to run independently, regardless of error?
B. Best Practices for Error Generation and Propagation in LabVIEW
• You should be able to look at a block diagram and know exactly how that diagram
will function with an error condition
• Patterns described in this presentation
• Good code documentation
• With auto error handling, there’s no way to know if the VI is going to pop up error
dialogs or not without viewing the VI Properties
Definition
Definition
Refactoring – The process of redesigning software to make it more
readable and maintainable so that the cost of change does not increase
over time
Usually does *not* involve adding new features, so it’s sometimes hard
to justify to managers.
Refactoring Poor Variable Naming
Excessively short names
Excessively long names
See the LabVIEW Style Checklist for file and parameter naming guidelines:
https://zone.ni.com/reference/en-XX/help/371361R-01/lvdevconcepts/checklist/
Refactoring Duplicated Code and/or Complex Code
Refactoring Unnecessary Complexity