LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event for streaming TCP/IP frames

Solved!
Go to solution

Hello All,

My application currently has 2 devices attached using TCP/IP to stream data frames at 100ms and 50ms refresh to a PC. I would like to change from polling for data to generating an event when data arrives but I am unsure how to do this. I currently have 2 devices streaming via TCP/IP to a labview routine with 2 loops and they appear to run as expected however I have to poll currently. The situation is not ideal and won't improve once I have 5 or 6 TCP/IP devices all generating frames at different rates.

 

I have previously used VISA for serial data and stumbled across the event function for serial which dramatically improved my codes behaviour once I got rid of my fast polling loop.

 

I have been looking for a solution but so far I can only find the VISA > Advanced > Event handling palette which appears to support most comm types except TCP/IP (hopefully I am wrong). I also vaguely remember a conversation where queues or notifiers could be setup to provide the equivalent of an event for data retrieval.

 

I imagine theres a number of other possible ways to produce something resembling an event.

 

Advice appreciated.

 

Regards

Chris

0 Kudos
Message 1 of 3
(2,496 Views)
Solution
Accepted by topic author CB

I don't know of any way to trigger an event when TCP data arrives, but I also don't know why you'd need to do so. No need to poll the TCP connection, just set a long (or even infinite) timeout and wait for the data to come to you. Keep a copy of the TCP connection refnum somewhere else, so that if you need to kill the TCP Read,  you can do so by closing the TCP connection (which will cause TCP Read to return an error).

 

If you want to generate an event from this, you could feed the string that you read from TCP Read into a user event.

 

If you need to handle an unknown number of connections and you don't want to loop through them all, polling each one, you could instead create a reentrant VI and launch a new instance of it for each TCP connection. That said, I've never had a problem with the polling approach across multiple connections, and I've used that pattern quite a bit.

Message 2 of 3
(2,478 Views)

Hello Nathand,

Your explanation and suggestions have answered my questions. It was worth asking the question because I need to minimise the time from frame acquisition to display of data, calculations and visual stuff on the screen. I need as little lag as possible.

 

I will follow up on your suggestion to set a timeout, kill the TCP read and re-entrant vi.

 

Thanks

Chris

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