LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a VI as ActiveXObject using Javascript

Hello,
 
I would like to control a Labview-VI (Version 7.1) from a Javascript-program by using the ActiveXObject-model.
 
It looks like that:
 
    lvapp = new ActiveXObject("Labview.Application");
    viPath = "C:\\test.vi";
    vi = lvapp.GetVIReference(viPath);   // Load the vi into memory
    vi.FPWinOpen = 1;                               // Open front panel
    var paramNames = new Array(["Input","Output"]);   // create array with parameter names
    var paramVals  =     new Array([125,0]);                       // create array with parameter values
 
    vi.Call(paramNames, paramVals);    // call Labview  --> error occurs here
 
    alert("Result from LV:"+paramVals[1]);

Starting Labview and loading the VI works fine. The scripts stops during the "Call"-methode.
Problem is, that an error occurs which indicates that VI-object does not unterstand
the Javascript array structure ("expected 1D-array"). If I call theVI without parameters everything
works fine, but this makes no sense since I cant exchange data with LV.
 
The same programm coded in VisualBasic-Script worked fine also.
 
Is there anyone who knows of which type parameters for "Call"-mehode must look like in
Javascript?? Every hint is welcome.
 
Regards
0 Kudos
Message 1 of 11
(5,447 Views)
The problem is that JScript arrays are unique to JScript - they are unlike other languages in that they are actually sparse arrays.
 
The ActiveX interface requires that the array that is passed in is a SAFEARRAY type. Inside JScript, this is exposed via the type VBArray. Give that a try.
0 Kudos
Message 2 of 11
(5,440 Views)

Hi,

thanks for fast response. The proposed way with an VBArray in Jscript does not work either. Even if it would have  - JScript does not allow to manipulate this kind of arrays. See:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsobjvbarray.asp

 There seems to be no way to pass the (array formatted) parameters from Jscript to the Labview-ActiveXObject.

 Obviously I have to change to Visual basic if there is no alternative way to call LV with primitve data types.

Regards

 

 

 

 

 

0 Kudos
Message 3 of 11
(5,437 Views)
Hmmm...well, I'm not an expert on JScript and ActiveX (anyone else want to jump in?), but the ActiveX interface requires that you send a SAFEARRAY of VARIANTs. The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time. Actually, that gives me another idea - if you do a GetControlValue on a Cluster Front Panel control or indicator, we'll return a SAFEARRAY of VARIANTs. If we can get JScript to give up information on what that is, we might be able to see how that should be created. Again, not an expert in JScript so I'm not sure.
 
BTW - What is the purpose of the script (and why it is a script)?
0 Kudos
Message 4 of 11
(5,435 Views)
Hi Brian
 
That was the hint I looked for:
 > The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time. 
0 Kudos
Message 5 of 11
(5,420 Views)
Hi Brian
 
That was the hint I looked for:
  > The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time. 
0 Kudos
Message 6 of 11
(5,421 Views)
Sorry, this replay was submitted befored finished...
 
Hi Brian
 
That was the hint I looked for:
  > The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time.
 
Since I stranded to create the mentioned SAFEARRAY of VARIANTs I tried it with the following way:
   lvapp = new ActiveXObject("Labview.Application");
    viPath = "C:\\test.vi";
    vi = lvapp.GetVIReference(viPath);   // Load the vi into memory
    vi.FPWinOpen = 1;                               // Open front panel
    vi.SetControlvalue("Input",125)       // set the input parameter, 125 is just a sample
    vi.Run();                                               // run the VI here, the"Call"-methode without parameter does not work since it uses
                                                                  // the defaults of the controls
 
    var paramNames = new Array(["Input","Output"]);   // create array with parameter names
    var paramVals  =     new Array([125,0]);                       // create array with parameter values
 
    vi.Call(paramNames, paramVals);    // call Labview  --> error occurs here
 
    alert("Result from LV:"+paramVals[1]);
0 Kudos
Message 7 of 11
(5,411 Views)
Sorry, this replay was submitted befored finished...
 
Hi Brian
 
That was the hint I looked for:
  > The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time.
 
Since I stranded to create the mentioned SAFEARRAY of VARIANTs I tried it with the following way:
   lvapp = new ActiveXObject("Labview.Application");
    viPath = "C:\\test.vi";
    vi = lvapp.GetVIReference(viPath);   // Load the vi into memory
    vi.FPWinOpen = 1;                               // Open front panel
    vi.SetControlvalue("Input",125)       // set the input parameter, 125 is just a sample
    vi.Run();                                               // run the VI here, the"Call"-methode without parameter does not work since it uses
                                                                  // the defaults of the controls
  
    var paramNames = new Array(["Input","Output"]);   // create array with parameter names
    var paramVals  =     new Array([125,0]);                       // create array with parameter values
 
    vi.Call(paramNames, paramVals);    // call Labview  --> error occurs here
 
    alert("Result from LV:"+paramVals[1]);
0 Kudos
Message 8 of 11
(5,411 Views)
Sorry, this replay was submitted befored finished...
 
Hi Brian
 
That was the hint I looked for:
  > The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time.
 
Since I stranded to create the mentioned SAFEARRAY of VARIANTs I tried it with the following way:
   lvapp = new ActiveXObject("Labview.Application");
    viPath = "C:\\test.vi";
    vi = lvapp.GetVIReference(viPath);   // Load the vi into memory
    vi.FPWinOpen = 1;                               // Open front panel
    vi.SetControlvalue("Input",125)       // set the input parameter, 125 is just a sample
    vi.Run();                                               // run the VI here, the"Call"-methode without parameter does not work since it uses
                                                                  // the defaults of the controls
   
    var paramNames = new Array(["Input","Output"]);   // create array with parameter names
    var paramVals  =     new Array([125,0]);                       // create array with parameter values
 
    vi.Call(paramNames, paramVals);    // call Labview  --> error occurs here
 
    alert("Result from LV:"+paramVals[1]);
0 Kudos
Message 9 of 11
(5,411 Views)
Sorry, this replay was submitted befored finished...
 
Hi Brian
 
Thanks, that was the tip I looked for:
 
  > The only other thing you could do would be to use the SetControlValue/GetControlValue to do the I/O one control at a time.
 
Since I stranded to create the mentioned SAFEARRAY of VARIANTs I tried it with on following way:
         lvapp = new ActiveXObject("Labview.Application");
    viPath = "C:\\test.vi";
    vi = lvapp.GetVIReference(viPath);   // Load the vi into memory
    vi.FPWinOpen = 1;                    // Open front panel
    vi.SetControlvalue("Input",125)      // set the input parameter, 125 is just a sample
    vi.Run();                            // run the VI here, the "Call"-methode without parameter
                                         // does not work since it uses
                                         // the defaults of the controls
    response = vi.GetControlvalue("Output")  // get the output parameter    
 
    alert("Result from LV:"+response);   

This works fine so far. Hope that I have never have to pass more complicated data structures.
The question why I need all this. I have a very special application which allows to be controlled
internally by Jscript. Unfortuntly it has no API (DLL or COM) but I need the functionality of
the application for a Labview-program. Therefore I look for a chance to provide an Interface
for Labview by using the scripting engine.
 
BTW Is there any detailed description of all methodes and properties of the Labview-ActiveXControl??
Rainer
 

Message Edited by rainercats on 11-17-2005 04:49 AM

0 Kudos
Message 10 of 11
(5,414 Views)