LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

getting data from a web site

Solved!
Go to solution

I have a device that has a built in web server that I need to write a LV program for

 

I need to read the date the web server is producing and compare it to actcual measured data.

 

Now the measureing and comparing is easy but I don't know how to make LV read a webpage.

 

Any thoughts or examples?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 1 of 11
(5,002 Views)
Solution
Accepted by topic author RTSLVU

Hi,

 

Check out http://zone.ni.com/devzone/cda/epd/p/id/2743. It has code to get the HTML code from a URL. Once you have this, all you need to do is parse this code (String) for the data of interest.

 

Amit Jayakaran

 

Message 2 of 11
(4,991 Views)
Thanks Amit, that is exactly what I was looking for.
========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 11
(4,961 Views)

DOH! I tried the vi from http://zone.ni.com/devzone/cda/epd/p/id/2743 but it does not work!

 

It looks like it works at first glance loading the www.ni.com webpage but on closer examination (like if you change the URL) it seems to never get the webpage. Is the www.ni.com page is somehow stored in the vi?

 

I do not know enough about workign with ActiveX to figure out why it does not work.

 

Can somsone take a look at it and see if it works for you or why it would not work?

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 11
(4,952 Views)

 

The example code uses Events. The event on which the new URL loads is "URL - Value Change". Once you run the code, replace www.ni.com with say www.google.com and click outside that string control. This will trigger the Event and will load your page.

 

 

To use this code in your final application you will not need the events part. You probably will just need whatever is in the "URL - Value Change".

 

Amit

0 Kudos
Message 5 of 11
(4,945 Views)

I got it to work, but It seem like the first time I launch it I sometimes I the first time I run it I get this error.

 

Error 97 occurred at UnknownSystem Error

Possible reason(s)

Labview: Null Refnum was passed as input.

 

Also it does not always ouput the text the first time and you have to run it twice. 

 

Worse yet it seems to cache the text so sometimes when you load a new page the text is still the text left over from the previous page yet you can see the new page has loaded in the SHDocVw.IWebBrowser2 indicator.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 11
(4,909 Views)
Here's my code...
========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 11
(4,908 Views)

 

You are essentially using Internet Explorer. So you will need to change IE's setting for caching. I think you need to set it to "check for new version of page everytime I visit".

 

Regarding the errors and incorrect text, This is what I think is happening. Your code is running faster than the browser/Internet. You open a URL. The browser sends a request to the internet. Patiently waits for a response. Meanwhile, you already read its document object, which is still on the old URL. The next time you run it, its fine!!! Remember, we see in 100s of mS, computers see in uS!!! Simply place a flat sequence over the Navigate Invoke node and place a delay of 2000ms in that structure. This gives the browser time to load the page. The downside of this is that sometimes, the internet chokes up and 2 seconds is also not enough!!! Look around, there must be a property that sets when the page loads completely.

 

Amit

 

 

0 Kudos
Message 8 of 11
(4,897 Views)

Hello everyone!!!

 

First at all, Amit, thanks for informing us about this VI. I have to make a VI which gets data from a web site, and this VI has helped me to get some ideas about what I have to do. The problem is that it is my first time working with web site and I don't know very well what I have to do to get an specific element.

 

What I want to do is to save the TAI (temps atomique international, I think) in a device because I want to measure the non-accurancy of its internal clock (I will work with relative times so I think that possible delays are not  big deals). To get this time, I am using a web site (http://tycho.usno.navy.mil/simpletime.html). Of all the hours that you can find, I just need one (whatever). I am trying to get the first one. So, what I have done is to open the source code of the website and try to guess the name of this variable. As I have say I have not much idea about web sites so I don't know whether what I have done is right or not. Once I have the name (for the first one I think is USNOtime), I create an invoke node of the IHMTLElement to perform the getAttribute operation and in the strAttributeName parametre I write USNOtime. After that, I run the VI but I don't get any output.

 

Other thing I have tried is to use DataSocket functions. I have used DataSocket Read function and after this subVI, I have added a "GetVariantAttribute" one (once again in the name parametre I have written USNOtime), but it doesn't work either.

 

Do you know what I am doing wrong?

 

Thanks!

Mila

0 Kudos
Message 9 of 11
(4,769 Views)

You might want to try this VI from the NI Developer Zone

 

LabVIEW Atomic Clock

 

Downloads

Filename: atomic_clock.zip
Requirements: View

This VI connects to the US Naval Observatory through dataSocket, gets the time from the Master Clock, and displays it on the front panel. The VI uses string parsing to retrieve the time, and therefore depends on the format the data is displayed on the corresponding observatory site.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(4,764 Views)