32
National Instruments Confidential

National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

Page 1: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

Page 2: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential2

LabVIEW Development Tips and Tricks Revealed

Carl Ljungholm - LabVIEW Product Support EngineerTravis Hailey - LabVIEW Product Support Engineer

Page 3: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

Challenge

• Starting with an existing VI• Add TCP communication

Page 4: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

Challenge

• Starting with an existing VI• Add TCP communication

• How much time will it take??

Page 5: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 6: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

LabVIEW Development Tips and Tricks

• Program Architecture• Building Applications• Debugging• Memory Management• Performance• Miscellaneous

Page 7: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential7

Program Architecture

Page 8: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 9: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 10: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 11: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential11

Building Applications

Page 12: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 13: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

Stripping Paths

Page 14: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential14

Debugging

Page 15: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 16: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 17: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential17

Memory Management

Page 18: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 19: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 20: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 21: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 22: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential23

Performance

Page 23: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 24: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 25: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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 !!

Page 26: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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)

Page 27: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential28

Miscellaneous

Page 28: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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

Page 29: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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”

Page 30: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

Can You Do This?

• Get the strings of an enum? (with out VI Server)

• Sort clusters?

• Merge Errors (no subVI)?

Page 31: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

National Instruments Confidential

Want Additional Tips???

• LabVIEW Help contains many tips• In particular…

Page 32: National Instruments Confidential. 2 LabVIEW Development Tips and Tricks Revealed Carl Ljungholm - LabVIEW Product Support Engineer Travis Hailey - LabVIEW

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