Search code examples
pythoncompywin32win32comcanoe

win32com.client.Dispatch opening the undesired canoe version


I have 2x CANoe versions installed on my station and i want to open CANoe 11 (because i use a cfg file made in CANoe 11) with dispatch but instead it opens CANoe 10.

import time, os, msvcrt
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, '...', sep='')
        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()
       
# -----------------------------------------------------------------------------
# main
# -----------------------------------------------------------------------------
app = CanoeSync()

# loads the sample configuration
app.Load('path_to_the_cfg_file')

# 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()

My question: is there any way to tell dispatch what canoe version to open or how to set canoe version 11.0.81 SP3 as my default canoe?

I think it s relevant to say that firstly i open the canoe and then i load the cfg file

I already tried:

1.Deleting all system and account paths for canoe 10 and replacing them for canoe 11 (restarted pc after that)

2.I tried to put 'CANoe.Application.11' instead of 'CANoe.Application'

After all these it still opens CANoe version 10

Thanks


Solution

  • You have to navigate to the folder Exec32 or Exec64 of your CANoe 11 installation with the windows explorer.

    Inside that folder you find an EXE-file called RegisterComponents.exe

    Execute that file (with administrator rights).

    This will register this CANoe installation as server for the CANoe-COM-Interface.

    All this is also described in CANoe's documentation in Topic Technical Reference -> COM Interface -> Computer Configuration