Example Code

Serial Loopback Test in NI VeriStand

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.

    Software

  • LabVIEW
  • Veristand

Code and Documents

Attachment

Overview
This example demonstrates how to perform Serial I/O in NI VeriStand through a loopback test.

Description:
The Serial I/O is performed through LabVIEW code (based on the Basic Serial Write and Read example) compiled into a LabVIEW model (.lvmodel) following the steps in Using Models Created with LabVIEW in NI VeriStand. A tester VI was also written to demonstrate how the NI VeriStand Engine performs the loopback test.
Before using this code, first follow the instructions in How to Do a Serial Loopback Test to set up your serial cable for a loopback test.

-Serial Operations.vi
This VI performs the Serial I/O operations and can be compiled into a LabVIEW model. It has the following states:

  • State 0: Idle
  • State 1: Initializes Serial port COM1
  • State 2: Writes the value of the double "Write" control to the serial port
  • State 3: Reads a double value from the serial port and outputs it to the "Read" indicator
  • State 4: Closes the serial port

-VeriStand Engine.vi
This tester VI demonstrates how the NI VeriStand Engine calls Serial Operations.lvmodel. The different VeriStand Engine elements involved are:

  • "Serial Operations" model
  • "Increment" calculated channel
  • "Modulus" calculated channel
  • Mapping between the "Modulus" and the "Action" channels
  • Primary Control Loop rate = 4 Hz = 250 m



Steps to implement or execute code
To implement this example:

  • Run the VI
  • (Optional) Turn on the Highlight Execution to see the flow of the VI


Requirements
Software
LabVIEW 2012 or compatible
NI VeriStand

Hardware
-

 

fp.JPGbd.JPG

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

Software Engineer
National Instruments

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