LabVIEW: Tips & Tricks
Ihor Korolov
March 2011
Contents
GPIB communication
VISA: GPIB and Serial port configuration and communication
How to create and use *.dll in LabVIEW (C++ example)
LabVIEW Tips and tricks:
VI hierarchy Event structureApplication control (property node and invoke node)How to execute system command…..
Creating an executable VIs
Remote panel connection manager and Web publishing tool
I. Korolov: LabVIEW: Tips & Tricks
GPIB
I. Korolov: Tips & Tricks
GPIB
I. Korolov: LabVIEW: Tips & Tricks
General Purpose Interface Bus (GPIB)
All GPIB devices and interfaces must have a unique GPIB address between 0 and 30.
Address 0 is normally assigned to the GPIB interface. The instruments on the GPIB can use addresses 1 through 30. GPIB devices can be talkers, listeners, or controllers.
(IEEE-488 is a short-range digital communications bus specification) 8 data lines, 3 Handshaking lines, 5 Interface management lines HS488 can transfer up to 8 Mbytes/s (2 m cable)
GPIB
I. Korolov: LabVIEW: Tips & Tricks
General Purpose Interface Bus (GPIB)
(IEEE-488 is a short-range digital communications bus specification) 8 data lines, 3 Handshaking lines, 5 Interface management lines HS488 can transfer up to 8 Mbytes/s (2 m cable)
GPIB-USB GPIB-RS232 GPIB-PCI
GPIB - LabVIEW
I. Korolov: LabVIEW: Tips & Tricks
Use the GPIB 488.2 functions to exchange data and instructions between VIs and GPIB 488 devices
You should consider initializing the bus with the "GPIB Initialization" function before starting R/W
Virtual Instrument Software Architecture
I. Korolov: Tips & Tricks
NI-VISA
I. Korolov: LabVIEW: Tips & Tricks
Virtual Instrument Software Architecture (VISA)is a standard for configuring, programming, and troubleshooting instrumentation systems comprising GPIB, VXI, PXI, Serial, Ethernet, and/or USB interfaces.
NI-VISA is the National Instruments implementation of the VISA I/O standard
Software libraries Interactive utilities(NISpy, VISA interactive control)
Configuration programs(MAX)
The creation of a new VISA driver in LabVIEW is relatively straightforward and quick process
The majority of modern instrument drivers are based on theVISA
LabVIEW Application LabVIEW VI Library VISA Operating System
Hardware Link(GPIB, Serial, VXI …)
Instrument
GPIB - VISA
I. Korolov: LabVIEW: Tips & Tricks
Open a VISA Session to the instrument resource. Also set the timeout.
Write command from the Write Buffer control to the device
Read the data returned from the NI Close the VISA Session.
Open Write
command/dataRead data
Close
Simple GPIB-VISA session
If possible, try to use the VISA functions instead of GPIB because of VISAs versatility
GPIB- VISA
Using serial ports
I. Korolov: LabVIEW: Tips & Tricks
Serial communication uses a transmitter to send data, one bit at a time, over a single communication line to a receiver
Serial (RS-232) port
PC235
Device235
Cable connection over RS-232 interface
No Flow Control
Connector pins definition
RS-232 to USB4 x RS-232 to PCI
For hardware flow control (RTS/CTS)
VISA serial
I. Korolov: LabVIEW: Tips & Tricks
Configure Serial port
Write command/data
Read data
Close
Simple Serial-VISA session (similar to GPIB-VISA)
Closing the serial port allows it to be used by other applications without quitting LabVIEW.
Configure Serial port (baud rate, data bits, parity, stop bits and flow control)
Write bytes to port. Read the number of bytes specified
Close session to port
Serial- VISA and driver
Note: To read an information from a serial instrument, first run the “Bytes at Port” vi. This VI checks how many bytes of information are waiting at the serial port. Use this VI in a while loop to wait for a specified number of bytes accumulated in the buffer before you read the information.
How to create and use DLL
I. Korolov: Tips & Tricks
What is DLL?
I. Korolov: LabVIEW: Tips & Tricks
DLL is a file which does a particular job, and allows other programs to use its efforts in assisting the program's job. Some programs use a DLL so that they won't need to spend time figuring out how to do that job*
Dynamic-Link Library
*www.dynamiclink.nl/frames/about_dll.htm
Borland C++ Compiler
(Free) (Free)
How to create *.dll (C++ example)
Applications and DLLs can link to other DLLs
Code::Blocks (New project)
The WinAPI, is Microsoft core set of application programming interfaces (APIs) available in Microsoft Windows op. systems
This function is called when DLL is loaded or unloaded
Our function
How to create DLL?
I. Korolov: LabVIEW: Tips & Tricks
In Borland C/C++
DWORD WINAPI Function (DWORD a, DWORD b, …..);Long WINAPI Function (float *a, long b, float *c, ….);
In Microsoft C++
_declspec (dllexport) DWORD Function (DWORD a, DWORD b, …..);_declspec (dllexport) long WIAPI Function (float *a, long b, float *c, ….);
The syntax of a function declaration
Func1 = a + b
a0 = a*a*ab0 = b*b
avg = (a[0] + a[1] +…+ a[size-1]) / size
Code blocs
How to create DLL?
I. Korolov: LabVIEW: Tips & Tricks Code blocs
Our dll The header file *.h
Build dll
All of the functions we have created in the source code are available to other applications
How to use DLL in LabVIEW?
I. Korolov: LabVIEW: Tips & Tricks
???
1. Path (dll location)
2. Function name
The DLL can be called by using the LabVIEW Call Library Function
How to use DLL in LabVIEW?
I. Korolov: LabVIEW: Tips & Tricks
???
Data types LabVIEW/C++
ExampleDLLs
unsigned char BYTE; // 8-bit unsigned short WORD; // 16-bit unsigned long DWORD; // 32-bit………………. ………………….*
*http://msdn.microsoft.com/en-us/library/cc230309%28v=PROT.10%29.aspx
Instrument
1.dll 2.dll
Tips & Tricks
I. Korolov: Tips & Tricks
VI hierarchy
I. Korolov: LabVIEW: Tips & Tricks Example LP MD
View VI Hierarchy
Redo Layout—Repositions the hierarchy nodes after you expand, collapse, or move nodes.
Vertical Layout—Arranges the nodes from top to bottom, placing roots at the top of the layout.
Horizontal Layout—Arranges the nodes from left to right, placing roots on the left side of the layout.
Include VI Lib—Includes VIs in labview\vi.lib in the hierarchy layout.
Include Globals—Toggles the hierarchy layout to include or exclude global variables.
Include Type Definitions—Toggles the hierarchy layout to include or exclude type definitions.
The “VI Hierarchy” window displays a graphical representation of all open LabVIEW projects and targets, as well as the calling hierarchy for all VIs in memory, which includes type definitions, global variables, LabVIEW classes and dynamic member VIs, etc. Use this window to view the subVIs and other nodes that make up the VIs in memory and to search the VI hierarchy*.
*http://zone.ni.com
Event structure
I. Korolov: LabVIEW: Tips & Tricks
The Event structure waits until an event happen, then executes appropriate case to handle that event
Example Event
Right click on the structure border Add event case Configure which events to handle
Place the event structure on the block diagram
Scroll Through Structure
I. Korolov: LabVIEW: Tips & Tricks
Use Ctrl + Mouse Scroll to scroll through:
Case Structures Event Structures Stacked Sequence Structures Diagram Disable Structures
Ctrl+
Example Scroll
Property node and Invoke node
I. Korolov: LabVIEW: Tips & Tricks Example PN
Right click
The “OK” button will start blinking if the “Blinking” button is pressed
Property node
Property nodes is used to get and set VI, object, or application properties
Invoke nodes is used to perform actions, or methods on VI object, or application
Property node: Cursors
I. Korolov: LabVIEW: Tips & Tricks Example PN
assist in viewing data points can be assigned to different plots lock to plot to help reading data
Cursors:
Open VI Reference
I. Korolov: LabVIEW: Tips & Tricks
This method requires a path to *.vi
Example PN
Sound, Dialog and User interface
I. Korolov: LabVIEW: Tips & Tricks
SoundDialog and
User interface
This code will run a windows calculator
Examples
Run a system command
Creating an Executable
I. Korolov: Tips & Tricks
Creating an executable
I. Korolov: LabVIEW: Tips & Tricks
With the Application Builder, you can create an executable from any operational LabVIEW VI that will run as a standalone program on any other machine with the same operating system.
Save ViNew project (add)Build specification ->Right click New -> Application (exe)
Creating an executable
I. Korolov: LabVIEW: Tips & Tricks
1
2 3
4
Build specification ->Right click New -> Application (exe)
Creating an executable
I. Korolov: LabVIEW: Tips & Tricks example
After you have pressed the "Build" button and Application Builder finishes writing the executable to disk, you are ready to run it.
Regardless of your Application Builder and LabVIEW version, you must always install any required driver files on the target machine (e.g. NI-DAQ, NI-488.2)
Install LabVIEW Runtime engine on your target computer (~100 MB). The runtime engine allows you to run LabVIEW executables without needing further LabVIEW on your or target PC.
Run your application.exe on the target computer
You can also create an installer: Build specification ->Right click New -> Installer
Remote panel Web publishing tool
I. Korolov: Tips & Tricks
Remote panel and VI/Web server
I. Korolov: LabVIEW: Tips & Tricks
Server machineMain panel and Application
Client machineViewing remote panel
Client machineControlling remote panelLANLAN
WANWAN
Remote Panels allow multiple clients to simultaneously view/control the front panel of the same VI
Remote panel connection manager
I. Korolov: LabVIEW: Tips & Tricks example
Allow access Operate Connect to remote panel…
Enable the LabVIEW VI/Web Server on the server machine Connect and execute remote panels on the client machine
Tools Options
Two main steps to connect:
1 2
Web server
I. Korolov: LabVIEW: Tips & Tricks Example MD
Web publishing tool Tools
Local PC
Web browser
To display front panels on the Web, the VIs must be in memory on the computer
The “web publishing tool” is used to view the front panels of VIs on the Web. ! Do not forge to enable the LabVIEW Web Server on the server machine
Useful links
I. Korolov: LabVIEW: Tips & Tricks
http://labviewwiki.org/Tips_and_tricks
www.ni.com/labview
Tips and Tricks on the LabVIEW Wiki
National instruments
http://learnlabview.blogspot.com
Learn LabVIEW
http://astore.amazon.com/lealab-20Books
www.forums.ni.com
NI forum
Köszönöm for your attention!
I. Korolov: LabVIEW: Tips & Tricks