Example Code

Serial Port Forwarding (Port Sniffer/Logger)

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

  • Instrument Control

    Software

  • LabVIEW

    Driver

  • NI VISA

Code and Documents

Attachment

Overview

This example demonstrates reading data from one serial port and forwarding this data to be written out of another port. This is useful when there are multiple serial ports and you are interested in sniffing or monitoring the serial communication between two points.


Description

Read the data in from one port with VISA Read and write it to another port with VISA Write. Both ports need to be configured. This example also displays a log of the data read in so that it can be viewed on the front panel.

Requirements

Software

LabVIEW 8.6 (or compatible)

NI-VISA


Steps to Implement or Execute Code

  1. Configure the two serial ports (baud rate, data bits, parity, stop bits, and flow control)
  2. Use a property node to extract the number of bytes available at the serial port being read.
  3. Use VISA Read to read in the data. Use the value returned by the property node for the byte count input of VISA Read.
  4. Use VISA Write to write the data to the second port.
  5. Display the read data by formatting the string for the log. 
  6. Close VISA sessions to both ports to free them up for other applications.


Additional Information or References
fp.JPG


VI Snippet

Serial Port Forwarding.png

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

---

Peter Flores
Applications Engineer

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

Comments
mrx 23
Member
Member
on

Could anyone upload the Block diagram of this project? Or a Labview v7.1 compatible vi file?
Thanks.

pflores
NI Employee (retired)
on

They're up!

---

Peter Flores
Applications Engineer
mrx 23
Member
Member
on

Thank you very much!

刘林
Member
Member
on

A good idea。

Huck
Member
Member
on

could someone point me to the Full block diagram of this so that i can attempt to rebuild it for myself in LabView 6.0 ?

Thanks,

aniketjha
Member
Member
on

Sorry, for bumping the old thread but my requirement is similar to this.

 

Is it possible that from 1 port i receive the data and forward this data to 2 port as well as receive the data from 2 ports and forward to the same single port?

 

Thanks 

ThamS
Member
Member
on
Contributors