Advanced HMI Subscribe有一个指向m_SynchronizingObject的空指针
本文关键字:SynchronizingObject 空指针 HMI Subscribe 有一个 Advanced | 更新日期: 2023-09-27 18:16:20
尝试订阅时出现错误。m_Plc。读取函数工作得很好,但是对于我的应用程序来说太慢了。
这是我的代码:
private AdvancedHMIDrivers.EthernetIPforCLXCom m_Plc;
public MainPageViewModel()
{
m_Plc = new EthernetIPforCLXCom();
m_Plc.IPAddress = m_IPAddress;
m_Plc.ProcessorSlot = Convert.ToInt32(m_ProcessorSlot);
m_Plc.ComError += DoOnCommError;
m_Plc.SubscriptionError += DoOnCommError;
string testString = m_Plc.Read("MyTag");
int index = m_Plc.Subscribe("MyTag", 1, 2000, testPlcReaded);
}
private void testPlcReaded(object sender, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs e)
{
try
{
Console.WriteLine(e.Values[0]);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
,这是我得到的错误:
m_SynchronizingObject.BeginInvoke (SubscriptionList(我)。dlgCallBack, z)
在文件夹:EthernetIPforCLXCom.vb.
有一个指向m_SynchronizingObject的空指针。
错误细节:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=AdvancedHMIDrivers
StackTrace:
at AdvancedHMIDrivers.EthernetIPforCLXCom.DataLinkLayer_DataReceived(Object sender, PlcComEventArgs e) in C:'prj'TLLAB'TLLAB'AdvancedHMIBeta363 (1)'AdvancedHMIDrivers'EthernetIPforCLXCom.vb:line 1269
at MfgControl.AdvancedHMI.Drivers.CIP.OnDataReceived(PlcComEventArgs e)
at MfgControl.AdvancedHMI.Drivers.CIP.DataReceivedEIP(Object sender, PlcComEventArgs e)
在我看来是当前版本的一个bug
代码检查SynchronizingObject是否为空,或者在调用它之前是否创建了它的句柄,所以如果它为空,它就会崩溃
If m_SynchronizingObject Is Nothing OrElse DirectCast(m_SynchronizingObject, Windows.Forms.Control).IsHandleCreated Then
'...<some code>...
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallBack, z)
End If
你应该提交一个bug,因为它可能看起来像这样
If m_SynchronizingObject IsNot Nothing AndAlso DirectCast(m_SynchronizingObject, Windows.Forms.Control).IsHandleCreated Then
'...<some code>...
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallBack, z)
Else
'...<some other code>...
End If
编辑:我把这个贴在Sourceforge的项目网站上,Archie已经为下一个版本解决了这个问题
没有实例化对象。当您尝试使用它时,它是空的。这应该有帮助:
private EthernetIPforCLXCom m_Plc = new EthernetIPforCLXCom
{
IPAddress = m_IPAddress,
ProcessorSlot = Convert.ToInt32(m_ProcessorSlot),
ComError += DoOnCommError,
SubscriptionError += DoOnCommError
};