Serial Instrument Control Tutorial

Publish Date: Apr 24, 2020 | 120 Ratings | 1.57 out of 5 | Print | 8 Customer Reviews | Submit your review

Overview

This tutorial shows you how to set up National Instruments hardware and software to communicate with a serial instrument in LabVIEW.

Table of Contents

  1. Prerequisites
  2. Install NI Software and Drivers
  3. Install NI Serial Instrument
  4. Configure Hardware in MAX
  5. Test Communication
  6. Install Instrument Driver
  7. Run an Example
  8. Related Links

1. Prerequisites

Consult the pinout or documentation for your serial instrument and make sure you have the correct cables and/or serial interface hardware to connect it to the computer. Refer to the following for more information.

Cables

Serial Interface Hardware

Back to Top

2. Install NI Software and Drivers

Install the latest compatible version of LabVIEW and the NI-VISA driver. If you are using a NI serial interface device, also install the latest compatible version of the NI-Serial driver. Refer to the following for compatibility information. 

Back to Top

3. Install NI Serial Instrument

After installing NI software, set up your hardware to connect the serial instrument to the computer.

  1. If you are using NI serial interface device, refer to the Serial Installation Guide to install the hardware. If your computer already has a serial port, skip to the next step. 
  2. Connect the instrument’s port to the NI serial interface device or the computer’s port via a serial cable and power it on. If you have a two-wire RS-422/485 instrument, refer to Set Up 2-Wire (Half-Duplex) Communication with RS-485 Port.

Back to Top

4. Configure Hardware in MAX

In Measurement and Automation Explorer (MAX), NI-VISA detects the instrument and creates the VISA resource for the serial communications (COM) port that you use to communicate with the instrument.

  1. Open MAX from the Start menu.
  2. Expand Devices and Interfaces. You should see the VISA resource name of the COM port listed as ASRL[board][::INSTR]. If you are using an NI serial interface device, the COM port will appear under the interface.

If you are unable to see the COM port, refer to Serial COM Ports Missing in MAX or LabVIEW.

  1. Select the VISA resource and select the General tab. You can change the VISA Alias for easier identification.
  1. Select the Port Settings tab. Confirm the settings for baud rate, package size, stop bits, and parity bits are compliant with the instrument. Refer to your instrument’s user manual for the required settings. Click Validate to make sure the settings are supported by the hardware.

  1. If you are using RS-485, select the Advanced tab and make sure the Transceiver Mode is set correctly.
  1. Save your settings.

Back to Top

5. Test Communication

After set up and configuration, use VISA Test Panels to verify communication with the instrument and test different instrument commands.

  1. In MAX, select the COM port of interest and select Open VISA Test Panel
  2. In the Test Panel window, select Input/Output.
  3. In the Basic I/O tab, input a supported command and select Query. Refer to your instrument’s user manual for supported commands.
  4. The display window will outline the write and read operations.

Back to Top

6. Install Instrument Driver

After completing your configuration and verifying communication with the instrument, you can easily transition from interactive mode to programming mode by using an instrument driver.

Refer to Choosing the Right Interface to Control Instruments in LabVIEW to determine which instrument driver type is best for your application. Follow the links in the document to install and use the instrument driver.

Back to Top

7. Run an Example

The instrument driver and NI-VISA driver will install examples and the API required to communicate with your instrument. Use these examples as programming references and an easy way to start using your instrument.

Note: Close MAX before you start running a LabVIEW example. Having MAX Test Panels open and running a LabVIEW example simultaneously will result in an access resource error. 

Instrument Driver Examples

If you installed an instrument driver, refer to the following examples:

NI-VISA Driver Examples

If you are using NI-VISA, refer to the following examples:

For both RS-232 and RS-485 (4-wire), communicate with your instrument with the shipping example Simple Serial.vi.

  1. To locate the example, open LabVIEW and navigate to the Help tab >> Find Examples >> Hardware Input and Output >> Serial >> Simple Serial.vi.
  2. Ensure the proper VISA resource name is selected and the serial settings are correct.
  3. Run the VI.
  4. The Respond indicator should display the *IDN?\n command.

If you are using RS-485 (2-wire), communicate with your instrument with the shipping example RS-485 Transceiver Control.vi.

  1. To locate the example, open LabVIEW and navigate to the Help tab >> Find Examples >> Hardware Input and Output >> Serial >> RS-485 Transceiver Control.vi.
  2. Ensure the proper VISA resource name is selected and the serial settings are correct.
  3. Specify the transceiver mode based on the one you want to use.
  4. Run the VI.
  5. The Respond indicator should display the *IDN?\n command.

For more information on the NI-VISA serial functions, refer to LabVIEW Help: Serial VIs and Functions.

Back to Top

8. Related Links

More Serial Resources

Other Instrument Control Tutorials

Back to Top

Customer Reviews
8 Reviews | Submit your review

good example  - Aug 5, 2017

I thought the example was useful and well explained. I'm new to LabView and I find the online help very good. It helps to have some programming experience in C, OOC or C++ for understanding the control/structure concepts. I used this example to query and communicate with one of my serial devices. :>

Indeed Helpful w/ requisite prior knowledge of LabView  - Jun 15, 2016

This short tutorial told me everything I needed to know re. the basics of setting up a serial instrument w/ NI-VISA. To the other commenters complaining of issues steming from lack of prior LabView knowledge, all I can suggest is looking at some more introductory LabView tutorials

All LabVIEW help from NI is useless  - May 26, 2016

I have spent a day just trying to tell the computer to set RS232 pin 3 high for a fixed pulse width every few minutes. Still can't do it. I have access to a LabVIEW developer level graduate and he has no clue.

Worthless  - Nov 23, 2015

So far most the documentation is designed for people who already know the answers. Too much "a priori" knowledge is assumed by the writer.

Almost Useless information  - Mar 16, 2012

This page doesn't describe the critical steps for creating controls on serial VISA.

This is Not a Tutorial  - Jul 11, 2011

This is not a tutorial. I know as little about VISA objects as I did before I read this page.

  - Aug 10, 2010

"A basic serial instrument control system consists of four parts: 1. PC 2. Serial cable 3. Serial instrument" What the ... ? For what is a fairly widely used communications method in industrial and research applications (which LabView targets) there is not much in this documentation. It also does not appear well reviewed as noted above.

insufficient documentation  - Oct 2, 2008

I am a novice user of LabVIEW and MAX. I could not make the VISA Test Panel work. There were no instructions for the many tabs and check boxes on the screen. There was no help function. Everything I tried failed.

View more reviews

Bookmark & Share


Ratings

Rate this document

Answered Your Question?
Yes No

Submit