2
我正在尝试将事件处理程序附加到COM Object的事件。但是我得到一个InvalidOperationException。将事件处理程序附加到Com事件:InvalidOperationException(S7-PLCSIM)
using S7PROSIMLib;
private S7ProSim ps = new S7ProSim();
ps.Connect();
ps.SetScanMode(ScanModeConstants.SingleScan);
ps.BeginScanNotify();
try {
ps.ScanFinished += Ps_ScanFinished;
//IS7ProSimEvents_ScanFinishedEventHandler scanFinishedDelegate = new IS7ProSimEvents_ScanFinishedEventHandler(Ps_ScanFinished);
//ps.ScanFinished += scanFinishedDelegate;
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Source);
Console.WriteLine(ex.InnerException);
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
private void Ps_ScanFinished(object ScanInfo)
{
Console.WriteLine("Event fired");
}
输出为:
event invocation for COM objects requires event to be attributed with DispIdAttribute
at System.Runtime.InteropServices.ComAwareEventInfo.GetDataForComInvocation(EventInfo eventInfo, Guid& sourceIid, Int32& dispid)
at System.Runtime.InteropServices.ComAwareEventInfo.AddEventHandler(Object target, Delegate handler)
at PiPLCSimBridge.Form1.Form1_Load(Object sender, EventArgs e) in C:\PiPLCSimBridge\Form1.cs:Line 72.
我也曾尝试使用注释掉的代码,但得到了同样的异常。
附加这样的事件应该工作,使用相同的COM接口is doing it this way.
什么是错我的代码的流行工具?
您是否试图将RaspberryPi连接到300/400模拟器? – dss539
是的,你怎么能告诉?:D – c3ntry
:)这听起来很整齐。你是否试图将Pi用作远程IO或其他东西?你对这个项目的帮助感兴趣吗? – dss539