LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling a web page from Labview

Solved!
Go to solution

You are correct - there is, in fact, an ActiveX control embedded in there.  It just wasn't visible in the tiny bit of the source in your screenshot.  The key bit of HTML/Javascript is:

 

				document.write('<object classid="CLSID:DD01C8CA-5DA0-4b01-9603-B7194E561D32" name="Tvs" width="720" height="');
				if (1 == '0')
				{
					document.write('576');
				}
				else
				{
					document.write('480');
				}
				document.write('" codebase="rel/webViewer.cab#Version=' + TVS_VERSION + '"></object>');    

This gives you the location on the server of the .cab file that contains the ActiveX component.  Download that file (webViewer.cab) and expand it - you may be able to run it directly; or rename it to .zip instead and see if you can extract it; or try the "expand" command-line tool included with some versions of Windows.  That should get you a DLL and probably some other files.  You'll note that the name of this object within the web page is Tvs.  You can now use the code I demonstrated to get a reference to the Tvs object by name.  Use Variant to Data to convert it to an ActiveX reference; you'll get the correct class by right-clicking the class constant, selecting Browse..., and locating the DLL you got from the .cab file.  Once you've done all that, you should have access to all the methods in that ActiveX component, and specifically the Snapshot and PreviewSnapshot methods which are called when you click the Snapshot button, as found in the incl/tvs.js file:

function tvs_snapshot(fileName)
{
	if (g_lChID =3D=3D 0)
	{
		return;
	}

//	document.Tvs.Snapshot(g_lChID, true);

	document.Tvs.Snapshot(g_lChID, 0, false); // 0 =3D bmp, 1=3Djpg
//	document.Tvs.Snapshot(g_lChID, false); // 0 =3D bmp, 1=3Djpg
	document.Tvs.PreviewSnapshot(g_lChID);
}

 

0 Kudos
Message 11 of 24
(3,016 Views)

One other thing you could try, as suggested in this thread, is to send the web browser object to "javascript&colon;on_snapshot()".  If that works for you it's certainly much simpler.

0 Kudos
Message 12 of 24
(3,008 Views)

Ok, I expanded the webViewer.cab and now I got TVS.dll. Sorry if I'm being too slow, but I find this thing really confusing, I don't know how to browse that .dll through the VarianttoData function. I think I saw how this should be done somewhere but I just can't find the way. With the use of this .dll, I wouldn't even need to login, am I right? and I could acquire and save the image directly from LabView? Would I still need those property and handle node functions to handle this whole thing of the HTML?

 

Thanks for your time.

0 Kudos
Message 13 of 24
(2,997 Views)
Solution
Accepted by topic author kalinikos

You'll need to experiment to find out what is possible with this Tvs ActiveX control.  Unfortunately you don't get any documentation, unless you're really lucky and the manufacturer is willing to help you, so you'll have to see what methods and properties the control provides and look through the web page source code to see how they're used.  It might be that the only way to do what you want is by embedding the TVS control in your LabVIEW application and bypassing Internet Explorer.  The snapshot function requires a Channel ID parameter that is returned by the Tvs Connect command; I'm not sure how you could get access within LabVIEW to the Javascript variable (g_lChID) in which that value is stored when running inside the web page.  If you were to do this directly through LabVIEW you'd have to run the connect command yourself but you'd have access to the Channel ID.

 

As for the Type input to Variant to Data, you need an Automation Refnum constant, which you can get by creating a constant from the refnum input or output of any ActiveX property or invoke node.  You could also drop an Automation Open primitive and create a constant from that.  Then, right-click on the constant, choose Select ActiveX Class -> Browse... and browse to the DLL.  I'm not sure which of the classes you'll need to create, but click the "Show Createable Objects Only" checkbox to limit the options.  The screenshot I posted earlier shows how you would get the reference to the object within the web page and cast it to the correct type using Variant to Data.

 

It's possible that your DLL also contains an ActiveX control that can be embedded on the front panel of your LabVIEW VI; without the entire contents of the .cab it's hard for me to tell (and we're pushing the limits of my knowledge of ActiveX here).  If there is one, that's what you'd want to use.

Message 14 of 24
(2,983 Views)

I've been trying to reach the manufacturer with no luck. I'm still trying to put things together. Besides the TVS.dll, how do I know if I need another file and how can I read the .dll file (the code that's in there)?

Attached are the other dlls that came out from the webViewer.cab, I had to split them in two files. Thank you very much for your time, I really appreciate it.

 

 

 

Download All
0 Kudos
Message 15 of 24
(2,973 Views)

As a start, drop an Automation Open (from the ActiveX palette) on the block diagram of a new VI.  Create a constant from the Automation Refnum input.  Right-click that constant, choose "Select ActiveX Class -> Browse...", wait for a while, click "Browse..." and navigate to TVS.dll.  Click "Show Createable Objects Only" and pick one that looks like it might be what you want (if it's not, you can always repeat this process later and pick a different object).  Then wire a property node and an invoke node (also from the ActiveX palette) to the Refnum output of Automation Open.  When you click on those nodes you'll see a list of properties and methods available for that object.  If you've selected the right class, those methods will be the same ones that the web page calls.  Check the include file TVS.js (you can download this directly from your video server) for the methods that are used in the web page.  With some experimentation you may be able to duplicate in LabVIEW what the web page does, although I cannot promise this.

 

I can't provide more specific directions, due to lack of both time and access to the real hardware.  I realize it sounds complicated, and I can't refer you to a good source of information - I just like to play with these things until they make sense to me.

 

By the way, did you ever try the much-simpler approach of sending an embedded internet explorer to the camera web page, then, once you're there, sending it to javascript &colon; on_snapshot()?

0 Kudos
Message 16 of 24
(2,989 Views)

Regarding the simpler approach, I haven't tried because once I logged in, LabView started crashing and gets out of LabView automatically, but that is something that I have to figure out.

0 Kudos
Message 17 of 24
(2,979 Views)

I created a simple VI, but when I run it, I'm getting an error code -2147467259 "unspecified error". I don't know if a have to call other function first or what I am supposed to change. The IChID is 1 because I checked that in the TVMS program, but for the ICompresion value I have tried many different numbers with no luck. I would appreciate any comment or tip you may have.

 

Thank you very much

0 Kudos
Message 18 of 24
(2,951 Views)

Which function returns the error: Connect, or GetSnapshot?

 

I don't know if it will make a difference, but if you look at tvs.js, it looks like the tvs_connect function sets two LocalConfig properties before executing the Connect method; you could try to duplicate that.

0 Kudos
Message 19 of 24
(2,940 Views)

The one that throws the error is GetSnapshot.

Which two LocalConfig properties are you referring to? and what do you mean by duplicating it? Thanks again for your time

0 Kudos
Message 20 of 24
(2,935 Views)