LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling LabView ActiveX Server from TCL?

Does anyone have experience calling a LabView ActiveX server vi from
TCL? I created a simple VI with one control (labeled "A") and one
indicator (labeled "B") and a +1 adder between them. I can load and
open the VI from TCL:

package require tcom
set lv [::tcom::ref createobject "LabView.Application"]
set viPath "D:\\National Instruments\\LabView\\Activity\\a.vi"
set vi [$lv GetVIReference $viPath]
$vi FPWinOpen True

But when I try to send in data:

$vi -namedarg Call A 1

I get the error message "unknown parameter A".

I have also attempted to duplicate the "ActiveX Server" example
from the LabView help file, calling "Frequency Response.vi". This
approach encounters the same error message:

% package require t
com
3.0
% set lv [::tcom::ref createobject "LabView.Application"]
::tcom::handle0x013202F4
% set viPath "D:\\National
Instruments\\LabView\\examples\\apps\\freqresp.llb\\frequency
Response.vi"
D:\National Instruments\LabView\examples\apps\freqresp.llb\frequency
Response.vi
% set vi [$lv GetVIReference $viPath]
::tcom::handle0x01335AE8
% $vi FPWinOpen True
% $vi -namedarg Call Amplitude 10
unknown parameter Amplitude

If anyone can point me in the right direction, or give me an
example of how to do this I would greatly appreciate it.

TIA.

Leslie
0 Kudos
Message 1 of 10
(4,049 Views)
I have not used LabVIEW ActiveX VI Server with Perl but can give some
pointers about calling the ActiveX VI Server.

First when invoking the Call method, the VI must be opened and reserved for
call, that is setting the resvForCall parameter to True. It also expects an
array of strings as the parameter name list (these controls/indicators must
be on the connector pane) and an array of variant as the parameters values.

In a Visual Basic Script, that would be:

'********
Dim lvapp,viref,paramNames,paramVals
VIname = "a.vi"
VIPassword = ""
resvForCall = True
paramNames = Array("file")
paramVals = Array("c:\data.txt")

set lvapp = WScript.CreateObject("labview.Application")
set viref = lvapp.GetVIReference(VIname,VIPassword,resvForCall)
viref.Call paramNames
,paramVals
'*********

This piece of code sets the "a.vi" control named "file" to "c:\data.txt" and
calls the VI.

It might be simpler to invoque the "Run" method. The VI is not reserved for
call on open. Before running the VI, use the "Set Control Value" method to
set the input controls (not necessarly on the connector pane). Then run the
VI and use the "Get Control Value" method to retrieve the
controls/indicators values when finished.

I hope that helps

Jean-Pierre Drolet


LabVIEW, C'est LabVIEW

0 Kudos
Message 2 of 10
(4,048 Views)
In article ,
Leslie Brooks wrote:
>
>package require tcom
>set lv [::tcom::ref createobject "LabView.Application"]
>set viPath "D:\\National Instruments\\LabView\\Activity\\a.vi"
>set vi [$lv GetVIReference $viPath]
>$vi FPWinOpen True
>
> But when I try to send in data:
>
>$vi -namedarg Call A 1
>
> I get the error message "unknown parameter A".

I don't use LabView, but from the Visual Basic example I saw, it seems
the Call method takes two arguments. The first is an array of parameter
names and the second is an array of parameter values. Try to send in
data with the Tcl command

$vi Call [list A] [list 1]
0 Kudos
Message 3 of 10
(4,048 Views)
"Chin Huang" wrote in message news:9q2n97$26ah$1@news.tht.net...
>
> I don't use LabView, but from the Visual Basic example I saw, it seems
> the Call method takes two arguments. The first is an array of parameter
> names and the second is an array of parameter values. Try to send in
> data with the Tcl command
>
> $vi Call [list A] [list 1]

I'm unable to help the original question (don't know LAbView or VB stuff) but
just want to point out that [list A] is equal to A and [list 1] is the same as 1.

Bruce
0 Kudos
Message 4 of 10
(4,048 Views)
"Bruce Hartweg" wrote in message news:...
> "Chin Huang" wrote in message news:9q2n97$26ah$1@news.tht.net...
> >
> > I don't use LabView, but from the Visual Basic example I saw, it seems
> > the Call method takes two arguments. The first is an array of parameter
> > names and the second is an array of parameter values. Try to send in
> > data with the Tcl command
> >
> > $vi Call [list A] [list 1]
>
> I'm unable to help the original question (don't know LAbView or VB stuff) but
> just want to point out that [list A] is equal to A and [list 1] is the same as 1.
>
> Bruce

