Example Code

.NET Get Serial Port Names using LabVIEW

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

Code and Documents

Attachment

Overview
Demonstrates how to use the .NET Serial Port Class to get a list of the serial ports in the system.

 

Description
Here is simple example description:

This example shows how to use the .NET Serial Port Class to get a list of the serial ports in the system.  In order to access the method shown below, a constructor was first created.  Constructors may be found in the .NET palette, which is a sub-palette of the Connections palette.  Once the constructor is placed, a dialog pops up so you can select which object and constructor to use.  First, expand the system object, then select the system IO ports object.  Then, select the serialport() constructor.  Then, you can right click on the constructor and select create and method, and in the list of methods is the [S}GetPortNames method. 

Below, there is a VI using this example to get serial ports, and then showing a dialog to select the COM port.  Additionally, below that is a version of the .NET Basic Serial Write and Read that uses the dialog VI to select the COM port to use.  .NET is useful for using COM ports where VISA is not installed on a system or additional parameters need to be configured for the COM port, that VISA doesn't allow for.  Note that the class used is found in version 2.0 or higher of the VI framework.

 

Requirements

  1. LabVIEW 2015 (or compatible)


Steps to Implement or Execute Code

  1. Unzip the file and open "NET Basic Serial Write and Read With Port Select Dialog"
  2. Configure some related parameters, such as Port name, Baud Rate, Data Bits, Parity and Stop Bits and so on
  3. Write the detected string
  4. Check whether the string is received.

 

Additional Information or References

VI Snippet

NET Basic Serial Write and Read With Port Select Dialog 2015 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.