0

我有一个连接到 TestStand 并从 .seq (序列)文件中检索某些数据的 python 脚本。

import win32com.client
import pythoncom
TestStandEngine = win32com.client.Dispatch("TestStand.Engine")
Seqfile = TestStandEngine .GetSequenceFileEx("Seq_File.seq")
Main = Seqfile.GetSequenceByName("MainSequence") #Get's the main sequence of the file

我已经安装了 Test Stand 2014 的 x32 和 x64 版本,并且脚本运行得很好。卸载 x64 版本后(因为不需要它),脚本现在给出此错误:

Traceback (most recent call last):
  File "C:\ts\Main.py", line 9, in <module>
    TestStandEngine = win32com.client.Dispatch("TestStand.Engine")
  File "C:\LegacyApp\Python_2.7\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\LegacyApp\Python_2.7\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\LegacyApp\Python_2.7\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

在做了一些研究之后,我想我知道是什么导致了这个问题,但我找不到任何方法来解决它。

- 我电脑上的 Python 安装是 32 位的

>>> import platform
>>> platform.architecture()
('32bit', 'WindowsPE')

- 我的电脑上唯一安装的测试台是 32 位版本。

-操作系统:Windows x64 位操作系统

这是我的猜测:我认为当它调度 Teststand.Engine 时,它​​会尝试使用不再安装的 x64 版本;我尝试添加 clsctx 参数,但结果相同:

win32com.client.Dispatch("TestStand.Engine",clsctx=pythoncom.CLSCTX_LOCAL_SERVER)

有没有办法“强制”它启动 32 位版本?如果 TestStand 是 32 位的,而 Python 是 32 位的,它不应该返回一个 32 位的 COM 对象,该对象应该与 python 32 位一起工作吗?

更新:因此,在 PowerShell 中运行命令后,它返回了 COM 的所有有效名称的列表,但“ Teststand.Engine ”不在列表中。列表中唯一与 TestStand 相关的对象是 TestStand.ExLauncher (我可以调度它,但它没有与 TestStand.Engine 相同的属性/用途

4

2 回答 2

0

您是否尝试使用版本相关接口,即

TestStandEngine = win32com.client.Dispatch("TestStand.Engine.1")
于 2018-11-21T20:15:33.213 回答
0

通过重新安装 TestStand 解决了这个问题。(我知道重新安装会解决问题,但我希望不必重新安装它,因为它会影响多个配置)

问题是,当我卸载 TestStand x64 版本时,卸载程序认为我要完全卸载 TestStand,并且很可能删除了一些包含“TestStand.Engine”说明的注册表项。重新安装 x32 位版本后,它工作正常。

于 2018-05-29T11:25:55.567 回答