This tutorial shows you how to set up NI hardware and software to communicate via RS-232, RS-422, or RS-485 with a serial instrument in LabVIEW.
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.
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. If using a 3rd party cable, check to see if there is an additional driver, especially for USB serial adapters. Refer to the following for compatibility information.
After installing NI software, set up your hardware to connect the serial instrument to the computer.
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.
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.
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.
Open MAX from the Start menu.
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.
Select the VISA resource and select the General tab. You can change the VISA Alias for easier identification.
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.
If you are using RS-485, select the Advanced tab and make sure the Transceiver Mode is set correctly.
Save your settings.
After set up and configuration, use VISA Test Panels to verify communication with the instrument and test different instrument commands.
In MAX, select the COM port of interest and select Open VISA Test Panel.
In the Test Panel window, select Input/Output.
In the Basic I/O tab, input a supported command and select Query. Refer to your instrument’s user manual for supported commands.
The display window will outline the write and read operations.
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.
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.
If you installed an instrument driver, refer to the following 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.
To locate the example, open LabVIEW and navigate to the Help tab >> Find Examples >> Hardware Input and Output >> Serial >> Simple Serial.vi.
Ensure the proper VISA resource name is selected and the serial settings are correct.
Run the VI.
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.
To locate the example, open LabVIEW and navigate to the Help tab >> Find Examples >> Hardware Input and Output >> Serial >> RS-485 Transceiver Control.vi.
Specify the transceiver mode based on the one you want to use.
Note: SCPI commands i.e. '*IDN?\n' will only work with devices that support this protocol; Many third party devices will not respond to these commands.For more information on the NI-VISA serial functions, refer to LabVIEW Help: Serial VIs and Functions.
Serial Quick Reference Guide
How to Perform a Serial Loopback Test
Serial Baud Rates Supported by NI-VISA
NI-VISA Programmer Reference Manual
Ethernet Instrument Control Tutorial
GPIB Instrument Control Tutorial
USB Instrument Control Tutorial
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.