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
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. 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.
Install NI Serial Instrument
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.
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.
-
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.
Test Communication
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.
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.
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 IVI instrument driver 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.
-
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.
-
Ensure the proper VISA resource name is selected and the serial settings are correct.
-
Specify the transceiver mode based on the one you want to use.
-
Run the VI.
-
The Respond indicator should display the *IDN?\n command.
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.