03-18-2022 08:06 PM
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.
Solved! Go to Solution.
03-19-2022 10:59 AM
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
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)
03-20-2022 07:56 PM
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.
03-22-2022 05:39 PM
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.