Commit 3fc76b07 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 ErrorConf 添加PLC 断开 报警编号

parent a20a0d42
...@@ -17,7 +17,6 @@ namespace FLY.OBJComponents.Server ...@@ -17,7 +17,6 @@ namespace FLY.OBJComponents.Server
const int MARKNO_DELAY_ISCONNECTED = 4; const int MARKNO_DELAY_ISCONNECTED = 4;
#endregion #endregion
List<string> plcNames;
/// <summary> /// <summary>
/// 需要设置 /// 需要设置
/// </summary> /// </summary>
...@@ -26,21 +25,49 @@ namespace FLY.OBJComponents.Server ...@@ -26,21 +25,49 @@ namespace FLY.OBJComponents.Server
/// 报警系统 /// 报警系统
/// </summary> /// </summary>
WarningSystem2 mWarning; WarningSystem2 mWarning;
public byte ErrCode=0; /// <summary>
public ErrorConf(PLCProxySystem PLCos, WarningSystem2 mWarning, string plcName) /// 报警码自动排号,再枚举IsError 属性,对应的异常会被设置为ErrCode, 然后ErrCode++
/// </summary>
public int ErrCode =0;
class PlcDisconnectedErrMsg
{ {
this.PLCos = PLCos; public int ErrCode;
this.mWarning = mWarning; public string Description;
plcNames = new List<string>();
plcNames.Add(plcName);
} }
List<PlcDisconnectedErrMsg> plcDisconnectedErrMsgs = new List<PlcDisconnectedErrMsg>();
public ErrorConf(PLCProxySystem PLCos, WarningSystem2 mWarning, string plcName) : this(PLCos, mWarning, new string[] { plcName })
{
}
public ErrorConf(PLCProxySystem PLCos, WarningSystem2 mWarning, string[] plcNames) public ErrorConf(PLCProxySystem PLCos, WarningSystem2 mWarning, string[] plcNames)
{
initialize(PLCos, mWarning, plcNames, PlcErrNos.Instance.ERRNO_PLC_DISCONNECTED.Code - (PLCos.PLCs.Count() - 1));
}
public ErrorConf(PLCProxySystem PLCos, WarningSystem2 mWarning, string[] plcNames, int plcErrCodeBegin)
{
initialize(PLCos, mWarning, plcNames, plcErrCodeBegin);
}
void initialize(PLCProxySystem PLCos, WarningSystem2 mWarning, string[] plcNames, int plcErrCodeBegin)
{ {
this.PLCos = PLCos; this.PLCos = PLCos;
this.mWarning = mWarning; this.mWarning = mWarning;
this.plcNames = new List<string>();
if (plcNames.All(s => !string.IsNullOrEmpty(s))) //初始化 PLC连接断开的描述列表
this.plcNames.AddRange(plcNames); int plcCnt = PLCos.PLCs.Count();
int errCode = plcErrCodeBegin;
string descrption = PlcErrNos.Instance.ERRNO_PLC_DISCONNECTED.Descrption;
for (int i = 0; i < plcCnt; i++)
{
plcDisconnectedErrMsgs.Add(new PlcDisconnectedErrMsg()
{
ErrCode = errCode + i,
Description = $"{GetPlcName(plcCnt, i, plcNames)} " + descrption
});
}
} }
#region 报警 #region 报警
public class ErrorAction public class ErrorAction
...@@ -53,7 +80,7 @@ namespace FLY.OBJComponents.Server ...@@ -53,7 +80,7 @@ namespace FLY.OBJComponents.Server
public class ErrorInfo public class ErrorInfo
{ {
public string property; public string property;
public byte code; public int code;
public string msg; public string msg;
} }
Dictionary<INotifyPropertyChanged, ErrorAction> obj_error = new Dictionary<INotifyPropertyChanged, ErrorAction>(); Dictionary<INotifyPropertyChanged, ErrorAction> obj_error = new Dictionary<INotifyPropertyChanged, ErrorAction>();
...@@ -113,62 +140,35 @@ namespace FLY.OBJComponents.Server ...@@ -113,62 +140,35 @@ namespace FLY.OBJComponents.Server
{ {
for (int i = 0; i < PLCos.PLCs.Count(); i++) for (int i = 0; i < PLCos.PLCs.Count(); i++)
{ {
bool b = !PLCos.PLCs[i].Client.IsConnected; int errcode = plcDisconnectedErrMsgs[i].ErrCode;
ERR_STATE state = b ? ERR_STATE.ON : ERR_STATE.OFF; string description = plcDisconnectedErrMsgs[i].Description;
ERRNO errno = PlcErrNos.Instance.ERRNO_PLC_DISCONNECTED; if (!PLCos.PLCs[i].Client.IsConnected)
UInt16 errcode = (UInt16)(errno.Code - i); {
string description = $"{GetPlcName(i)} " + errno.Descrption; mWarning.Add(errcode, description, canReset: false);
}
mWarning.Add(errcode, description, state); else {
mWarning.Remove(errcode);
}
} }
}, TimeSpan.FromSeconds(3), true, false, this, MARKNO_DELAY_ISCONNECTED, false); }, TimeSpan.FromSeconds(3), true, false, this, MARKNO_DELAY_ISCONNECTED, false);
//--------------------------------------------------------------------------------
//启动定时器,每1秒查报警,防止 以为报警复位了,但其实还在报警
//FObjBase.PollModule.Current.Poll_Config(PollModule.POLL_CONFIG.ADD,
// () =>
// {
// foreach (var objError in obj_error)
// {
// object sender = objError.Key;
// ErrorAction errorAction = objError.Value;
// foreach (var ei in errorAction.error_property)
// {
// //获取描述
// var type = sender.GetType();
// var property = type.GetProperty(ei.property);
// bool b = (bool)property.GetValue(sender, null);
// string desp = ei.msg;
// ERR_STATE state = b ? ERR_STATE.ON : ERR_STATE.OFF;
// byte errcode = ei.code;//每个报警必须不一样!!
// string description = desp;
// errorAction.action?.Invoke(ref description, errorAction.state);
// mWarning.Add(errcode, description, state);
// }
// }
// }, TimeSpan.FromSeconds(3));
} }
string GetPlcName(int index)
string GetPlcName(int plcCnt, int index, string[] plcNames)
{ {
if (PLCos.PLCs.Count() == 1) if (plcCnt == 1)
{ {
return plcNames[0]; return plcNames[0];
} }
//多个PLC //多个PLC
if (PLCos.PLCs.Count() != plcNames.Count()) if (plcCnt != plcNames.Count())
{ {
//没有定义全部名字 //没有定义全部名字
return $"{plcNames[0]} No.{index + 1}"; return $"{plcNames[0]} No.{index + 1}";
} }
return plcNames[index]; return plcNames[index];
} }
public void ResetError(INotifyPropertyChanged sender) public void ResetError(INotifyPropertyChanged sender)
...@@ -200,7 +200,7 @@ namespace FLY.OBJComponents.Server ...@@ -200,7 +200,7 @@ namespace FLY.OBJComponents.Server
var property = type.GetProperty(ei.property); var property = type.GetProperty(ei.property);
bool b = (bool)property.GetValue(sender, null); bool b = (bool)property.GetValue(sender, null);
string description = ei.msg; string description = ei.msg;
byte errcode = ei.code;//每个报警必须不一样!! int errcode = ei.code;//每个报警必须不一样!!
if (b) if (b)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment