Instrument Control
Contents
• Introduction
• GPIB communication
                 Data transfer termination
                 Data transfer rate
• Hardware specifications
• Software architecture
• Instrument I/O assistant
• VISA
         VISA programming terminology
         VISA and serial
• Instrument drivers
• Virtual Instrument Software Architecture (VISA) and IVI
• USB
• Firewire.
     INTRODUCTION
National Instruments hardware and
software connect the computer to
your application.
By providing an extensive hardware
selection, including data acquisition
and signal conditioning devices,
instrument control interfaces (such
as GPIB, Serial, VXI and PXI), image
acquisition, motion control and
industrial communications
interfaces, National Instruments
offers the widest range of solutions
for practically any measurement.
GPIB COMMUNICATION
• IEEE Standard 488.1
• known as General Purpose Interface Bus (GPIB), describes a standard interface
  for communication between instruments and controllers from various vendors.
• GPIB instruments are often used as stand-alone benchtop instruments where
  measurements are taken by hand.
• You can automate these measurements by using a PC to control the GPIB
  instruments.
• GPIB is a digital, 8-bit parallel communication interface with data transfer rates of 1
  Mbyte/s and higher, using a three-wire handshake.
• The bus supports one system controller, usually a computer, and up to 14 additional
  instruments.
• The GPIB protocol categorizes devices as controllers, talkers, or listeners to determine
  which device has active control of the bus.
• Each device has a unique GPIB primary address between 0 and 30.
• The controller defines the communication links, responds to devices that request
  service, sends GPIB commands, and passes/receives control of the bus.
• Controllers instruct talkers to talk and to place data on the GPIB.
• You can address only one device at a time to talk.
• The controller addresses the listener to listen and to read data from the GPIB.
• You can address several devices to listen.
• 5 control lines
• 3 handshake lines
• 8 bi-directional data lines.
• Devices exist on the bus in any one of 3 general forms:
       1. Controller
       2. Talker
       3. Listener
• The Controller manages the flow of information on the GPIB by sending commands
  to all devices.
• For example a ‘listen’ only device can not be made to talk to the controller.
• The Talker sends data to other devices.
• The Listener receives the information from the Talker.
Data Transfer Termination
• Termination informs listeners that all data has been transferred.
• You can terminate a GPIB data transfer in the following three ways:
    ● The GPIB includes an end-or-Identify (EOI) hardware line that can be asserted
    with the last data byte. This is the preferred method.
    ● Place a specific end-of-string (EOS) character at the end of the data string itself.
     Some instruments use this method instead of or in addition to the EOI line
     assertion.
    ● The listener counts the bytes transferred by handshaking and stops reading when
     the listener reaches a byte count limit. This method is often used as a default
     termination method because the transfer stops on the logical OR of EOI, EOS (if
     used) in conjunction with the byte count. Thus, you typically set the byte count to
     equal or exceed the expected number of bytes to be read.
Data Transfer Rate
• To achieve the high data transfer rate that the GPIB was designed for, you must
  limit the number of devices on the bus and the physical distance between devices.
• You can obtain faster data rates with HS488 devices and controllers.
• HS488 is an extension to GPIB that most NI controllers support.
HARDWARE SPECIFICATIONS
• The GPIB is a digital, 24-conductor parallel bus.
• It consists of eight data lines (DIO 1-8), five bus management lines (EOI, IFC,
  SRQ, ATN, REN), three handshake lines (DAV, NRFD, NDAC), and eight ground
  lines.
• The GPIB uses an eight-bit parallel, byte-serial, asynchronous data transfer
  scheme.
                                       •Five lines manage the flow of information across the
                                       interface:
                                       •ATN (attention)
                                       •IFC (interface clear)
                                       •REN (remote enable)
                                       •SRQ (service request)
                                       • EOI (end or identify)
The eight data lines, DIO1 through DIO8, carry both data and
command messages. The state of the Attention (ATN) line determines
whether the information is data or commands.
                             Handshake Lines asynchronously control
                             the transfer of message bytes between
                             devices. The process is called a 3-wire
                             interlocked handshake. It guarantees that
                             message bytes on the data lines are sent
                             and received without transmission error.
                             •NRFD (not ready for data)
                             •NDAC (not data accepted)
                             •DAV (data valid)
 Electrical specifications and Configurations
● A maximum separation of 4 m between any two devices and an average
 separation of 2 m over the entire bus.
● A maximum cable length of 20 m.
● A maximum of 15 devices connected to each bus with at least two- thirds of the
  devices powered on.
• The data transfer speed largely depends on the configuration of the system.
• The stackable connectors and the design of the bus allow a single computer
  interface card to be used to connect to as many as 15 instruments in a star or linear
  configuration, as shown below.
SOFTWARE ARCHITECTURE
• The software architecture for the instrument control using LabVIEW is similar to the
  architecture for DAQ.
• Instrument interfaces such as GPIB include a set of drivers.
• Use MAX to configure the interface.
• VISA, Virtual Instrument Software Architecture, is a common API to communicate
  with the interface drivers and is the preferred method used when programming for
  instrument control in LabVIEW, because VISA abstracts the type of interface used.
• Many LabVIEW VIs used for instrument control use the VISA API.
• Use the Instrument I/O Assistant when an instrument driver is not available.
• In LabVIEW, an instrument driver is a set of VIs specially written to communicate
  with an instrument.
The instrument is connected to the
computer through a built-in connector
such as RS-232 or an installed interface
board such as GPIB or VXI/MXI.
Driver-level software for instrument is
in the form of a Dynamic Link Library
(DLL).
LabVIEW is the high-level application
software layer.
LabVIEW includes built-in functions for
GPIB, serial, VXI, and computer-based
instruments that load and use the
installed driver software.
MAX (Windows; GPIB)
• Use MAX to configure and test the GPIB interface.
• MAX interacts with the various diagnostic and configuration tools installed with the driver
  and also with the Windows Registry and Device Manager.
• The driver-level software is in the form of a DLL and contains all the functions that directly
  communicate with the GPIB interface.
• The Instrument I/O VIs and functions directly call the driver software.
• Open MAX by double-clicking the icon on the desktop or by selecting Tools»Measurement
  & Automation Explorer in LabVIEW to open the window as in Figure.
• Configure the objects listed in MAX by right-clicking each item and selecting an option
  from the shortcut menu.
• The Measurement and Automation Explorer (MAX) allows you to configure the GPIB card
  and search for instruments, set the VISA alias name, run NI-Spy and configure IVI
  instrument drivers.
INSTRUMENT I/O ASSISTANT
• The Instrument I/O Assistant is a LabVIEW Express VI which you can use to
  communicate with message-based instruments and convert the response from raw data to
  an ASCII representation.
• You can communicate with an instrument that uses a serial, Ethernet, or GPIB interface.
• The Instrument I/O Assistant organizes instrument communication into ordered steps.
• To use Instrument I/O Assistant, you place steps into a sequence.
• As you add steps to the sequence, they appear in the Step Sequence window.
• Use the view associated with a step to configure instrument I/O.
• The Instrument I/O Assistant shown in Figure is located on the Functions»Input and
  Functions»All Functions»Instrument I/O palettes is a LabVIEW Express VI that allows
  you to easily test communication with your instrument and develop a sequence of query,
  parse and write steps. These steps can be saved as an Express VI for instant use or can be
  converted to a LabVIEW subVI.
• Use the Instrument I/O Assistant when an instrument driver is not available.
• To launch the Instrument I/O Assistant, place the Instrument I/O Assistant Express
  VI on the block diagram in LabVIEW.
• The Instrument I/O Assistant Express VI is available in the Instrument I/O
  category of the Functions palette.
• The Instrument I/O Assistant configuration dialog box appears. If it does not
  appear, double-click the Instrument I/O Assistant icon.
Steps to configure the Instrument I/O Assistant
• Step 1: Select an instrument. Instruments that have been configured in MAX appear in the
  Select an instrument pull-down menu.
• Step 2: Choose a Code generation type. VISA code generation allows for more flexibility
  and modularity than GPIB code generation.
• Step 3: Select from the following communication steps using the Add Step button:
        ● Query and Parse—Sends a query to the instrument, such as *IDN? and parses the
          returned string. This step combines the Write command and Read and Parse
          command.
        ● Write—Sends a command to the instrument.
        ● Read and Parse—Reads and parses data from the instrument.
Step 4: After adding the desired number of steps, click the Run button to test the sequence
of communication that you have configured for the Express VI.
Step 5: Click the OK button to exit the Instrument I/O Assistant configuration dialog box.
Serial Configuration of the Instrument I/O Assistant
      A GPIB instrument was set up, then a query (*IDN?) was sent to the
      instrument. The response was automatically parsed, resulting in a string output.
• LabVIEW adds input and output terminals to the Instrument I/O Assistant Express VI
  on the block diagram that correspond to the data you receive from the instrument.
• To view the code generated by the Instrument I/O Assistant, right-click the
  Instrument I/O Assistant icon and select Open Front Panel from the shortcut menu.
• This converts the Express VI to a subVI. Switch to the block diagram to see the code
  generated. After you convert an Express VI to a subVI, you cannot reconvert the
  Express VI.
• Once you have placed the I/O Assistant on the block diagram, the wizard opens.
• The wizard starts in the Select Instrument step, where you can choose a GPIB or
  serial instrument.
• You also can check the interface properties from this window. After selecting the
  instrument, you can add sequences to Query and Parse, Write, or Read and Parse.
• In addition, after you have set up a communication sequence with one instrument,
  you can set up additional instruments in the same Express VI.
Virtual Instrument Software Architecture (VISA)
• Virtual Instrument Software Architecture (VISA) is the lower layer of functions in
  the LabVIEW instrument driver VIs that communicates with the driver software.
• VISA by itself does not provide instrumentation programming capability.
• VISA is a high-level API that calls low-level drivers.
• As shown in Figure VISA can control VXI, GPIB, serial, or computer-based
  instruments and makes the appropriate driver calls depending on the type of
  instrument used.
• In LabVIEW, VISA is a single library of functions you use to communicate with
  GPIB, serial, VXI and computer-based instruments.
• You do not need to use separate I/O palettes to program an instrument.
• For example, some instruments give you a choice for the type of interface.
• If the LabVIEW instrument driver was written with functions on the Functions»All
  Functions»InstrumentI/O»GPIB palette, those instrument driver VIs would not
  work for the instrument with the serial port interface.
• VISA solves this problem by providing a single set of functions that work for any
  type of interface.
• Therefore, many LabVIEW instrument drivers use VISA as the I/O language.
• National Instruments initially addressed the software problems with instrument
 drivers, which helped reduce both integration time and software development
 costs.
VISA Programming Terminology
• VISA or Virtual Instrument Software Architecture is a protocol built upon 488.2
  driver and functions to meet the industry needs for having a way to easily interface
  with multiple I/Os and have all manufacturers of instruments and instrument
  drivers follow a protocol.
• VISA created by the VXIplug&play Alliance which is composed of the top 35
  instrument manufacturers such as HP. National Instruments is a leading member of
  the alliance.
• The resource name contains information on the type of I/O interface and the device
  address. You can use an alias you assign in MAX instead of the instrument
  descriptor.
• The most important objects in the VISA language are known as resources. The
  functions you can use with an object are known as operations. In addition to the
  operations that you can use an object, the object has variables, known as attributes,
  associated with it that contains information related to the object.
• Resource—Any instrument in the system, including serial and parallel ports.
• Session—You must open a VISA session to a resource to communicate with it, similar
  to a communication channel.
• When you open a session to a resource, LabVIEW returns a VISA session number
  which is a unique refnum to that instrument.
• You must use the session number in all subsequent VISA functions.
• Instrument Descriptor—Exact name of a resource.
• The descriptor specifies the interface type (GPIB, VXI, ASRL), the address of the
  device (logical address or primary address) and the VISA session type (INSTR or
  Event).
• The instrument descriptor is similar to a telephone number, the resource is similar to the
  person with whom you want to speak and the session is similar to the telephone line.
• Each call uses its own line, and crossing these lines results in an error.
• The most commonly used VISA communication functions are the VISA Write and
  VISA Read functions.
• Most instruments require you to send information in the form of a command or
  query before you can read information back from the instrument.
• Therefore, the VISA Write function is usually followed by a VISA Read function.
• The VISA Write and VISA Read functions work with any type of instrument
  communication and are the same whether you are doing GPIB or serial
  communication.
• However, because serial communication requires you to configure extra
  parameters, you must start the serial port communication with the VISA
  Configure Serial Port VI.
VISA and Serial
• The VISA Configure Serial Port VI initializes the port identified by VISA resource name
  to the specified settings.
• Timeout sets the timeout value for the serial communication.
• Baud rate, data bits, parity and flow control specify those specific serial port parameters.
• The error in and error out clusters maintain the error conditions for this VI.
• The VISA Configure Serial Port VI opens communication with COM2 and sets it to 9,600
  baud, eight data bits, odd parity, one stop bit and XON/XOFF software handshaking.
• Then, the VISA Write function sends the command.
• The VISA Read function reads back up to 200 bytes into the read buffer, and the Simple
  Error Handler VI checks the error condition.
• The VIs and functions located on the Functions»All Functions»Instrument I/O»Serial
  palette are also used for communication.
IVI (Interchangeable Virtual Instruments)
• IVI is a revolutionary standard for instrument driver software technology.
• IVI builds on the VXI plug & play specifications and incorporates new features
  that address issues such as system performance, development flexibility, and
  instrument interchangeability.
• IVI drivers also take advantage of the power of the VISA I/O library defined by
  VXI plug & play to seamlessly communicate with instruments across different I/O
  buses such as GPIB, VXI, PXI, Serial, Ethernet, and USB.
• IVI specifications subdivide instruments into classes such as digital multimeter or
  oscilloscope.
• They then create a specification for that class based on the most common features
  and functionality of the most popular instruments within that class.
IVI Instrument Classes
• Digital Multimeter
• Oscilloscope
• DC Power Supply
• Arbitrary Waveform/Function Generator
• Switch
• Power Meter
• Spectrum Analyzer
• RF Signal Generator
IVI Architecture
• IVI is an integral component of a test system.
• IVI sits above the VISA I/O layer in the program hierarchy and is integrated into
  the application development environments.
• The IVI architecture breaks the traditional instrument driver into two parts – an
  instrument-specific driver and a class driver.
• The instrument-specific driver functions the way traditional instrument drivers have
  in the past, but with an underlying architecture that is optimized for performance
  and includes instrument simulation.
• The class instrument driver contains generic functions for controlling an instrument
  category and calls the corresponding instrument specific driver functions at run
  time.
• You can write your test program with either the class driver or the specific driver,
  but only programs written to the class driver are interchangeable.
• On the right hand side are a group of components referred to as the IVI Shared
  Components.
• These components, which are created and distributed by the IVI Foundation, provide a
  common basis for configuring IVI systems and handling other tasks such as dynamic
  driver loading and error handling.
• The IVI Foundation provides the shared components to ensure interoperability between
  different vendor systems.
• In addition, the IVI Foundation has defined the IVI architecture to work with two
  interface technologies, one based on the ANSI C standard and one on Microsoft COM
  (Component Object Model) technology.
• The two architecture types are designed to be interoperable.
• You can use IVI-C drivers and IVI-COM drivers in the same application.
• With the IVI configuration utility, you can interchange instruments without recompiling
  or relinking your application source code by configuring logical names and driver
  sessions in MAX.
INSTRUMENT DRIVERS
• LabVIEW provides more than 1200 LabVIEW instrument drivers from more than 50
  vendors.
• You can use these instrument drivers to build complete systems quickly.
• Instrument drivers drastically reduce software development costs because developers do
  not need to spend time programming their instruments.
• You can reuse the drivers in a variety of systems and configurations.
• LabVIEW instrument drivers simplify instrument programming to high-level
  commands, so you do not need to learn the low-level instrument-specific syntax needed
  to control your instruments.
• The programming is broken down into general functions for the DMM.
• These instrument drivers are called LabVIEW instrument drivers because the source
  code is graphical programming made from standard LabVIEW functions and VIs.
• LabVIEW instrument drivers are in the form of VI libraries and are organized into
  categories of instrument functions.
• Consider an example where you wrote a LabVIEW VI that communicates with a specific
  oscilloscope in your lab.
• Unfortunately, the oscilloscope no longer works, and you must replace it.
• However, this particular oscilloscope is no longer made.
• You found a different brand of oscilloscope that you want to purchase, but your VI no
  longer works with the new oscilloscope.
• You must rewrite your VI. When you use an instrument driver, the driver contains the
  code specific to the instrument.
• Therefore, if you change instruments, you must replace only the instrument driver VIs
  with the instrument driver VIs for the new instrument, which greatly reduces your
  redevelopment time.
• Instrument drivers help make test applications easier to maintain because the drivers
  contain all the I/O for an instrument in one library, separate from other code.
• When you upgrade hardware, upgrading the application is easier because the instrument
  driver contains all the code specific to that instrument.
• A LabVIEW Plug and Play instrument driver is a set of VIs that control a
  programmable instrument.
• Each VI corresponds to an instrument operation, such as configuring, triggering
  and reading measurements from the instrument.
• You can locate most LabVIEW Plug and Play instrument driver in the Instrument
  Driver Finder.
• You can access the Instrument Driver Finder within LabVIEW by selecting
  Tools»Instrumentation»Find Instrument Drivers or Help»Find Instrument Drivers.
• The Instrument Driver Finder connects you with ni.com to find instrument drivers.
VIs in an instrument driver
Instrument driver model
USB (Universal Serial Bus)
• In the latest PCs, many of the peripherals such as the keyboard, mouse, scanners,
   printers, modem and even external CD-ROM drives and CD-writers are
  connected to the computer through a USB cable.
• As personal computers became more and more powerful and began to handle
  photographic images, audio, video and other bulky data, it became evident that
  existing communication buses were not good enough to carry the data back-and-
  forth between the computers and peripherals.
• The users wanted the bulky data to be moved around faster, rather than more
  slowly.
