LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with TCP/IP reads with multiple read loops.

I am developing an application that uses TCP/IP to communicate with a custom device. In one loop (test result loop) I am constantly using a TCP read to monitor incoming information from my device. This aspect of my program works as designed. I encountered problems when I tried to set up a handshake with the device to monitor whether the device was still connected. To do this I set up another loop (handshake loop) in which I am sending a command that asks for the current version of my device. If it returns the correct string, I know I am still connected. 

 

However there seems to be timing issues where I will sometimes read the handshake information in the loop designed to wait for test results, and vice versa. The incoming test results are received at completely random intervals so I need to make sure my test result reads are uninterrupted.

 

What's the best way to code this?

0 Kudos
Message 1 of 3
(2,757 Views)

It sounds like you have one open connection to your device, and it sends unsolicited data to you. If this is the case then you cannot have two independent loops that try to talk to it separately, there is always the risk that data will arrive and read by the wrong loop. This means a handshake response must be read by the same loop that reads the test results.

 

Your TCP messages need to be packaged in a way that makes them identifiable. When built this way you can be sure of what you have received and it therefore doesn't matter what responses come first, or when. And you will only need one loop for all your TCP/IP communications.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 3
(2,719 Views)

This document is the first I found on NI.com describing a TCP/IP packet protocol for indentifying messages between devices:

http://www.ni.com/white-paper/3524/en/

 

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 3 of 3
(2,718 Views)