Ethernet Instrument Control Tutorial

Updated Oct 20, 2020

Environment

Hardware

  • Ethernet Device

Software

  • LabVIEW

Driver

  • NI-VISA

This tutorial shows you how to set up NI hardware and software to communicate with an Ethernet/LAN instrument in LabVIEW. Consult the documentation for your Ethernet instrument and make sure you have the correct cable to connect the instrument to the network.

Install NI Software and Drivers

Install the latest compatible version of LabVIEW and the NI-VISA driver. Refer to the following for compatibility information.


Connect Instrument to Network

Directly connect the instrument’s Ethernet port to the Ethernet port on the target machine via an Ethernet cable. Refer to your instrument’s user manual for more information.
 

Test Network Communication

Ping your device to make sure you can communicate with your instrument over the network.

  1. Open the Command Prompt from the Start menu.

  2. Type in the following command:

Ping xxx.xxx.xxx.xxx:yyyy
Where xxx.xxx.xxx.xxx is the IP address of the instrument and yyyy is the port. Depending on the instrument, you may not need to specify the port. Press Enter.

  1. If you get a reply response back, you are able to communicate with the instrument and are ready to configure it in Measurement & Automation Explorer (MAX).
     


 

Configure Ethernet Instrument in MAX 

Use Measurement and Automation Explorer (MAX) to create and configure the VISA TCP/IP Resource used to communicate with your instrument.
 

  1. Open MAX from the Start menu.

  2. Right-click on Devices and Interfaces and select Create New

  3. In the Create New… window, select VISA TCP/IP Resource. Click Next.  
     

 
  1. Select the type of TCP/IP resource to add.
If your instrument conforms to the VXI-11 LAN or LXI instrument specifications, select one of the following
  • Auto-detect of LAN Instrument – This option provides a list of LAN instruments found on the local subnet.
  • Manual Entry of LAN instrument - Add the IP address and LAN device name for your instrument manually.
Otherwise, select Manual Entry of Raw Socket to add your Ethernet instrument as a Raw Socket. With this option, you will have to enter an IP address and port number for your instrument. The instrument's port number should be indicated in its Ethernet Interface Specification found in manufacturer documentation.

 

 

  1. Validate and finish the configuration. There should now be a new VISA TCP/IP Resource under Devices and Interfaces >> Network Devices in MAX in one of the following formats:
  • LAN Instrument - TCPIP[board]::host address[::LAN device name][::INSTR]
  • Raw Socket Instrument - TCPIP[board]::host address::port::SOCKET

Test Communication in VISA Test Panels

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 Tools tab >> NI-VISA >> VISA Interactive Control.

  2. Select the VISA TCP/IP resource of your instrument.

  3. In the Test Panel windows, select the Input/Output tab.

  4. In the Basic I/O tab, input a supported command and select Query. Refer to manufacturer documentation for a valid list of commands to use with your instrument. 

  5. 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 the following examples:

NI-VISA Driver Example

If you are using NI-VISA, refer to the following LabVIEW snippet. This example opens a session to the Ethernet instrument, performs a write of *IDN?\n, reads the specified number of bytes back from the instrument, closes the session, and handles any errors.

  1. Drag the snippet directly onto an empty LabVIEW block diagram.  

  2. On the front panel, configure the VISA resource name to be the VISA TCP/IP resource of your instrument previously configured in this tutorial.

  3. Run the VI.

For more information on VISA functions, refer to LabVIEW Help: VISA VIs and Functions.