I figure this is probably a simple question for most of you. How does one call a LabVIEW VI to execute from a Visual Basic Script? Also can one do the opposite and call Visual Basic Scripts from within LabVIEW? Thanks!
Here is example code to call a VI from a Visual Basic Script (VBS) using ActiveX. I don't include it as an attachment since it would certainly trigger antivirus warning... ' Reference to LabVIEW Application Dim lvapp ' Reference to called VI Dim viref ' Path to file VI or only the VI name if it ' is already in memory VIname = "c:\mydir\myVI.vi" VIPassword = "" ' Set resvForCall to True to invoke the Call method ' Set to False to invoke the Run method resvForCall = True ' Name(s) of the control of the VI ' that receives the data and indicators to read. ' They must be on the connector pane. Dim paramNames paramNames = Array("Input1","Output1") ' Value of control(s)on call. Values ' of indicators is irrelevant Dim paramVals
paramVals = Array("GetOutput1","") ' Open a connection to ActiveX VI Server set lvapp = WScript.CreateObject("labview.Application") ' get a VI reference set viref = lvapp.GetVIReference(VIname,VIPassword,resvForCall) ' call the VI viref.Call paramNames,paramVals ' Value of Output1 is the second element ' of paramVals
The Run method is simpler. You don't have to specify arguments paramNames and paramVals, just invoke viref.Run
To call a VBS from LabVIEW the most simple is to call the System Exec.vi with the command line: "wscript.exe [vbs path]".
I have been brief on the VI side... The called VI, here "myVI.vi" has at least one control named "Input1" which in this specific case is a string that receives the value "GetOutput1" when called by the script. All required inputs names on the connector pane must be included in the paramNames array. The VI has also at least one indicator named "Output1" whose value is returned in paramVals after the call. It is easy to set and return strings, numbers or booleans. I have not been able to transfer arrays with a Visual Basic Script but I think it is possible in a Visual Basic Application.