所以我设法在 Python .NET 中导入了一个托管的 .NET 程序集,并且设置了几个对象并调用了一些函数,但我不知道这个程序应该如何工作。
这是我要移植的 C# 代码:
// read event sticky clears all initial events
CML_EVENT_STATUS status=0;
xAxisAmp.ReadEventSticky(ref status);
statusTextBox.Text = Convert.ToString(status);
我可以导入CML_EVENT_STATUS
,它报告它是<class 'CMLCOMLib.CML_EVENT_STATUS'>
,但是当我尝试创建它的实例时,我收到此错误:
>>> stat = CML_EVENT_STATUS()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot instantiate enumeration
如果有另一种方法来调用该函数,我无法弄清楚。我试过调用xAxisAmp.ReadEventSticky()
and xAxisAmp.ReadEventSticky(0)
,它只是 return TypeError: No method matches given arguments
。
我得到的最接近的是这个错误xAxisAmp.ReadEventSticky(CML_EVENT_STATUS)
:
System.ArgumentException: Object of type 'System.RuntimeType' cannot be converted to type 'CMLCOMLib.CML_EVENT_STATUS&'.
我究竟做错了什么?我找不到任何关于声明枚举类型或通过引用传递它们的文档,这让我发疯。