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

Read status of RS232 serial lines

Code and Documents

Attachment

Overview

The RS232 signal detect.vi reads and returns the status of the RS232 serial lines.

Description

The vi calls an instr property node with Modem Line Settings. The status of the lines are displayed in a color coded cluster of booleans. Yellow represents an incoming signal, green represents an outgoing signal. Light color represents ON state, dark color OFF. You can force the DTR and RTS lines to ON or OFF. The Receive Data (RXD) and Transmit Data (TXD) lines status are not detected by the vi but transfered from the calling vi. The calling vi will read the port and call the sub vi with RXD = TRUE if data were received. The calling vi will call the sub vi with TXD = TRUE if the calling vi is about to send data.

A calling vi is attached to illustrate how the sub vi can be intergated with code.


Steps to Implement or Execute Code

  1. Connect some RS232 equipment to your COM port
  2. Open RS232 signal detector.lvlib
  3. Open RS232 caling.vi
  4. Set COM parameters before running the vi
  5. Run the vi
  6. Observe the status of the signal lines in Signal lines
  7. Enter a command in string to write and hit Write
  8. Observe that TXD flashes green
  9. Any answere from the instrument is displayed in read string
  10. Observe that RXD flashes yellow
  11. Force DTR high or low by swithcing the drop down in Set DTR/RTS
  12. Observe that DTR state swithes

Requirements

Software: Labview 8.5

Hardware: PC

Additional Images or Views

RS232 signal detector FP.JPG

RS232 signal detector.vi front panel

RS232 signal detector BD.JPG

RS232 signal detector.vi block diagram

Call parameters:

   COM Port - COM port number

   Set DTR/RTS - Cluster of wanted DTR and RTS settings

      0: Set to off

      1: Set to on

      2: Ignore. Don't change state

   RXD/TXD - Current status of receive and transmit lines

   Error In - Calling vi's COM port error status

Return parameters:

   COM Port 2 - Same as COM Port

   Signal lines - Cluster of signal lines status

   Error Out - COM Port error status

RS232 calling vi FP.JPG

RS232 Calling vi.vi front panel

RS232 calling vi BD.JPG

RS232 Calling vi.vi block diagram


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

Contributors