Python Forum
ValueError: This COM object does not support events.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: This COM object does not support events.
#1
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wait for the first of these events Skaperen 4 1,926 Mar-07-2022, 08:46 PM
Last Post: Gribouillis
  'int' object does not support item assignment shane1236 5 7,492 Aug-13-2019, 01:53 PM
Last Post: buran
  Error: int object does not support item assignment ankita_nthu 2 13,951 Jul-07-2019, 02:14 PM
Last Post: ankita_nthu
  ValueError: invalid rectstyle object fen1c5 1 5,659 Jun-05-2019, 02:51 PM
Last Post: heiner55
  How do I use this? TypeError: 'NoneType' object does not support item assignment ejected 9 22,266 Mar-26-2019, 05:06 AM
Last Post: ejected
  Simulating events using Hawkes akshit2291 1 2,138 Sep-25-2018, 04:17 AM
Last Post: Larz60+
  win32com Events not catching dageci 0 3,740 Aug-06-2018, 03:18 PM
Last Post: dageci
  'str' object does not support item assignment SolaVitae 1 9,801 Jul-28-2017, 06:03 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020