I know what is supposed to be passed to the 'Call' method. Doing
this:

set inst
[::tcom::info interface $vi]
$inst methods

produces (among other things):

{1015 VOID Call {{{in out} {VARIANT *} paramNames} {{in out} {VARIANT
*} paramVals}}}

So the 'Call' method is expecting two parameters, both pointers
to variants. TCOM appears to be passing the correct parameter type
because the TCOM documentation says that a TCL List maps to a
one-dimensional array of VT_VARIANT. However, the results are
INvariant (bad pun intended):

% $vi -namedarg Call Amplitude 10
unknown parameter Amplitude
% $vi -namedarg Call [list Amplitude] [list 10]
unknown parameter Amplitude
% $vi -namedarg Call [list Amplitude] [list [::tcom::na]]
unknown parameter Amplitude
% set i 5
5
% $vi -namedarg Call [list Amplitude] {incr i}
unknown parameter Amplitude
% $vi -namedarg Call [list Amplitude] [list [incr i]]
unknown parameter Amplitude
% $vi -namedarg Call Amplitude [incr i]
unknown parameter Amplitude

Who can help me with this? Who is the LabView Guru?

Leslie
0 Kudos
Message 5 of 10
(4,048 Views)
Few more remarks that might help:

- The Call method expects variable arguments to return values: you can't
invoque it with arguments that are expressions or constants.
- For your "a.vi" in the original post, you need to connect A and B on the
connector pane.
- In your script, set a variable (say paramNames) to an array(list?) of
strings "A","B". You need to specify B also if you want to retrieve the
value of B after the call. Set also a variable (say paramVals) which is an
array of values for A and B. On return from the call, paramVals should
contain the value of A and B after execution.

Jean-Pierre Drolet


LabVIEW, C'est LabVIEW

0 Kudos
Message 6 of 10
(4,048 Views)
In article ,
Leslie Brooks wrote:
>
>% $vi -namedarg Call Amplitude 10
>unknown parameter Amplitude
>% $vi -namedarg Call [list Amplitude] [list 10]
>unknown parameter Amplitude
>% $vi -namedarg Call [list Amplitude] [list [::tcom::na]]
>unknown parameter Amplitude
>% set i 5
>5
>% $vi -namedarg Call [list Amplitude] {incr i}
>unknown parameter Amplitude
>% $vi -namedarg Call [list Amplitude] [list [incr i]]
>unknown parameter Amplitude
>% $vi -namedarg Call Amplitude [incr i]
>unknown parameter Amplitude
>
> Who can help me with this? Who is the LabView Guru?

The -namedarg option doesn't work the way you seem to think it works.
The -namedarg option provides
a way to specify arguments named from the
method's parameter specification. For example, you discovered that the
Call method takes two parameters named "paramNames" and "paramVals".
Tcom returns the error "unknown parameter Amplitude" because "Amplitude"
doesn't match either parameter name.

Both parameters of the Call method have the [in, out] mode, which means
tcom expects you to set the values you want to pass into Tcl variables
and specify those Tcl variable names as arguments to the Call method.

set names [list Amplitude]
set values [list 1]
$vi Call names values
0 Kudos
Message 7 of 10
(4,048 Views)
cthuang@vex.net (Chin Huang) wrote in message news:<9q64bc$311t$1@news.tht.net>...
> In article ,
> Leslie Brooks wrote:
> >
> >% $vi -namedarg Call Amplitude 10
> >unknown parameter Amplitude
> >% $vi -namedarg Call [list Amplitude] [list 10]
> >unknown parameter Amplitude
> >% $vi -namedarg Call [list Amplitude] [list [::tcom::na]]
> >unknown parameter Amplitude
> >
> > Who can help me with this? Who is the LabView Guru?
>
> Both parameters of the Call method have the [in, out] mode, which means
> tcom expects you to set the values you want to pass into Tcl variables
> and specify those Tcl variable names as arguments to the Call method.
>
>
set names [list Amplitude]
> set values [list 1]
> $vi Call names values

Chin Huang is the ActiveX GURU! To complete the LabView helpfile
example:

#
# Interfacing to LabView via TCOM
#
package require tcom

