Example Code

Serial Write and Read One Byte

Code and Documents

Attachment

Overview

Performs Serial Write/Read one byte at a time for use cases where certain instruments are incapable of parsing entire strings.

Description

The calling VI, Serial Write and Read One at a Time, is built off of the LabVIEW Basic Serial Read Write Example, with the VISA Write VI replaced with the One at a Time VI. 

 

The One at a Time VI breaks Strings down into single ASCII characters before writing/reading.

Hardware and Software Requirements

LabVIEW NXG 1.0 or compatible

Serial instrument and cable

Steps to Implement or Execute Code

In the Serial Write and Read One at a Time VI: 

1. Select the serial resource and configuration parameters.
2. Select the operations to be performed.
3. Connect the serial port to your device. If no device is available, perform a loopback test by doing one of the following: Short pins 2 and 3 on a RS-232 cable or short pin 4 to pin 8 and pin 5 to pin 9 on a RS-485/422 cable.
4. Run the VI to see the data read. (The "read string" will match the "string to write" if a loopback test was performed.)

Additional Information or References

Original LabVIEW compatible example: http://www.ni.com/example/31174/en/

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

Comments
TommyDunkz
Member
Member
on

Hi fiendfyre,

 

Thanks for taking the time to put this example together for LabVIEW NXG! This code will be an invaluable resource to LabVIEW NXG users looking to interface with Serial instruments and communicate one byte at a time.

 

I have a few suggestions for your example code, in order to ensure visual and functional consistency between programs which are released to the community. Most of these are minor cosmetic changes, and should be pretty quick to implement:

 

  • The panel for One at a Time.gvi could use some logical grouping of its controls and indicators. I recommend using the rectangle decoration for this.
  • The top-level .gvi should be saved with the top of the overview rectangle in line horizontally with the top of the 'Unplaced Items' node.
  • I'm unable to get the 'stop bits' control in the top-level .gvi to represent its data properly--it defaults to values of 10, 15, or 20. Is there any way to resolve this?
  • The panel should fit within 1000x600 pixels at 100%. This allows the entire panel to be visible at the minimum supported resolution (1028 x 768), with the IDE panes collapsed.
  • The diagram should fit within 1000x600 resolution at 100%. If this is not possible, it is permissible to scroll the diagram in one direction. For both .gvis in this example, it should be possible to compress the diagrams vertically into one screen.
  • Ensure any Properties node (Cluster Properties, Waveform Properties, etc.) is set to 'Autosize List View' so that all element names are fully visible.
  • There are overlapping wires at VISA Close in the top-level .gvi.
  • The text of the VISA Property Node in the top-level .gvi is cut off.
  • Arrange diagrams so that the primary wire travels in a straight line between nodes. The primary wire is usually a reference or error wire. In this example, it should be the VISA session wire for both .gvis.
  • The wires around VISA Configure Serial Port in the top-level .gvi could use some touching up. Try to keep at least 20 pixels of white space between wires if possible.
  • Arrange diagrams so that the primary wire travels in a straight line between nodes. The primary wire is usually a reference or error wire.
  • Align and distribute nodes, terminals, and constants. Use the Align and Distribute pull-down menus on the document toolbar to arrange objects symmetrically on the diagram. When objects are aligned and distributed evenly, you can use straight wires to wire the objects together. Using straight wires makes the diagram easier to read.
  • Make sure control and indicator terminals on the connector pane are not inside structures on the diagram. LabVIEW can optimize subVI execution time when all controls and indicators on the connector pane reside on the top-level diagram of the VI.

 

Let me know once you get a chance to implement these changes, and I'll go ahead and release this example to the Community. Thanks again for your effort in putting this code together!

Tom D.
Staff Software Engineer
NI
Contributors