• So a group of leading computer and telecom firms including IBM, Intel,
  Microsoft, Compaq, Digital Equipment, NEC, and Northern Telecom got
  together and developed USB.
Architecture of USB
• The USB is a medium-speed serial data bus designed to carry relatively large
  amounts of data over relatively short cables: up to about 5 m long.
• It can support data rates of up to 12 Mbps (megabits per second), which is
  fast enough for most PC peripherals such as scanners, printers, keyboards,
  mice, joysticks, graphics tablets, low-res digital cameras, modems, digital
  speakers, low speed CD-ROM and CD-writer drives, external Zip disk drives,
  and so on.
• The USB is an addressable bus system, with a 7-bit address code so it can support
  up to 127 different devices or nodes.
• Any device connected to the USB can have a number of other nodes connected
  to it in daisy-chain fashion, so it can also form the hub for a mini-star
  subnetwork.
• Similarly, it can have a device which purely functions as a hub for other node
  devices, with no separate function of its own. This expansion through hubs is
  available because the USB supports a tiered star topology, as shown in Fig.
• On a USB hub device, the single port is used to connect to the host PC either directly or
  via another hub known as the upstream port, while the ports used for connecting other
  devices to the USB are known as the downstream ports.
• Most hubs provide either four or seven downstream ports, or less.
• Another important feature of the USB is that it is designed to allow hot swapping.
• Devices can be plugged into and unplugged from the bus without having to turn the
  power off and on again, re-boot the PC or even, manually start a driver program.
• A new device can simply be connected to the USB, and the PCs operating system
  should recognize it and automatically set up the necessary driver to service it.
• USB cables consist of two twisted pairs of wires, one pair used to carry the
  bidirectional serial data and the other pair 5 V DC power.
• This makes it possible for low-powered peripherals such as a mouse, joystick or
  modem to be powered directly from the USB.
USB pins and signals
• A USB network can only have one host.
                                          USB socket
Data Formats
• USB data transfer is essentially in the form of packets of data, sent back-and- forth
  between the hosts and peripheral devices. However, USB is designed to handle different
  types of data. The two main formats are the asynchronous mode and synchronous
  mode.
• Asynchronous Mode. This mode is used for transferring data that is not time
  critical. This format is used to transmit data from a scanner or digital scanner for
  example to a printer. The packets can be interleaved on the USB with others being
  sent to or from other devices.
• Synchronous Mode. The other main format is synchronous mode, used to transfer
  data that is time critical, such as audio data to digital speakers, or to/from a
  modem. These packets must not be delayed by those from other devices.
Advantages of USB
• Always ON, always connected and always ready to go
• Capable of downloading up to 100 times faster than Traditional devices
• Supports upstream data rates up to 30 Mbps
• Enables access to real-time online games
• Downloads mega files in seconds
• Stand-by switch disconnects the modem from the outside world when not in use
• No telephone line needed
• USB or Ethernet connectivity simplifies installation
FireWire
• FireWire is a high-speed serial bus based on the IEEE 1394 standard and the IEC
  1883 standard.
• The name was given by Apple Computers, where the standard developed.
• Also known as i-Link from Sony and some other consumer electronics companies.
• About the bus structure
           Logically Tree-like -- single root control device branches out to
            logical nodes. This is implemented over a physical “daisy-chaining”
            setup.
          There is a maximum of 1023 buses connected by bridges. Each bus
          supports 63 devices, each having 256 terra-bytes of addressable space
          giving about 16K exabytes of addressable storage (64 bit addresses).
 Physical Layout (Hardware Perspective)
FireWire is plug-and-play
 FireWire       devices                   The main reason to
 are hot    pluggable,                    use FireWire over
 which means they can                     USB is simply the
 be    connected   and                    connection speed.
 disconnected at any
 time, even with the 
 power on.
The Cable
• Two shielded twisted pair wires and two power wires in a shielded round jacket.
• Power cables keep all parts of bus alive even when devices un-energized.
• Also eliminates need for power cable on low power requiring devices.
• Four pin connector cables with no power cables are also available.
The Protocol
• FireWire supports two distinct transfer modes:
• Asynchronous
• Intended for normal, non-real-time data, such as control signals.
• Two-way send/ack protocol for transmissions between explicitly identified
  senders and receivers.
• Sender may transmit up to 64 outstanding (un-acked) packets to maintain
  throughput.
• Isochronous
• Intended for high-bandwidth, real-time transfers, such as video and sound
• Guaranteed-bandwidth for just-in-time delivery, reducing or eliminating the need
  for buffers
• Broadcasts to all parts of the bus without acknowledgment, receivers ignore all
  traffic not on the correct channel