Professional Documents
Culture Documents
Overview
LabVIEW and the G programming language were
released by National Instruments (NI) in 1987. Up to
that time programmers commonly controlled an
instrument from a computer by making toolbox calls
through RS-232, GPIB (and sometimes parallel) interfaces. NI still supports this kind of access for developers who are using non-G compilers. In addition, in its
first release, LabVIEW offerred special VIs for the
specific access of RS-232 and GPIB ports. But since
Release 4.0, and especially since the advent of VXI
devices and the call for greater standardization, NI
has promoted a more general structure for interface
access. 1 This structure is called VISA. It is based on a
What VISA is
VISA is an acronym for Virtual Instrument Standard
Architecture. As described by NI, VISA is a standard
I/O Application Programming Interface (API) for instrumentation programming. VISA by itself does not
provide instrumentation programming capability.
VISA is a high level API that calls into lower level
drivers (Figure 5-1). Common VISA VIs can control
VXI, GPIB, or RS-232 instruments making the appropriate driver calls depending on the type of instrument
being used. Because VISA is an industry standard for
developing instrument drivers, most instrument
drivers currently written by NI use VISA and therefore support most major computer platforms if the
system level drivers exist for that platform.4
VISA uses the same high-level operations to communicate with instruments regardless of the interface
type. This means that the VISA command to write an
ASCII string to a message-based instrument is the
same whether the instrument is of VXI, GPIB or RS-
VISA
VXI
GPIB
Serial
NI-VXI
NI-488.2
OS Calls
5-1
Portability
Another advantage of VISA is that a program written
with VISA function calls on one platform is more
easily ported to another. To make this possible VISA
strictly defines its own data types. Issues like the size,
VISA
Open
VISA
Write
VISA
Read
VISA
Close
Error wire
Figure 5-2. A block diagram of a program to control an instrument using VISA VIs. For the sake of simplicity, the necessary
controls and indicators for each block have been omitted.
5-2
Help
The help for VISA Find Resource is reproduced in
Figure 5-3.
VISA Class
VISA Class in the expression above is a grouping that
contains some or all of the VISA operations. There is a
VXI class, a GPIB class, a serial class and an INSTR
class. The INSTR class includes all VISA operations
for an instrument. If the VISA class is omitted from
the expression, INSTR class is assumed by default.
The drivers for student use in this course were written
to assume INSTR class in order to make them most
general.
Building MyFindResources.vi
You will now start building a simple standalone VI.
The first step is to place and wire VISA Find Resource.
Do the following:
Instrument Resources
GPIB
RS-232
All
Expression
GPIB[0-9]*::?*INSTR
ASRL[0-9]*::?*INSTR
?*INSTR
5-3
When you are ready to quit, save your VI in the location and under the name of your choice (MyFindResources.vi will do nicely). If you are doing this as
part of Lab #3 save your VI on the floppy disk. You
will be adding to this VI in the following activities.
Help
The help for VISA Open in LabVIEW 6.1 is reproduced
in Figure 5-6.6
5-4
VISAOpenDefaults.vi
This section is optional and you might wish to skip it
on a first reading of this chapter. To find the default
values VISA Open assumes you can run VISAOpen
Defaults.vi (Figure 5-7). Some of the RS-232 parameters,
such as baud rate, etc., are described in Appendix B.
There are a number of others:
Serial Settings
These settings apply to RS-232 communication only:
1
Adding to MyFindResources.vi
You are now ready to add a VISA Open and a Property
Node to MyFindResources.vi. Do the following:
5-5
Figure 5-10. Selecting Termination character from the Property Node pulldown menu.
5-6
To continue
Help
You write a message to your instrument with VISA
Write. Its help window is shown in Figure 5-13. The
picture of a watch in the upper right hand corner of
the icon indicates that VISA Write is asynchronous by
default. You should change this to synchronous
operation. To do this place the mouse pointer over the
icon, command click and select synchronous from the
drop down menu.
VISA Write
VISA Write takes a maximum of three controls: VISA
resource name, write buffer (), and error in (no error). VISA
5-7
VISA Close
Any session you open to a VISA resource uses system
resources within your computer (for example, the port
itself and memory set aside for buffers), so at the end
of the VISA session you should free up these
resources. If you fail to do so, the session remains
open. To close a session use VISA Close (Figure 5-15).
Adding to MyVISAProgram.vi
Add a VISA Write, VISA Read and VISA Close to
MyVISAProgram.vi as follows:
5-8
5-9
Figure 5-20. An error out cluster consists of three indicators: a boolean, a code numeric and a source string. An
error in cluster contains a status control, code control and
source control.
5-10
Taking Stock
At this stage you have a working VI. Looking back
you can see that your VI consists of a number of parts
or building blocks. In the next activity we shall have
you examine some building blocks or student
drivers that have already been prepared for you.
These drivers should make it even easier for you to
write G programs to control the other instruments
described in this course.
RSOpen.vi
The first VI we present is RSOpen.vi (Figure 5-21). This
VI performs a VISA Open specifically for an RS DMM.
It contains two sub-VIs, FindResourcesDemo.vi and
RSPrep.vi. It begins by finding the resources on the
host computer using FindResourcesDemo.vi. This VI
returns the resource name requested or, if one is not
requested, a default one.
If you wish you can open the front panels of the subVIs. If you do this you will see that RSPrep.vi uses an
attribute node to set a number of values for the
instruments RS-232 interface (the RS DMM does not
work with GPIB). The termination (EOL) character is
set for the platform used: <CR> <LF> for a Windows
PC, <CR> for a Mac, <LF> for a UNIX box.
5-11
5-12
Table 5-1. A selection of student drivers available at the time of writing. All xxxOpen VIs are similarly written and use
FindResourcesDemo.vi. These drivers are designed to be used in conjunction with other drivers and not on their own.
Driver Name
RSClose.vi
RSDecoder.vi
RSGet.vi
RSOpen.vi
RSPrep.vi
Data+.vi
TekClose.vi
TekDecoder.vi
Instrument
Radio
Shack
Auto
Range
Digital
Multimeter
Tektronix
TDS210
Digital
Oscilloscope
TekHardCopy.vi
TekIMM.vi
TekOpen.vi
TekPrep.vi
TelClose.vi
TelOpen.vi
TelWrite.vi
HPMClose.vi
HPMOpen.vi
HPPClose.vi
HPPOpen.vi
HPPPrep.vi
HPPSweepInit.vi
OHClose.vi
OHOpen.vi
Telulex
SG-100/A
Signal
Generator
Agilent (HP)
34401A
Digital
Multimeter
Agilent (HP)
3640A
Programmable
Power
Supply
Ohaus Scout II
electronic
Description
Performs a VISA Close.
Decodes the 14-byte string returned and displays the mode, numeric and unit parts
of the string in indicators.
Gets a 14-byte string. Outputs an optional time stamp for the Read operation.
Performs a VISA Open. Works only for RS-232.
Sets the values of the RS-232 parameters for the DMM.
This VI queries the instrument for the waveform data and the formatting data. It
outputs two bundles, one for each channel. Uses TekDecoder.vi.
Performs a VISA Close.
This takes waveform data in the form of a binary string and converts it to an
output array of SGLs in absolute units.
Returns a hardcopy display of the oscilloscope screen in the form of a string.
Called by TekBMPDisplay.vi.
Illustrates how to use the immediate measurement mode, the mode in which the
oscilloscope performs a measurement such as Mean.
Performs a VISA Open. Works with GPIB or RS-232. For either resource OPC?
query operation is enabled. For more information on device specific commands see
Appendix A.
Sends some initial, desireable commands to the oscilloscope.
Performs a VISA Close.
Performs a VISA Open. Works only for RS-232 since the instrument works only
with RS-232.
Writes a control string to the instrument and then purges the serial buffer of
unwanted \r\n> character groups returned by the instrument.
Performs a SYSTEM:LOCAL and a VISA Close.
Performs a VISA Open. Works with GPIB or RS-232. If RS-232 is used the serial
parameters are set and SYSTEM:REMOTE is performed. Also performs *RST and
*CLS for RS-232 and GPIB.
Performs a SYSTEM:LOCAL and a VISA Close.
Performs a VISA Open. Works with GPIB or RS-232. If RS-232 is used the serial
parameters are set. Performs *RST and *CLS for RS-232 and GPIB.
Sets up parameters for HPPSweep.vi.
Initializes HPPSweep.vi.
Performs a VISA Close.
Performs a VISA Open. Sets the RS-232 parameters and the weight units.
5-13
Table 5-2. A selection of Demo VIs available for student use. These VIs can be used with any of the instrument VIs listed in
Table 5-1.
VI Name
Description
FindResourcesDemo.vi
TwoResourcesDemo.vi
Finds the VISA resources on the host computer. This VI is used by most xxxOpen VIs.
A VI to access two resources simultaneously. The resources may be RS-232 and GPIB or both.
Table 5-3. A selection of Example Programs (VIs) available for student use. All VIs use the xxxOpen and xxxClose VI
appropriate for the instrument. If the control Resource Desired on the instruments xxxOpen VI is left unwired, a default
resource is chosen. Some of these VIs will be demonstrated in Lab #3.
VI Name
TwoResources.vi
MyRSExample.vi
RSCOMDemo.vi
RSTest.vi
Instrument
General
Radio Shack
Manual/
Auto Range
Digital
Multimeter
RSDualPort.vi
GetTekID&Time.vi
GetTekCurve&Time.vi
TekBMPDisplay.vii
Tektronix
TDS210
Digital
Oscilloscope
TekGetCurve.vi
TekGetID.vi
TekMeas1Pt.vi
TekMultiPt.vi
TekParseCurve.vi
TekTest.vi
TelGetID.vi
TelStep.vi
TelSweep.vi
HPMGetID.vi
HPMMeasVolt.vi
HPPGetID.vi
HPPSweep.vi
Telulex
SG-100/A
Signal
Generator
Agilent 34401A
Multimeter
Agilent
3640A
OHContinuous.vi
OHPCommand.vi
Ohaus
ScoutII
5-14
Description
Enables one or two RS-232 or GPIB resources to be accessed concurrently.
Reads and displays the output.
Reads and displays output when the DMM is in COM mode (when it is
sending continuously).
Performs an Open, Get and Close in slow motion steps to enable the RS-232
interface to be tested with an LED indicator box.
Gets and displays a 14-byte string from two DMMs, one on each of two COM
ports.
Gets and displays the ID and the elapsed time.
Gets and displays the waveform data and the elapsed time.
Gets and shows on a Panel in BMP format the screen display of the
oscilloscope.
Gets one channel of waveform information in ASCII format and displays it in a
string indicator.
Gets and displays an instrument ID.
Illustrates how to get a single measurement of voltage.
Shows how to turn the oscilloscope into a continuous reading voltmeter.
Illustrates how to parse the CSV file returned.
Tests the GPIB or RS-232 interface (like RSTest.vi).
Gets and displays an instrument ID.
Practice Problems
In solving the following problems you may use the student drivers listed in Tables 5-1 and 5-2.
The programs are to be written in G. Some of these problems are also described in Appendix E.
1.
2.
3.
4.
6.
5-15
VXI (pronounced vixie) stands for Virtual Extensions for Instrumentation. A VXI device is usually a rack-mounted box
lacking front panel controls that is designed to be used in research or industry. Control is entirely by computer. National
Instruments is a major supplier of VXI devices. Though you might eventually be called upon to use a VXI device in the course
of your science research, we will not using VXI devices in this course.
2
The official descriptions of Universal Serial Bus and IEEE-1394 were written by the various consortia with frequent
reference to the VISA paradigm. See for example, Appendix B and the websites
3
If you come across a text on LabVIEW written prior to 1999 you will find tutorials on how to use the special serial and
GPIB VIs. Though we realize they have pedagogical value in learning about serial and GPIB devices they are obsolete and we
shall not be discussing them here. There is no guarantee National Instruments will support these special VIs indefinitely.
Indeed, NI accepts contributions of RS-232/GPIB/VXI VIs for posting on its website only if they are written with VISA VIs.
4
Platforms supported are Macintosh (on which LabVIEW was originally developed), Windows 3.x, Windows 95/98/NT,
Solaris 1, Solaris 2, and HP-UX
5
To produce Figure 5-5 MyFindResources.vi was run by the auther on his Mac G3 powerbook which is known to have two
serial ports, only one of which has an actual connector (like many Windows PC laptops). Should you run this VI on a generic
Windows PC you should see several resource names in find list. VISA FindResource behaves subtly differently for serial and
GPIB, but in a way consistent with the functioning of the interface. It will return resource names for serial resources whether
or not serial instruments are connected to the host computer and whether or not those instruments are on. However, a GPIB
resource name will be returned if and only if the GPIB card is installed and a GPIB instrument is connected and powered up.
If the device is off the resource name will not be returned. On a Mac G3 powerbook only two resource names should have
been returned. Three are shown in Figure 5-5. (Two only are returned by LabVIEW version 5.1.) At the time of writing the
reason for the difference was not known.
6
The VISA Open VI in LabVIEW version 6.1 is subtly different from version 5.1. Indeed, in version 6.1, VISA Open and VISA
Close VIs are not actually necessary. For good programming practice, however, both should be used especially if more than
one interface is being addressed at a time.
7
A timeout is the amount of time a VI will attempt to perform its intended function. If unable to do so the VI returns an
error message. This behavior is definitely better than hanging the computer indefinitely. In LabVIEW if a timeout control is
left unwired, G will usually use a default value.
5-16