How to Perform a Serial Loopback Test

Updated Jul 27, 2023

Environment

Hardware

  • Serial Interface Device

Software

  • Measurement & Automation Explorer (MAX)
  • LabVIEW

Driver

  • NI-Serial
  • NI-VISA

Operating System

  • Windows

This tutorial shows how to set up your NI hardware and software to conduct a serial loopback test.

A loopback test can verify the operation of serial communication by sending and receiving data from the same serial port. It can show problems in the serial port, the cable, or the software generating the messages without having to connect to third-party hardware. Loopback tests can be used for RS-232, RS-422, and RS-485 serial communication.

Before you begin, make sure you have the following: 

Connect Hardware

Refer to the sections below to properly connect your hardware. Identify what serial communication protocol you are using (RS-232 vs. RS-422/485) and the type of serial connector you have.  
 

Note: The pin diagrams provided for this tutorial are for the female connector. For more details on NI Serial Hardware pinouts, refer to the Serial Quick Reference Guide.
Note: If you are using a third-party serial interface, use this article based on your hardware pinout.

RS-232

On an RS-232 port, connect the transmit (TXD) signal to the receive (RXD) signal. Refer to the pins below based on your connector type. The connections are indicated in grey.

Connector Types

Pins

Diagrams

DB-9 (female)

Pin 3 to 2 (TXD to RXD)

 

 

 

 

DB-25 (female)

 

 

 

 

 

 

 

 

Pin 2 to 3 (TXD to RXD)

 

 

 

 

RJ-50

Not recommended*

 

*It is not recommended to use the RJ-50 connector by itself to perform a loopback test due to the small separation between pins. If you use a RJ-50 to DB-9 serial cable (Part Number 182845-XX), a loopback test can be performed using the pins for a DB-9 connector. 

 

RS-422/485 (4-Wire)

On an RS-422/485 port, connect the TXD+ signal to RXD+ signal, and the TXD- signal to the RXD- signal. Refer to the pins below based on your connector type. The positive connections are indicated in red and the negative connections are indicated in blue.

Connector Types

Pins

Diagrams

DB-9 (female)

Pin 4 to 8

(RXD+ to TXD+)

 

Pin 5 to 9

(RXD- to TXD-)

DB-25 (female)

Pin 5 to 20

(TXD+ to RXD+)

 

Pin 7 to 22

(RXD- to TXD-)

 

RJ-50

 

 

Not recommended*

 

 

*It is not recommended to use the RJ-50 connector by itself to perform a loopback test due to the small separation between pins. If you use a RJ-50 to DB-9 serial cable  (Part Number 182845-XX), a loopback test can be performed using the pins for a DB-9 connector. 

 

RS-485 (2-Wire Auto)

For 2-wire configurations, you will need two RS-485 ports to achieve a setup similar to a traditional loopback test. 

  1. On each RS-485 port, place jumper wires between the TXD+ and RXD+ signals, and between TXD- and RXD- signals.
  2. From port 1 to port 2, wire the shorted positive signals together, and the shorted negative signals together. Wire the GND signals together. Refer to the pins below based on your connector type.

The positive connections are indicated in red, the negative connections are indicated in blue, and the GND connections are indicated in green.

DB-9 Connector (female)

Port 1 Pins

 

Port 2 Pins

Pin 1 (GND)Is connected toPin 1 (GND)
Pins 4/8 (RXD+ to TXD+)Is connected toPins 4/8 ((RXD+ to TXD+)
Pins 5/9 (RXD- to TXD-)Is connected toPins 5/9 (RXD- to TXD-)

 

DB-25 Connector (female)

Port 1 Pins

 

Port 2 Pins

Pin 8 (GND)Is connected toPin 8 (GND)
Pins 5/20 (RXD+ to TXD+)Is connected toPins 5/20 ((RXD+ to TXD+)
Pins 7/22 (RXD- to TXD-)Is connected toPins 7/22 (RXD- to TXD-)

 

It is not recommended to use the RJ-50 connector by itself to perform a loopback test due to the small separation between pins. If you use a RJ-50 to DB-9 serial cable  (Part Number 182845-XX), a loopback test can be performed using the pins for a DB-9 connector. 

 

Configure Software

  1. Open Measurement and Automation Explorer (MAX) from the Start menu.
  2. Select the communications port of interest under Devices and Interfaces. If you are unable to see the port, refer to Serial COM Ports Missing in MAX or LabVIEW.
  3. Select the Port Settings tab at the bottom of the window. Make sure the proper settings are selected and select Validate. For more information on serial settings, refer to the Help topic.

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

 

Test Communication

Note: You can test communication in MAX VISA Test Panels or LabVIEW examples. Make sure not to have VISA Test Panels and LabVIEW simultaneously open, or VISA will throw an access resource error (error code -1073807246 hex:0xbfff0072).

 

Measurement and Automation Explorer

  1. In MAX, select the communications port of interest and select Open VISA Test Panel.
  2. Once the Test Panel window has opened, select Input/Output.
  3. In the Basic I/O tab, select Query to send the default *IDN?\n command.
  4. The display window will then outline the write and read operations. The Test Panel should successfully read the sent *IDN?\n command.

 

LabVIEW

For both RS-232 and RS-485 (4-wire), test communication with 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), test communication 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.