LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to sync TCP/IP command with data

Hello. I am trying to catch a TCP/PI data and write it to the file. I am using the TCP Communicator example as the base. My goal is to send a command and write to the file the response from the host. Few challenges. I can send multiple commands, but I only want to write to file after specific one and only once. It is the reason I have some logic in the send loop to enable write block. My problem is, by the time data comes, my enable changes value, so I only write the data that was on the bus from previous command. Or, I keep witing to file ove r and over.

 

What is the best way to sync send a command and wait for the result for this command? Should I just use case structure since I do not need to listen host all the time, only after I sent  commands.

Labview 8.2

Win7

 

Thank you

 

0 Kudos
Message 1 of 2
(2,915 Views)

Do you have control over the data on both ends of the connection? If so, create a simple messaging protocol that will help you keep things in sync and give you the ability to recognize the commands. The simplest protocol would be to define your data packets to contain a message header and data. The message header would contain a message identifier identifier and the message data length. The header should be fixed length. This allows you to easily read the header and the data. The data will be whatever you need for each message type. The header message length will let you know how much data to read. Using this simple protocol the message reading would be very simple. Since each message will contain an identifier you can easily chose how to process the message and what actions you take. If you need to match responses with specific commands you could put a command sequence number in the message header. This would allow you to match the response with the specific command. You would need to include the command sequence number in the response.

 

If you don't have control over the other side of the connection you will need to get the message format the device uses. That will dictate how to process the messages.

 

Also, if your system is always a command/response system you do not have to have the read and write in separate tasks. You can send the command and wait for the response immediately afterward. You would not send the next command until you get a reposes. If you know you won't get a response for a specific command you would skip the read.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 2
(2,908 Views)