我想用Python来控制专有的光谱软件(Princeton Instruments LightField)。我有一个使用Matlab的LightField自动化示例。该示例使用.NET来使用提供的DLL来控制LightField。如何使用Python和.NET/C#自动化Princeton Instruments LightField
我用pythonnet将DLL加载到Python中,但是我没有和LightField通信。
这里是一个(非)工作示例:
import sys
sys.path.append(r"C:\Program Files\Princeton Instruments\LightField")
sys.path.append(r"C:\Program Files\Princeton Instruments\LightField\AddInViews")
import clr
clr.AddReference('PrincetonInstruments.LightFieldViewV4')
clr.AddReference('PrincetonInstruments.LightField.AutomationV4')
clr.AddReference('PrincetonInstruments.LightFieldAddInSupportServices')
import PrincetonInstruments.LightField.AddIns as AddIns
from PrincetonInstruments.LightField.Automation import Automation
instance = Automation(True,[])
这里是错误消息:
File "D:/python/test_lightfield.py", line 21, in instance = Automation(True,[])
TypeError: no constructor matches given arguments
但是,当我看着帮助(自动化)的开头:
help(Automation)
Help on class Automation in module PrincetonInstruments.LightField.Automation:
class Automation(System.Object)
| Void .ctor(Boolean, System.Collections.Generic.List`1[System.String])
|
| Method resolution order:
| Automation
| System.Object
| builtins.object
|
| Methods defined here:
|
| __call__(self, /, *args, **kwargs)
| Call self as a function.
或相关的Matlab示例文件:
out.automation = PrincetonInstruments.LightField.Automation.Automation(visible,[]);
它看起来像我用有效参数(一个布尔值和一个空字符串)实例化自动化类。 除了我的Matlab示例文件外,我没有太多文档。
我在做什么错?
编辑:这是一个类型的问题。使用.NET类型列表来代替Python列表。
from PrincetonInstruments.LightField.Automation import Automation
from System.Collections.Generic import List
from System import *
l = List[String]()
instance = Automation(True,l)