From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

LabVIEW Loopback Test for Serial Port

Code and Documents

Attachment

Overview

This examples tests any serial COM port installed on the machine.

 

Description

This LabVIEW VI verifies the operation of your serial port hardware. You will need LabVIEW, standard 9-pin serial cable, and some wire or a paperclip. Connect the serial cable to your serial port and then short the transmit and receive pins of the cable with the wire. For an RS-232 cable you must short pin 2 to pin 3. For an RS-485 cable you must short pin 4 to pin 8 and pin 5 to pin 9.

Once everything is connected and your cable is shorted, run the Loopback.VI. This sends out a string and if your hardware is working correctly then you should receive that same message back.

 

Requirements

Hardware: PC/Laptop with Serial COM port (RS-232 or RS-422/485), Serial cable (RS-232 or RS-422/485) Software: LabVIEW Full Development System 2012 or compatible, NI-VISA

 

Steps to Implement or Execute Code

  1. Connect the serial cable to COM port
  2. Short circuit the transmit (Tx) and receive (Rx) pins of the serial cable. For an RS-232 port, wire pin 2 to pin 3. For an RS-485 port, wire pin 4 to pin 8 and pin 5 to pin 9
  3. Check the COM number from NI MAX under Devices and Interfaces.
  4. Enter the Port Number in the control
  5. Enter the String to Write text
  6. Run the VI

 

Additional Information or References

VI Code Screenshot*

 Serial Loopback 2012 NIVerified.png

*The NIVerified version of this code simply flattens the sequence structure for readability. Rewriting this to use the newer VISA Serial API is still recommended.

 

 

**The code for this example has been edited to meet the new Community Example Style Guidelines.**

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Khoa
Member
Member
on

Hi there!

I see you used some vi's in the serial.llb file in C:\Program Files\National Instruments\LabVIEW 2010\vi.lib\Instr\serial.llb. But I wonder how can you find all of them because they do not appear on the functions palette. Do we have some way to get them all displayed in the function palette. I tried copying them to the user library folder but it doesn't work.

Thanks!

crossrulz
Knight of NI Knight of NI
Knight of NI
on

These VIs use the old serial port LabVIEW drivers.  They really should be rewritten using the VISA drivers instead.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5