Example Code

RS-485 Loopback (Port to Port) Test 2 Wire AUTO MODE ONLY

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview
This example will perform a RS-485 two wire loopback in AUTO mode.

 

Description

In order to perform a RS-485 two wire loopback in AUTO mode, you need to have two separate ports to communicate between.  In this example, the two wire AUTO mode is programmatically set on both ports.  The important part is the connection made between the two ports.  Make sure to tie pins 4 and 8 (RXD+ and TXD+) together then wire this connection to pins 5 and 9 (RXD- and TXD-), which should also be tied together.  This is refelected in the next two images.

RS485 2 Wire AUTO connection.jpg

 

Software:

  1. LabVIEW 2012 (or compatible)
  2. NI-VISA


Steps to Implement or Execute Code

  1. Specify VISA setting
  2. Run the application.

 

Additional Information or References

Select the serial resource and the operations (Read, Write, or both) to be performed.  If both are selected, the VI will write the data first, read data and then close the VISA session that is opened to the port.  This VI will wait until the specified number of bytes is received at the port. Only the number of bytes specified will be read.

VI Snippet

RS-485 Loopback (Port to Port) Test 2 Wire Auto Mode 2012 NIVerified.png

  

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

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

Comments
Member
Member
on

I know there is another RS-485 auto mode VI on this community, but I was unable to get it to work without using two separate ports, which that examples does not include.  I have tested this, and it worked for me.

Cheers!

NI Employee
on

Good stuff here, thanks for posting!

Todd S.
LabVIEW Community Manager
National Instruments
Member
Member
on

This is a great, simple summary.  Perfect for troubleshooting of RS485 2-wire connections.

Member
Member
on

Great, tried NI examples with no joy. Your example worked first time! My card is working fine - all I wanted to know. Much appreciated.

Member
Member
on

Sorry if it sounds silly but can anyone please confirm if this example runs on a plain pair of RS-232 COM ports on a commercial PC? Or do we need to have hardware with RS-485 ports? Because i am getting an error when i run this vi using a pair of RS-232 COM ports on my PC.

Member
Member
on

Have you tested the voltage of idle level in 2-wire mode? Is it high or is it 0V?