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