LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading XML data from socket (have IP address and port #) using labview

Hi, 

I am having problems with reading XML data from socket using Labview. 

I am able to read the data if I have a stored XML file on my computer. But I want to read it straight through the network. 

I am not sure where to start it from. 

I know that I have to use TCP read function to do that. 

Any ideas how I can do that. 



Thanks

0 Kudos
Message 1 of 17
(5,923 Views)

Look at the TCP Client examples in the LabVIEW examples. It gives an example of how to connect to an IP/port and read/write data to it. The help for the TCP Read also has a lot of information.

 

You will need to think about how the data is transmitted - how do you know when you have reached the end of the XML data and is the data sent periodically or do you have to request it from the 'server'?

 

Once you've had a look at the examples and tried to create your own VI then you can post it here so we can see where the problem might be.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 17
(5,897 Views)

Hi Sam,

 

I am able to read it from the socket now. But the data output type is string. 

I am not sure how to convert this xml string and extract the data from it. 
Thanks for help. 

 

 

0 Kudos
Message 3 of 17
(5,878 Views)

For converting the XML to 'data' you will need to do one of the following:

 

1) Use the .NET XML library

2) Use a LabVIEW XML toolkit

3) Do some simple string parsing to get the data you want

 

These will allow you extract the data from the XML string and convert it into data you can use


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 17
(5,869 Views)

Hi Manny,

 

If you have an XML string, the thing to do is create a new DOM object using the XML parser functions and load the string into the object.

 

The XML parser functions are under Programming -> File I/O -> XML -> XML Parser. (I am using LabVIEW 2009 SP1. It may be in other places in other version.)

 

Start by calling New.vi to create the DOM object. Then use an invoke node to Load String. (Load XML File.vi has an example of these steps but uses the Load File method instead of the Load String method.)

 

The rest is down to using the XML VIs in the parser palette or the methods and properties in the object (Through Invoke and property nodes) to do whatever you need.

0 Kudos
Message 5 of 17
(5,866 Views)

Sorry for late reply. I was away from this project for couple of months.

I tried using match pattern method to get the values. But I am not sure  if that is the best way. I am suspecting it might be slower method and I might miss some points. I have attached the screenshot of the method I am using. 

 

I tried to use the parser method, but it kept on giving me the error. I am not sure if the schema matters in the parser method (if thats the cause of error).

 

So, I was wondering if match pattern is an okay method and I won't loose any points?


Thanks
Manraj Thind

 

 

0 Kudos
Message 6 of 17
(5,680 Views)

This looks fine as long as you don't have multiple values of a particular type in the string. Your searches are only going to pick up the first sample of a given type. 

 

This seems like a strange way to send data. With XML, I would expect a complete file, not a sample data stream.

 

Does the source support other methods for transmitting data? 

0 Kudos
Message 7 of 17
(5,671 Views)

I would like you to consider the following statement.

 

"This looks fine as long as you don't have multiple values of a particular type in the string. Your searches are only going to pick up the first sample of a given type. 

 

This seems like a strange way to send data. With XML, I would expect a complete file, not a sample data stream.

 

Does the source support other methods for transmitting data? "

 

You can read an XML file in LabVIEW even if it has different data types:
https://decibel.ni.com/content/docs/DOC-36321

 

However, if your application does not follow the LabVIEW schema for how the data is tagged, then you'll need to parse it out:

http://zone.ni.com/reference/en-XX/help/371361E-01/lvconcepts/parsing_xml_files_in_lv/

 

Which will give a better understanding on how to parse XML files.

 

Also check the next references:

 

http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/converting_data_to_and_from_xml/#LabVI...

 

 

Kind Regards,

Siggi D.

Application Engineer

 

 

 

 

"everything is achieveable through technology'
0 Kudos
Message 8 of 17
(5,645 Views)

Hi Siggi,

 

The type I was referring to was not data type. It is different samples in the XML that the OP is trying to parse. If you look at his code you can see that he is using search strings to look for four different kinds of samples. Specifically pressure, tip, sleeve and temperature. I used the word type here and I can see that would be confusing.

 

I did not mean data type.

 

If the OP's code gets a string where he has multiple samples of pressure, his code will only read the first sample and throw away any subsequent pressure samples before reading the next packet. The point I was trying to make was that if he knows each packet will only ever have one sample of the four kinds (type?) then his code should work.

 

 

0 Kudos
Message 9 of 17
(5,637 Views)

Oh exactly. I couldn't agree more with you.

Basically, the workaorund would be figuring a simple way to acquire, for example on a Queue, all the input data for the different, hmm lets call it magnitudes (pressure, temperature..etc) haha , so the data dont get lost, and the output is not only just the first input from reading the sample.

 

So for the OP, the documentation i left to you, i hope it helps.

I will be reviewing this post frequently. 

If you have further questions related to this issue please let us know.

 

Regards,

 

Siggi 

AE

"everything is achieveable through technology'
0 Kudos
Message 10 of 17
(5,632 Views)