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

Producer Consumer Loop Example: COM Port Hyperterminal Application

Code and Documents

Attachment

Download All

Introduction:

In this example, it demonstrates how to use a produce consumer architecture to be able to send and receive commands from a COM Port. The producer loop handles all the user generated events while the consumer loop manages the communication to the COM Port.

Components to the Example:

1.) Initializes the Queue that passes the states.

2.) Produce Loop Cases of the Event Structure:

Timeout: Check to see if the is any errors.

Initialize: Sends the Initialize command

Write: Sends the write command

Close: Sends the Close Command

3.) Consumer Loop Cases of the Case Structure

Wait: Waits for a command from the Consumer loop

Initialize: Initialize the COM Port and send it to the Read Port State

Read Port: Checks the bytes at port and reads the data back from port

Write Port: Writes a command to the port and send it to the Read Port State

Close: Closes the Session and stops the while loop.

4.) Closes the Queue and displays errors.


Jim St
National Instruments
RF Product Support Engineer

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

Comments
jcoreyw1969
Member
Member
on

Would you be willing to compile this app using LabVIEW 8.6?

jafanovic
Member
Member
on

What about add save to file functionality? Is it easy to implement it?  

AntDeane
Member
Member
on

How do you use the write capability in the code? When I type in code, and press enter (or the write command button) nothing happens on my external unit. However, when I use the same settings and same code in Termite (a serial port terminal) I get the desired outcome.

Any ideas on why this is the case? Am I doing something incorrectly?

Thanks

Contributors