This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Passing output arguments to an ActiveX application
Type: compile error Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benji13, ezio.melotti, mark.dickinson
Priority: normal Keywords:

Created on 2009-09-23 16:04 by benji13, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg93043 - (view) Author: Benjamin (benji13) Date: 2009-09-23 16:04
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 
<module>
    Err = SysMonApp.GetOnline(byref(OnlineSt))
  File "<COMObject System Monitor API>", 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 
<module>
    Err = SysMonApp.GetOnline(OnlineSt)
  File "<COMObject System Monitor API>", 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
msg93044 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-09-23 16:13
If you need general help, the bug tracker is not the right place where
to ask. If you think you have found a bug please follow these
instructions and explain clearly what the problem is:
http://www.python.org/dev/workflow/.
msg93045 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-09-23 16:20
You might try asking on the ctypes-users mailing list:

https://lists.sourceforge.net/lists/listinfo/ctypes-users

I'll close this for now;  if, after discussing this on the ctypes-users 
list, you're reasonably sure that you've found a bug in Python itself 
(which is what this tracker is for), please come back and open another bug 
report.
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51228
2009-09-23 16:20:07mark.dickinsonsetstatus: pending -> closed
nosy: + mark.dickinson
messages: + msg93045

2009-09-23 16:13:24ezio.melottisetstatus: open -> pending

nosy: + ezio.melotti
messages: + msg93044

resolution: not a bug
2009-09-23 16:04:43benji13create