LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

streaming in TCP/IP data from 5 devices

Hello All,

I am working on a project which requires Labview to stream in TCP/IP 50 character frames from 5 devices at approx 65ms each. I connected the first test equipment device and had this running well using Telnet from the NI Internet Toolkit. Once I added the second Telnet test device the problems started. I can send TCP messages from PC to the test devices but the test devices can also be set to stream TCP frames back to the PC. The streaming loop locks up after about 50 seconds, I think this is because one test device streams TCP frames quicker than the other and a buffer somewhere (PC?) fills up. Also frames from both test devices arrive at the rate of the slower device

 

I need all frames from both (eventually 5) test devices to be reliably captured and made ready for processing regardless of their transmission rate.

 

What I would like to achieve is some extendable parallel code allowing me to capture all in coming frames from the 2 (eventually 5) devices. I noticed other posts discussing the Internet Toolkit and its use of semaphores. Are the semaphores causing the hang issue I am seeing? I am unsure if theres some way implement a TCP equivalent, but this feels like a lot of effort. OR do I need a different type of physical and aoftware architecture altogether?

 

I have tried to implement a simple TCP/IP reader but no success so far.

 

Advice Appreciated.

 

Regards

Chris

0 Kudos
Message 1 of 5
(4,337 Views)

Hi Chris - it's hard to understand your post. Can you include some code, showing what you've tried and explaining exactly what error occurs?

 

There are several ways to handle simultanenous TCP connections. Take a look at the "Multiple Connections - Server" example that ships with LabVIEW as one starting point. I posted a screenshot of a similar approach here. Or, you can dynamically launch a copy of a VI to handle each new incoming connection; I think you might find an example of that if you search this forum. You'll need to figure out how you want to handle returning data to each client - do you send the same data to each one, or do you send an individual response depending on what data the server receives?

0 Kudos
Message 2 of 5
(4,323 Views)

Hello Nathand,

Thanks for the quick reply, your linked tcpip solution looks impressive in terms of being able to automatically connect, manage data from multiple devices and automatically disconnect. This appears to be what I'm looking for. The project is in the early stages and I was advised the device relied on Telnet so looked for a library to support this. Telnet allowed me achieve comms quickly but now I am starting to develop code I have found some issues and started to question if Telnet is actually needed. I suspect I may be able to drop the Telnet vis in favour of the equivalent TCP/IP functions.

 

below is a simple application ive setup using the Internet toolkit - telnet vis. When I run one device it is fine but after adding the second device the code locks up within 50 seconds. The code below opens the Telnet connections, instructs it  to stream data, monitors the incoming stream and closes the connection after stop is pressed. Most of the time the device will be streaming however theres also a range of other commands resulting in a returned string (not covered in the code below)

telnet.png

 

now Ive seen your solution I am keen to implement something similar if possible. The first question is how do I get the TCP/IP functions working. A number of times in the past Ive failed to get the Simple TCP/IP project working with the Client and Server vis on different machines (they only appear to work for me when executing on the same machine).

 

The next question is... can I use TCPIP with the devices I am using. As I am currently receiving data via Telnet vis could I also receive data using the TCP/IP functions?

 

To sum up, I think your TCP/IP multple automated connections looks ideal. If I can learn how to establish TCP comms between a PC and remote device this would be a great help, hopefully leading onto something like your automated TCP/IP solution.

 

Regards

Chris

 

 

 

 

 

0 Kudos
Message 3 of 5
(4,283 Views)

I think I partially misunderstood your question. I thought your code should act as the server, but it appears that your code is actually the client - it establishes the connections to the remote devices, rather than waiting for new incoming connections. In that case, my code isn't helpful to you, although you could still use a similar technique of maintaining an array of connections and looping through them to check for new data. Instead of accepting new connections, you would instead need some logic to detect when the connection to a particular device failed, and restart it (ideally in a separate loop so as not to interfere with reading the other connections).

 

Telnet is a thin wrapper around the TCP functions (you can open those Telnet VIs and examine them). Replacing them with the TCP functions should not be difficult, they match up almost directly. The Telnet functions are not reentrant, meaning that if you call one function (such as Read) in two loop simultaneously, only one executes at a time. That's probably part of the problem with your code; the TCP functions are reentrant.

 

Can you be more specific about "locks up"? What exactly happens? When it does that, what do you do to kill it? Have you tried turning on execution highlighting when it's "locked up" to see where it's stalled?

0 Kudos
Message 4 of 5
(4,260 Views)

Hello Nathand,

Yes I need the code to act as a client and just receive streaming data from a number of external devices. The automated open, write, read, close and then poll for reconnect seems ideal.

 

If I am able to get the TCP functions to work I intend to drop Telnet and use the TCP functions instead.

 

During a lockup I enabled execution highlighting and can see the wjhile loop TelnetRead has hung on both loops. I then stop the vi and restart then everything is fine for another 50 seconds until the next lockup. The 2nd loop is running 3 times quicker than the first loop and I think a buffer is filling up and eventually causes the lockup once full (?)

 

Your idea the notifiers are causing the hold seems right. In which case I cannot use the Telnet vis. As you suggest I will try replacing the Telnet vis with TCP equivalent and then look for multiple server to client code. Have you come across code I could use as a start point?

 

Regards

Chris

0 Kudos
Message 5 of 5
(4,243 Views)