Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET Serial Port Write and Read Using LabVIEW

Overview
This example shows how to use the .NET Serial Port Class with a remake of a classic VI, the Serial Basic Write and Read. 


Description
This is useful if you don't have the VISA driver installed on the machine.  Note that this class is found in version 2.0 or higher of the .NET Framework.

 
Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

 

1.Select a port of serial device, configure serial setting.

2.Run the VI, and write to the string

 

Additional Information or References
VI Block Diagram

1.png 

 

 

 

 

 

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

 

Comments
Member JPowell
Member

Thanks much for this.  This gave me what I needed to talk to an old spectrometer that needed some wierd delay settings for the serial port that normal VISA couldn't do.

Member Jeff'sGPIB
Member

Hi,  I see this is an old thread.  I have a new comment.  First, thanks!  This is a good example of .NET.  Most appreciate.  What I am trying to do is to discover what com ports are available.  i.e. get a list of com's. programmically.  I see in this example, the com name is a string and it is given.  How would I discover what com's are available?

Thanks JeffsGPIB.

Member JPowell
Member

Hi Jeff,

First, go to the connectivity palette and there to the .NET palette.  Select Constructor.  Once the constructor is placed, a dialog will pop up so you can select what creator to use.  In the Objects section of the dialog box, select System, then System.io.ports then click on Serial Port.  In the Constructor section, select the SerialPort() object and press OK.  Now, right click on the constructor and select create, then the option that says Method for System... .  Then, select GetPortNames().  An invoke method node will be created.  In my test VI, I just connected the output of the invoke node to an indicator.  You will be able to delete the constructor at that point.  See the attached image for an example and the results on the front panel.  You can also get the example at https://decibel.ni.com/content/docs/DOC-43774 along with a version of the example from this page, in which I used the example code.  I created that page, since I couldn't attach the example here.

John

GetSerialPorts.jpg