Commit 2801cd82 authored by 潘栩锋's avatar 潘栩锋 🚴

Merge branch 'dev7.0-blowing' of…

Merge branch 'dev7.0-blowing' of http://private.flyautomation.net:82/panruising/thick_public into dev7.0-blowing
parents cbeff0c3 3fc76b07
......@@ -17,7 +17,6 @@ namespace FLY.OBJComponents.Server
const int MARKNO_DELAY_ISCONNECTED = 4;
#endregion
List<string> plcNames;
/// <summary>
/// 需要设置
/// </summary>
......@@ -26,21 +25,49 @@ namespace FLY.OBJComponents.Server
/// 报警系统
/// </summary>
WarningSystem2 mWarning;
public byte ErrCode=0;
public ErrorConf(PLCProxySystem PLCos, WarningSystem2 mWarning, string plcName)
/// <summary>
/// 报警码自动排号,再枚举IsError 属性,对应的异常会被设置为ErrCode, 然后ErrCode++
/// </summary>
public int ErrCode =0;
class PlcDisconnectedErrMsg
{
this.PLCos = PLCos;
this.mWarning = mWarning;
plcNames = new List<string>();
plcNames.Add(plcName);
public int ErrCode;
public string Description;
}
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)
{
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.mWarning = mWarning;
this.plcNames = new List<string>();
if (plcNames.All(s => !string.IsNullOrEmpty(s)))
this.plcNames.AddRange(plcNames);
//初始化 PLC连接断开的描述列表
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 报警
public class ErrorAction
......@@ -53,7 +80,7 @@ namespace FLY.OBJComponents.Server
public class ErrorInfo
{
public string property;
public byte code;
public int code;
public string msg;
}
Dictionary<INotifyPropertyChanged, ErrorAction> obj_error = new Dictionary<INotifyPropertyChanged, ErrorAction>();
......@@ -113,62 +140,35 @@ namespace FLY.OBJComponents.Server
{
for (int i = 0; i < PLCos.PLCs.Count(); i++)
{
bool b = !PLCos.PLCs[i].Client.IsConnected;
ERR_STATE state = b ? ERR_STATE.ON : ERR_STATE.OFF;
ERRNO errno = PlcErrNos.Instance.ERRNO_PLC_DISCONNECTED;
UInt16 errcode = (UInt16)(errno.Code - i);
string description = $"{GetPlcName(i)} " + errno.Descrption;
mWarning.Add(errcode, description, state);
int errcode = plcDisconnectedErrMsgs[i].ErrCode;
string description = plcDisconnectedErrMsgs[i].Description;
if (!PLCos.PLCs[i].Client.IsConnected)
{
mWarning.Add(errcode, description, canReset: false);
}
else {
mWarning.Remove(errcode);
}
}
}, 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];
}
//多个PLC
if (PLCos.PLCs.Count() != plcNames.Count())
if (plcCnt != plcNames.Count())
{
//没有定义全部名字
return $"{plcNames[0]} No.{index + 1}";
}
return plcNames[index];
}
public void ResetError(INotifyPropertyChanged sender)
......@@ -200,7 +200,7 @@ namespace FLY.OBJComponents.Server
var property = type.GetProperty(ei.property);
bool b = (bool)property.GetValue(sender, null);
string description = ei.msg;
byte errcode = ei.code;//每个报警必须不一样!!
int errcode = ei.code;//每个报警必须不一样!!
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