![](/img/trans.png)
[英]Different behaviour when opening Excel and Word in python using win32com.client.dispatch function
[英]win32com.client.Dispatch opening the undesired canoe version
我在我的工作站上安装了 2 个 CANoe 版本,我想通过调度打开 CANoe 11(因为我使用了在 CANoe 11 中制作的 cfg 文件),但它打开了 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()
我的问题:有什么方法可以告诉 dispatch 要打开哪个独木舟版本或如何将独木舟版本 11.0.81 SP3 设置为我的默认独木舟?
我认为首先我打开独木舟然后加载cfg文件是相关的
我已经尝试过:
1.删除canoe 10的所有系统和账户路径并替换canoe 11(之后重启电脑)
2.我试图把'CANoe.Application.11'而不是'CANoe.Application'
毕竟,它仍然打开 CANoe 版本 10
谢谢
您必须使用 Windows 资源管理器导航到 CANoe 11 安装的文件夹Exec32
或Exec64
。
在该文件夹中,您会找到一个名为RegisterComponents.exe
的 EXE 文件
执行该文件(具有管理员权限)。
这将将此 CANoe 安装注册为 CANoe-COM-Interface 的服务器。
所有这些也在 CANoe 文档中的 Topic Technical Reference -> COM Interface -> Computer Configuration 中进行了描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.