01-27-2009 04:29 PM
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?
Solved! Go to Solution.
01-27-2009 06:46 PM
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
01-28-2009 09:13 AM
01-28-2009 09:51 AM
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?
01-28-2009 10:12 AM
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
01-29-2009 10:07 AM
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.
01-29-2009 10:10 AM
01-29-2009 11:47 AM
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
04-01-2009 08:55 AM
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
04-01-2009 09:07 AM
You might want to try this VI from the NI Developer Zone
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.