12-21-2012 10:11 AM
I am using labview 11 and I have a computer send data over tcp ip. The data string is like this P 22 33 44 P 22 44 66 P 22 33 11 P and so on The numbers in between P are x y and z co-ord I need labview to receive this and seperate each x y and z as seperate outputs
Solved! Go to Solution.
12-21-2012 10:26 AM
You will need to write a parser for the data. There are several options available to you. If you data will always be well behaved you can use a regular expression or scan from string to grab the P x y z.
I would probably write your application using two loops. One loop simply reads data from the TCP connection. It reads it in chunks and simply passes those to a processing task. That task can use the above suggestion to pull the data from the buffer. You could also do some level of data validation in that task just to verify that you haven't received garbage.
12-21-2012 10:31 AM
First, define what you mean be "real time". If you are running under Windoz you can't have "real time" as it is usually technically defined, i.e. deterministic (where events occur at repeatable and predictable times). Also, tcp/ip is generally not deterministic (you never know, precisely, when the next packet of data will arrive) particularly if the communications is over a "shared" network with multiple computers on the the network.
There are several examples of tcp/ip communications under LabVIEW in the examples ("Help:Find Examples" tcp). If the messages are well defined, i.e. P 22 33 44 P 11 22 44, then you just parse based on the delimiters, in your example apparently a space. A number of ideas come to mind, first being the "spreadsheet to array" function, using a space as the delimiter. This would give you an array with each P, 22, 33, 44, in a seperate column. There are a nearly inifinite way of parsing the string out to its x,y,z components
12-21-2012 11:14 AM
Thank you for the fast reply 🙂 I am a novice in LabVIEW. So this is what I exactly want to do. I have a sytem recording the x y and z co ordinates of a marker. This computer sends the data over to another computer over the network with labView in it. The tcp/ip port is 2000. The data receieved will be in this format P x y z P x y z P and so on. The P is there to signify the end of one frame. so the first x y z are the xyz co ord of the marker at time 0 and the second xyz after the P is the marker position at time 1 and so on. I made labview connect to this computer using TCP listen and made TCP read function to display the received string. The issue is that TCP read needs to read and display the data continuosly. Another issue is to split this data into seperate x y and z outputs and this output should keep updating itself as time passes. Kindly help me.
12-21-2012 11:21 AM - edited 12-21-2012 11:22 AM
A sample vi would highly help 🙂 if it isnt asking too much
12-21-2012 11:44 AM
@kishorgenius wrote:
A sample vi would highly help 🙂 if it isnt asking too much
If you're good enough at LabVIEW to make a TCP/IP connection, why don't you browse the "String" and "Array" palettes and see what you can come up with? 🙂
12-21-2012 11:53 AM
Establishing the connection part was easy. I am trying as much as I can to solve this. This forum has been highly useful in helping me accomplish whatever I could so far. So kindly help.
12-21-2012 12:06 PM
Thank you for the fast reply I am a novice in LabVIEW. So this is what I exactly want to do. I have a sytem recording the x y and z co ordinates of a marker. This computer sends the data over to another computer over the network with labView in it. The tcp/ip port is 2000. The data receieved will be in this format P x y z P x y z P and so on. The P is there to signify the end of one frame. so the first x y z are the xyz co ord of the marker at time 0 and the second xyz after the P is the marker position at time 1 and so on. I made labview connect to this computer using TCP listen and made TCP read function to display the received string. The issue is that TCP read needs to read and display the data continuosly. Another issue is to split this data into seperate x y and z outputs and this output should keep updating itself as time passes. Kindly help me.
12-21-2012 12:46 PM
What many LabVIEW newcomers don't realize is that you can click on the [?] on the VI toolbar to bring up the context help for whatever they mouse over - just about anywhere in LabVIEW. Sometimes this still isn't enough information. You'll find that, more often than not, there is more extensive help to be had by clicking on the "Click here for more help" link in the context help window.
If this STILL isn't enough help, it might be worth considering taking some of tutorials offered by NI.
If you have basic understanding of LabVIEW programming, we've given you a great headstart with the info already in the thread. If not, it might be time to hit the tutorials... Please, just give it a go and see what you can come up with...
12-21-2012 02:23 PM
Here are two examples of some basic parsing:
The top portion is using a regular expression which is much more forgving than the bottom section which uses the Scan From String. The Scan From String will only work if there is a single space between the items. The regular expression will work will allow multiple spaces.