LabVIEW Intermediate II
Connectivity
11500 North Mopac Expressway
Austin, Texas 78759
ni.com/training
What You Need To Get Started
LabVIEW Intermediate II
Course Manual
LabVIEW Intermediate II CD
• .NET Framework version 1.1 Service
Pack 1
Computer running
LabVIEW 8 and Windows XP
ni.com/training
File Locations
Root Exercises LabVIEW Intermediate II
Directory <or>
Solutions
ni.com/training
Instructional Methods
Demonstration
• Lecture gives a
foundation in the topic
• Instructor reinforces
Lecture Quiz
foundation through
demonstrations and Topic
quizzes
Development Concept
Exercise Exercise
ni.com/training
Instructional Methods
Demonstration
• Concept exercises
allow you to further
explore a topic
Lecture Quiz
• Examples:
– Watch a simulation Topic
– Experiment with example VIs
– Search the documentation
Development Concept
Exercise Exercise
ni.com/training
Instructional Methods
Demonstration
• Development exercises
give you hands-on
experience in a topic
Lecture Quiz
• Demonstration of a
finished development Topic
exercise further reinforces
the learning process
Development Concept
Exercise Exercise
ni.com/training
Getting The Most Out Of This Course
• Experiment with hands-on exercises to understand the
methods used
• Implementations given are only one possible solution—you
may find a better one
• Do not come to class prepared to develop an outside
application; concentrate on the exercises given to build a
good foundation
ni.com/training
Courses
New User Experienced User Advanced User
LabVIEW Basics I LabVIEW Intermediate I LabVIEW Advanced I
LabVIEW Basics II LabVIEW Intermediate II
Skills learned: Skills learned: Skills learned:
• LabVIEW environment • Modular application • Large application design
navigation development • Advanced development
• Basics application creation • Structured design and techniques
using LabVIEW development practices • Implementing multideveloper
• Basics of data acquisition and • Inter-application projects
instrument control communication and
connectivity techniques
Certifications
Certified LV Associate Certified LabVIEW Certified LabVIEW
Developer Exam Developer Exam Architect Exam
Skills tested: Skills tested: Skills tested:
• LabVIEW environment • LabVIEW application • LabVIEW application
knowledge development expertise development mastery
ni.com/training
LabVIEW
Course Learning Map Intermediate II
Calling Shared Serving Data to
Calling Objects a Client Using
Libraries in
in LabVIEW TCP/IP
LabVIEW
Broadcasting Publishing Data
VI Server to a Subscriber
Data
ni.com/training
Course Goals
This course prepares you to:
• Develop integrated systems
• Use networking technologies
• Programmatically control VIs using VI Server
• Implement VIs that use DLLs, ActiveX, .NET
ni.com/training
The NI Approach –
Integrated Software Framework
Test and Data Management Software
NI TestStand, DIAdem
Interactive Tools Application Development Software
LabWindows/ Measurement
SignalExpress LabVIEW CVI Studio
VI Logger Graphical Development ANSI C Development Visual Studio Components
Measurement and Control Services
ni.com/training
Lesson 1
Calling Shared Libraries in LabVIEW
TOPICS
A. Shared Libraries Overview
B. Call Library Function Node
C. Shared Library Import Wizard
ni.com/training
A. Shared Library Overview
• A shared library is a software module containing
executable code and data that can be call by
applications or other shared libraries
• Functions and data in a shared library are loaded
and linked at run time
• Shared libraries can be written in a variety of
languages
ni.com/training
Shared Library Overview (continued)
• Shared libraries expose functions and data through a
standardized interface
• Most types of shared library definition are similar to
function definitions in the C programming language
• Shared libraries are often called by different names
depending upon the platform where they are used
– Windows = DLLs
– MacOS = Frameworks
– Unix = Shared Libraries
ni.com/training
Advantages of Shared Libraries
• Most changes to a shared library do not require
changes to the calling VI
• Shared libraries allow you to call existing code in
another language
• Most modern development environments provide
support for creating shared libraries
ni.com/training
Calling Shared Libraries
• Two methods for calling a Shared Library from
LabVIEW
– Configure functions manually using the Call Library
Function node
– Allow LabVIEW to generate code by using the Import
Shared Library wizard
ni.com/training
B. Call Library Function Node
ni.com/training
Thread-Safe and Thread-Unsafe DLLs
• By default all library calls run in the User Interface thread
• Changing call to Reentrant allows the library to be called
multiple times simultaneously
• Reentrant calls require that the thread library is thread safe
ni.com/training
Thread-Safe and Thread-Unsafe DLLs
Thread Safe DLL Characteristics
– Does not contain any unprotected global data
– Does not access any hardware
– Does not make any calls to any functions that are not
thread safe
Run in UI Thread
Reentrant
ni.com/training
Calling Convention
The calling convention defines the way parameters are passed to and
from the shared library
– Cdecl
– Stdcall (WINAPI)
• Shared library documentation generally specifies the calling convention
ni.com/training
Parameters
• Each parameter corresponds to a terminal pair on the Call
Library Function Node
ni.com/training
Parameter Types
• Select a data type for each parameter
• Common Parameter Types
– Numeric
– Array
– String
– Adapt to Type
ni.com/training
Numeric Parameter Type
• Specify the numeric representation
• Determine whether to pass by value or reference
ni.com/training
Array Parameter Type
• Select the data type of the array
• Select the number of dimensions for the array
• Determine how to pass the array (Array Format)
• Identify another parameter to specify the array size if memory
needs to be allocated (one dimensional arrays only)
ni.com/training
Array formats
• Array Data Pointer,
– Type *Array - Pointer to the first element of the array
– Shared library cannot change the array’s location in memory
• Array Handle
– Type **Array - Pointer to a pointer to the first element of the array
– Shared library can change the array’s location in memory
• Array Handle Pointer
– Type ***Array - Pointer to a pointer to a pointer of the first element
of the array
– Often used for multidimensional arrays
ni.com/training
String Parameter Type
• Define the string format
• Allocate memory for the string if necessary
– Specify another parameter to define the string size
– Allocate the buffer manually by passing a string with sufficient length into the
input terminal
ni.com/training
String Formats
\00 \00 \00 \04 t e x t
LabVIEW String Handles
string length string data
\04 t e x t
Pascal String Format
string length string data
t e x t \00
string data NULL
C String Format
Character
ni.com/training
Adapt to Type Parameter
• Use to pass arbitrary LabVIEW data types to DLLs
– Scalars are passed by reference
– Arrays and string passed according to Data Format
– Clusters are passed by reference
ni.com/training
Working with Unusual Data Types
• Calling a function with unusual data types requires
a deep understanding of the data and how it is
represented in memory
• Data does not contain pointers
– Use Flatten to String to create a string containing the binary image
of the data
– Use byte order input to Flatten to String to specify native byte
order
• Data contains pointers or is otherwise complex
– Create a bridge DLL that accepts the data from LabVIEW and then
calls the other library with the expected data structure
ni.com/training
Callbacks
• Callbacks allow you to call functions from the DLL
automatically when certain events occur in the program
• Most commonly used to clean up resources allocated by
the DLL in the event of an aborted VI
ni.com/training
Exercise 1-1: Computer Name
Concept
Call a DLL function from the Windows API
GOAL
ni.com/training
C. Shared Library Import Wizard
• LabVIEW provides a wizard to automatically generate call library
function nodes and create a library of subVIs out of shared libraries
• Select Tools»Import»Shared Library to start the wizard
• Wizard requires a header file for the shared library
ni.com/training
Shared Libraries Summary
• Call Library Function node to offer easy access to your shared
libraries.
• To call a function in a shared library, you need to know the following:
– The data type returned by the function
– The calling convention used
– The parameters to be sent to the function, their types and the order in which
they must be passed
– The location of the library on your computer
– Whether the function can be called safely by multiple threads simultaneously
• The Shared Library Import Wizard allows you to automatically
generate shared library calls if you have a header file for the library
ni.com/training