修正PM未安装时,仍然会触发报警的问题。

This commit is contained in:
DESKTOP-1N1NK8A\auvkk 2023-04-20 16:10:41 +08:00
parent c89c1ca41b
commit 70e11bc6b0
4 changed files with 28 additions and 26 deletions

View File

@ -580,7 +580,7 @@ namespace SicModules.PMs
public void InitDevice()
{
if (IsInstalled)
if (IsInstalled) // 如果未安装不要初始化Module中的Device以免触发不必要的报警
{
if (SC.GetValue<bool>("System.IsSimulatorMode"))
{
@ -594,40 +594,42 @@ namespace SicModules.PMs
(Plc as SicAds).Initialize();
}
}
if (Plc != null)
{
Plc.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
Plc.OnConnected += PlcConnected;
Plc.OnDisconnected += PlcDisconnected;
_allModuleDevice.Add(Plc);
}
_isTagAttribute = attribute => attribute is TagAttribute;
_hasTagAttribute = mi => mi.GetCustomAttributes(false).Any(_isTagAttribute);
Parallel.ForEach(this.GetType().GetProperties().Where(_hasTagAttribute),
field =>
if (Plc != null)
{
TagAttribute tag = field.GetCustomAttributes(false).First(_isTagAttribute) as TagAttribute;
IDevice device = DEVICE.GetDevice<IDevice>($"{Module}.{tag.Tag}");
device.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
Plc.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
Plc.OnConnected += PlcConnected;
Plc.OnDisconnected += PlcDisconnected;
_allModuleDevice.Add(device);
_allModuleDevice.Add(Plc);
}
PropertyInfo pi = (PropertyInfo)field;
_isTagAttribute = attribute => attribute is TagAttribute;
_hasTagAttribute = mi => mi.GetCustomAttributes(false).Any(_isTagAttribute);
Parallel.ForEach(this.GetType().GetProperties().Where(_hasTagAttribute),
field =>
{
TagAttribute tag = field.GetCustomAttributes(false).First(_isTagAttribute) as TagAttribute;
IDevice device = DEVICE.GetDevice<IDevice>($"{Module}.{tag.Tag}");
device.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
var convertedValue = Convert.ChangeType(device, pi.PropertyType);
_allModuleDevice.Add(device);
System.Diagnostics.Debug.Assert(convertedValue != null);
PropertyInfo pi = (PropertyInfo)field;
pi.SetValue(this, convertedValue);
});
var convertedValue = Convert.ChangeType(device, pi.PropertyType);
if (_pmInterLock == null)
{
_pmInterLock = DEVICE.GetDevice<IoInterLock>($"{Module}.PMInterLock");
System.Diagnostics.Debug.Assert(convertedValue != null);
pi.SetValue(this, convertedValue);
});
if (_pmInterLock == null)
{
_pmInterLock = DEVICE.GetDevice<IoInterLock>($"{Module}.PMInterLock");
}
}
}