#
# Start the TAU GUI as an ActiveX server
#
set lv [::tcom::ref createobject "LabView.Application"]

set viPath "D:\\National Instruments\\LabView\\activity\\a.vi"
set vi [$lv GetVIReference $viPath]
$vi FPWinOpen True

#
# Create the parameter array
#
set names [list Amplitude "Number of Steps" "Low Frequency" "High
Frequency" "Response Graph"]

#
# Create the values array
#
set values [list 5 105 15 1005 0]

#
# Call the VI and get the results
#
$vi Call names values

#
# The Response Graph is returned in 'values'
#
puts $values

5 105 400 2000 {{400.0 406.238291234 412.573873162...} {...}}

Thank you Chin Huang!
0 Kudos
Message 8 of 10
(4,048 Views)
lesliebrooks@my-deja.com (Leslie Brooks) wrote in message news:...
> cthuang@vex.net (Chin Huang) wrote in message news:<9q64bc$311t$1@news.tht.net>...

In my example I gave the wrong path. These lines:

> #
> # Start the TAU GUI as an ActiveX server
> #
> set lv [::tcom::ref createobject "LabView.Application"]
>
> set viPath "D:\\National Instruments\\LabView\\activity\\a.vi"

should change to:

#
# Start "Frequency Response.vi" as an ActiveX server
#
set lv [::tcom::ref createobject "LabView.Application"]

set viPath "D:\\National
Instruments\\LabView\\examples\apps\freqresp.llb\Frequency
Response.vi"
set vi [$lv GetVIReference $viPath]

If you want to
invoke a VI that has been compiled, do this:

#
# Start the compiled "Frequency Response.vi" as an ActiveX server
#
set lv [::tcom::ref createobject "Frequency Response.Application"]

set viPath "Frequency Response.vi"
set vi [$lv GetVIReference $viPath]

(Of course the EXE file must be registered with Windows as an
ActiveX server.) You can register a LabView-compiled server EXE like
this:

C>My_EXE_Name /RegServer
0 Kudos
Message 9 of 10
(4,048 Views)
In article ,
Leslie Brooks wrote:
>"Bruce Hartweg" wrote in message
>news:...
>> "Chin Huang" wrote in message
>news:9q2n97$26ah$1@news.tht.net...
>> >
>> > I don't use LabView, but from the Visual Basic example I saw, it seems
>> > the Call method takes two arguments. The first is an array of parameter
>> > names and the second is an array of parameter values. Try to send in
>> > data with the Tcl command
>> >
>> > $vi Call [list A] [list 1]
>>
>> I'm unable to help the original question (don't know LAbView or VB stuff) but
>> just want to point out that [list A] is equal to A and [list 1] is the
>same as 1.
>>
>> Bruce
>
> I know what is supposed to be passed to the 'Call' method. Doing
>this:
>
>set inst [::tcom::info interface $vi]
>$inst methods
>
> produces (among other things):
>
>{1015 VOID Call {{{in out} {VARIANT *} paramNames} {{in out} {VARIANT
>*} paramVals}}}
>
> So the 'Call' method is expecting two parameters, both pointers
>to variants. TCOM appears to be passing the correct parameter type
>because the TCOM documentation says that a TCL List maps to a
>one-dimensional array of VT_VARIANT. However, the results are
>INvariant (bad pun intended):
>
>% $vi -namedarg Call Amplitude 10
>unknown parameter Amplitude
>% $vi -namedarg Call [list Amplitude] [list 10]
>unknown parameter Amplitude
>% $vi -namedarg Call [list Amplitude] [list [::tcom::na]]
>unknown parameter Amplitude
>% set i 5
>5
>% $vi -namedarg Call [list Amplitude] {incr i}
>unknown parameter Amplitude
>% $vi -namedarg Call [list Amplitude] [list [incr i]]
>unknown parameter Amplitude
>% $vi -namedarg Call Amplitude [incr i]
>unknown parameter Amplitude
>
> Who can help me with this? Who is the LabView Guru?

Try invoking the Call method without the -namedarg option. The
-namedarg option doesn't work the way you seem to think it works. The
-namedarg option provides a way to specify arguments named from the
method's parameter specification. For example, you discovered that the
Call method take two parameters named "paramNames" and "paramVals".
Tcom returns the error "unknown parameter Amplitude" because "Amplitude"
doesn't match either parameter name.
0 Kudos
Message 10 of 10
(4,047 Views)