![]() |
ValueError: This COM object does not support events. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: ValueError: This COM object does not support events. (/thread-8795.html) |
ValueError: This COM object does not support events. - meenakshi11 - Mar-08-2018 Hello all, I am trying to access Canoe tool using python script. I want to call 'WithEvents' function to make event handler of COM object using pywin32 library, but constantly getting "Value Error:This COM object does not support events" on this line 'WithEvents(self.App.Measurement, CanoeMeasurementEvents)' Traceback: File "D:\Meenakshi\ECM\RunTests.py", line 84, in __init__ WithEvents(app.Measurement , MeasurementEvents) File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 334, in WithEvents raise ValueError("This COM object does not support events.") alueError: This COM object does not support events. I am using python 2.7, Canoe 8.1 version and pywin32 is 'pywin32-223-cp27-cp27m-win_amd64' . Please help. import time, os, msvcrt from win32com import * from win32com.client import * from win32com.client.connect import * def DoEvents(): pythoncom.PumpWaitingMessages() time.sleep(.1) def DoEventsUntil(cond): while not cond(): DoEvents() class CanoeSync(object): """Wrapper class for CANoe Application object""" Started = False Stopped = False ConfigPath = "" def __init__(self): app = DispatchEx('CANoe.Application') app.Configuration.Modified = False ver = app.Version print('Loaded CANoe version ', ver.major, '.', ver.minor, '.', ver.Build, '...') self.App = app self.Measurement = app.Measurement self.Running = lambda : self.Measurement.Running self.WaitForStart = lambda: DoEventsUntil(lambda: CanoeSync.Started) self.WaitForStop = lambda: DoEventsUntil(lambda: CanoeSync.Stopped) WithEvents(self.App.Measurement, CanoeMeasurementEvents) def Load(self, cfgPath): # current dir must point to the script file cfg = os.path.join(os.curdir, cfgPath) cfg = os.path.abspath(cfg) print('Opening: ', cfg) self.ConfigPath = os.path.dirname(cfg) self.Configuration = self.App.Configuration self.App.Open(cfg) def Start(self): if not self.Running(): self.Measurement.Start() self.WaitForStart() def Stop(self): if self.Running(): self.Measurement.Stop() self.WaitForStop() class CanoeMeasurementEvents(object): """Handler for CANoe measurement events""" def OnStart(self): CanoeSync.Started = True CanoeSync.Stopped = False print("< measurement started >") def OnStop(self) : CanoeSync.Started = False CanoeSync.Stopped = True print("< measurement stopped >") # ----------------------------------------------------------------------------- # main # ----------------------------------------------------------------------------- app = CanoeSync() # loads the sample configuration app.Load('CANoeConfig\PythonBasicEmpty.cfg') # start the measurement app.Start() # wait for a keypress to end the program print("Press any key to exit ...") while not msvcrt.kbhit(): DoEvents() # stops the measurement app.Stop() |