[python-win32] Calling Labview 8 via Python and COM

2006-07-03 Thread propadovic . nenad
Hello,

I'm having an issue with Python/COM and Labview.
What I want to do is to instantiate Labview an let it open and execute a "VI"
(virtal instrument). 

This works well in Visual Basic:
---
'Declare the object type of a lvApp and VI
Dim lvApp As LabVIEW.Application
Dim VI As LabVIEW.VirtualInstrument
Dim VIPath As String

'Create a reference to LabVIEW
Set lvApp = CreateObject("LabVIEW.Application")

'Determine the path to the VI
VIPath = lvApp.ApplicationDirectory + "\Examples\General\Strings.llb\Parse
Arithmetic Expression.vi"

'Assign an object reference to VI
Set VI = lvApp.GetVIReference(VIPath)

Dim ParamNames(0 To 1) As String
Dim ParamVals(0 To 1) As Variant

ParamNames(0) = "Arithmetic Expression"
ParamNames(1) = "Result"

ParamVals(0) = "3*77"
VI.ShowFPOnCall = True

'Call the VI
Call VI.Call(ParamNames, ParamVals)
MsgBox ParamVals(1)
---

My Python equivalent is:
-LVCOM.py:-
from  win32com.client import Dispatch

lvApp = Dispatch("LabVIEW.Application.8")

VIPath = lvApp.ApplicationDirectory +  r"\Examples\General\Strings.llb\Parse
Arithmetic Expression.vi"
print VIPath
VI=lvApp.GetVIReference(VIPath)

ParamNames = []
ParamNames.append("Arithmetic Expression")
ParamNames.append("Result")  

ParamVals = []
ParamVals.append("3*77")
ParamVals.append("0")


VI.ShowFPOnCall = True
VI.Call(ParamNames, ParamVals)
print ParamVals[1]
--
Here the call:
VI.Call(ParamNames, ParamVals)
succeeds partially. The GUI of the "virtual instrument" is opened, but the new
values of the parameters are not inserted, and I get this traceback:

Traceback (most recent call last):
  File
"C:\dSPACE4.2\Common\Python22\Core\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
  File "C:\user\nenad\LabviewPyCOM\LVCOM.py", line 20, in ?
VI.Call(ParamNames, ParamVals)
TypeError: 'NoneType' object is not callable

As far as I understand, the problem is related to how Labview accepts the
arguments of the call. ParamNames is an array of string references, ParamVals is
an array of references to variants. In VB the values in ParamVals are used both
to transfer the values of the parameters, and to receive the results.

I realise this is not handeled this way in PythonCOM - as stated in the Paragraf
"Passing and Obtaining Python Objects from COM", chapter 12 of "Python
programming on Win32" - so I  frankly don't have a clue  if what I'm trying to
do is possible at all.

Also, please note that the type of the object VI is not known to Python:
>>> VI
>
because it was returned by a factory method, I guess.

I'd be gratefull for any helpfull sugestion.

Sincerelly,

Nenad Propadovic


-
debitel.net Webmail
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Calling Labview 8 via Python and COM

2006-07-05 Thread propadovic . nenad
Hello Mr. Hammond,

thanks a lot for the answer. I tried the solution, and it woks fine, that is,
with Python 2.4 and a recent version of win32all.

I'm, however, bound to Python 2.2.1 and win32all build 146, which are an
integral part of the software offering of dSpace automotive test equipment 
company.
So when I use the method _FlagAsMethod, I receive the following traceback:
...
AttributeError: ._FlagAsMethod

Is there a way to patch this new feature into the distribution I'm using,
without changing the whole setup of the SW?

Thanks in advance,

Nenad Propadovic

> > VI.ShowFPOnCall = True
> > VI.Call(ParamNames, ParamVals)
> > print ParamVals[1]
> 
> Before the failing Call, try adding:
> 
> VI._FlagAsMethod("Call")
> 
> _FlagAsMethod is a helper method inside these dynamic objects and will help
> work-around COM objects that don't differentiate property references from
> method calls (such as LabView)


-
debitel.net Webmail
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Calling Labview 8 via Python and COM

2006-07-06 Thread propadovic . nenad
Hello Mr. Hammond,
thanks once again, it worked fine, indeed.
Have a nice day.
Yours sincerelly,
Nenad Propadovic


> > Is there a way to patch this new feature into the
> > distribution I'm using,
> > without changing the whole setup of the SW?
> 
> This function should patch into that win32all version just fine.  Locate the
> method definition in win32com\client\dynamic.py, and just paste it directly
> into the relevant location in your older version.  These files have been
> fairly stable for quite some time, so I fully expect that to work (but let
> me know if it doesn't and I'll try and track down the exact checkin I made)
> 
> Mark





-
debitel.net Webmail
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32