Issue 6979: Passing output arguments to an ActiveX application (original) (raw)

Hi.

I hope I'm in the good thing to expose my problem... I try to make a script in Python working under ControlDesk, a dSpace simulator. In this script I call an ActiveX application given by an external software, System Monitor, to get some information from my ECU (Engine Control Unit).

I can access to the ActiveX, I can call functions but only ones which don't need output argument. When I use functions which need only input argument, it's working perfectly. If I want to use functions which need some output argument, I have a message error from Python...

======================================================================== Here is an example of a working script:


import os import win32com.client

if name == 'main': print "" Kit = "C:\U\TNR_MES_2009\THR2RAT11BA01.m"

SysMonApp = win32com.client.Dispatch("System Monitor API")
if SysMonApp == None:
    print "Pas d'instance System Monitor"
#endif
Err = SysMonApp.SetLiveUpdates(True)
if Err != 0:
    print Err
#endif
print "LiveUpdates Actif"
Err = SysMonApp.MatlabImport(Kit)
if Err !=0:
    print Err
#endif
print "Import kit .m termine"

SysMonApp = None
print "Fin du script"    

#endif

Here is an example of a NON-working script: import os import win32com.client from ctypes import *

if name == 'main': print "" Kit = "C:\U\TNR_MES_2009\THR2RAT11BA01.m"

SysMonApp = win32com.client.Dispatch("System Monitor API")
if SysMonApp == None:
    print "Pas d'instance System Monitor"
#endif

#OnlineSt = False
OnlineSt = c_double()
Err = SysMonApp.GetOnline(byref(OnlineSt))
if Err != 0:
    print Err
#endif
if OnlineSt == True:
    print "ECU Online"
else:
    print "ECU Offline"
#endif

SysMonApp = None
print "Fin du script"    

#endif

======================================================================== The error message is:

Traceback (most recent call last): File "C:\Python26\Lib\site- packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript exec codeObject in main.dict File "C:\U\TNR_MES_2009\EssaiSysMonSeul_Output_KO.py", line 16, in Err = SysMonApp.GetOnline(byref(OnlineSt)) File "", line 2, in GetOnline TypeError: Objects of type 'CArgObject' can not be converted to a COM VARIANT

As you can see I use the ctype library to try pass output argument, using byref. But I also try to pass argument directly under python, without ctypes:

OnlineSt = False
Err = SysMonApp.GetOnline(OnlineSt)

and I had the folowing error message:

Traceback (most recent call last): File "C:\Python26\Lib\site- packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript exec codeObject in main.dict File "C:\U\TNR_MES_2009\EssaiSysMonSeul_Output_KO.py", line 16, in Err = SysMonApp.GetOnline(OnlineSt) File "", line 2, in GetOnline com_error: (-2147352571, 'Le type ne correspond pas.', None, 1)

The help for the activeX function explain that the output arguments need to be pass as pointer:

GetOnline Returns whether the ECU is online or not. Arguments: bool* bResult - whether the ECU is online or offline.

Do you have any idea to solve this problem?

Many thanks

Benjamin