National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm -...
-
date post
19-Dec-2015 -
Category
Documents
-
view
218 -
download
0
Transcript of National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm -...
National Instruments Confidential
National Instruments Confidential2
LabVIEW Development Tips and Tricks Revealed
Carl Ljungholm - LabVIEW Product Support EngineerTravis Hailey - LabVIEW Product Support Engineer
National Instruments Confidential
Challenge
• Starting with an existing VI• Add TCP communication
National Instruments Confidential
Challenge
• Starting with an existing VI• Add TCP communication
• How much time will it take??
National Instruments Confidential
Merge VIs
• Reuse common pieces of code• VIs on Functions palette can be
configured to be merged when dropped• Enabled by customizing palette
• Example: Dropping a Wait Until Next ms Multiple with delay already wired
National Instruments Confidential
LabVIEW Development Tips and Tricks
• Program Architecture• Building Applications• Debugging• Memory Management• Performance• Miscellaneous
National Instruments Confidential7
Program Architecture
National Instruments Confidential
Program Architecture - General
• Separate time-critical code from UI updates and data transfer
• Use templates from the New dialog– Producer/Consumer (Data)– Master/Slave
• Use subVIs!– Easier to test/debug– Can use VI Profiler
National Instruments Confidential
Functional Global Variables
• Uninitialized shift registers store values• Use in subVI to retain data between
calls• FGV can store data or be more complex
– Enum input controls action• Read or Write• Initialize, Write, Close
National Instruments Confidential
Databases (One-Element Queue)
• A queue containing one element can serve the same purpose
• Allows multiple subVIs with different connector panes to use same data
• Queue acts as a semaphore
National Instruments Confidential11
Building Applications
National Instruments Confidential
Passing Command Line Arguments
• Command line arguments can be passed to LabVIEW• Use – (two dashes) to mark beginning of user arguments• Read arguments using Application property• For an executable all arguments can be passed to the VI
– Option in Application Builder
Application.Command Line Arguments
National Instruments Confidential
Stripping Paths
National Instruments Confidential14
Debugging
National Instruments Confidential
Custom Probe
• Use your own indicator for probes– Can have a break condition– Can contain code
• Right-click wire and choose Custom Probe>New
National Instruments Confidential
History Probe
• Combining custom probes and functional global variables gives a history probe
• Past values stored in shift register
• Display past values, calculate min/max/average
National Instruments Confidential17
Memory Management
National Instruments Confidential
Memory Management - General
• LabVIEW handles memory management automatically– You do not need to code when to allocate or deallocate
memory
– You have less control over when memory operations occur
• Performance can be improved by paying attention to
memory
National Instruments Confidential
Finding Memory Allocations
• Use to avoid unnecessary memory copies
• Shows a dot where memory is allocated• Tools>Advanced>Show Buffer
Allocations• Can NOT remove all allocations
National Instruments Confidential
Hiding the Dots with Inplaceness(Avoiding memory allocations)
• Inplaceness allows reuse of memory• Occurs when
– Input and output have same datatype and size– Overwritten data is not needed
• Replace Array Subset is inplace• Build Array is not inplace• Use shift registers
National Instruments Confidential
Wiring a Call Library Function• The way you wire to a Call Library Function tells
LabVIEW how to handle the data
Input Output Interpretation
Yes No Data not modified by DLLNo Yes Data allocated by DLLYes Yes Data allocated by
LabVIEW and modified by DLL
National Instruments Confidential23
Performance
National Instruments Confidential
Improving SubVI Performance
• Inputs are marked as required– More efficient since new inputs always provided
• Terminals are outside of structure– New output data always provided– No need to reread controls
• Inplaceness is used between input and output terminals – Allows inplaceness in parent VI– Inplaceness can traverse hierarchy
National Instruments Confidential
Performance Effects of Property Nodes
• Control and indicator property nodes are slow– Control properties require a thread swap to the UI thread to execute– Property nodes can not run in parallel– Many will force UI updates on completion of that node
• Write many properties with one node, or defer panel updates
National Instruments Confidential
•Do I have VI documentation?• Do I have avoidable Coercion Dots?• Do I have Debugging Enabled?• Do I have Waits in While loops?• Did I leave any Breakpoints?• Do I have clean and forward Wiring?• Are my VIs locked or Password protected?• Do I have Wires under objects?• Do I have Error Handling?• Do I have Hidden Objects in my Structures?• Do I have Default Icons?• Do I have Broken VIs?
VI Analyzer Checks Your Code
58 different tests !!
National Instruments Confidential
VI Analyzer Checks Your Code
• Improve the overall quality/reliability of VIs• Encourage good programming practices
(documentation, etc.)• Reduce code maintenance time by quickly finding
stylistic and functional problems• View results through interactive interface or in text-
based format (HTML, ASCII)
National Instruments Confidential28
Miscellaneous
National Instruments Confidential
Custom Shaped SubVIs
• Make subVI icons smaller• Leave white space in icon for all
three color depths
• Example:– Probe error cluster– Clear error
National Instruments Confidential
CTRL and Mouse Tricks
Hold down the CTRL key and…• Double-click subVI to open block diagram• Drag a rectangle to create space• Click terminal of two-terminal primitive to swap wires• Shift+Ctrl to get Scroll tool and pane diagram or front panel• Use scrollwheel on a case structure to scroll through cases• Access second most useful tool with AutoTool
• More shorcuts in the online help – search for “Keyboard Shortcuts”
National Instruments Confidential
Can You Do This?
• Get the strings of an enum? (with out VI Server)
• Sort clusters?
• Merge Errors (no subVI)?
National Instruments Confidential
Want Additional Tips???
• LabVIEW Help contains many tips• In particular…
National Instruments Confidential
Additional Resources
• LabVIEW Performance and Memory Management App Note• The Need for Speed, vol 7, number 4 (www.ltrpub.com)
• Managing Large Data Sets in LabVIEW• Optimizing LabVIEW Applications II• LabVIEW Development Guidelines, Ch 6, LabVIEW Style
Guide, describes good VI design and implementation practices• LabVIEW Books