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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Periodic write to serial port in background

Solved!
Go to solution

Hello,

 

Relatively new to LabVIEW, but my first project I need to write a hex value to a serial port every 500mS in the background, while still being able to read and write to the same port when needed for commands.  So I have the writing the hex value to the port down, and probably will use a timed while loop to write to it, but now my question is how to do this in the background and still be able to read and write as needed.  The hex value is sort of a keep-alive to the device I am talking to. And I will neet to asynchronously read and write to the device. 

0 Kudos
Message 1 of 4
(831 Views)

You would have to approach this as a queued state machine structure where every 500ms you send this keep-alive code whereas between these 500ms cycles, you're free to do any read/write, this way only one resource is communicating on the Serial port and there is no clash.

 

Since you're new to LabVIEW, you need to take up a bunch of training resources before you reach the state machine structure. You can find the training resource at the top of the LabVIEW board

santo_13_0-1647705520288.png

 

Timed loop is not recommended for regular Windows OS and is intended only for RTOS (of course it will run on Windows for debug but does not guarantee the timing)

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 4
(792 Views)
Solution
Accepted by topic author Frozen001

Additionally, I'll point you to a presentation I did on serial port communications: VIWeek 2020/Proper way to communicate over serial

 

Towards the end, you'll see how I handle this situation.  The short of it is I use a VI that runs in parallel with the rest of my code that does nothing but handle the serial communications.  I communicate with that VI with a Queue.  So if there is not message ready in the queue, the Dequeue function will time out and I can then send the periodic command through the port.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 4
(767 Views)

Thank you this looks to be what I need to do... now to just get to the point I understand it fully to be useful.

0 Kudos
Message 4 of 4
(742 Views)