Commit 93e90cea LN

增加运行日志。

1 个父辈 8e2bada4
......@@ -65,6 +65,7 @@
<Compile Include="util\MyWebClient.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="util\RunLogUtil.cs" />
<Compile Include="util\ScanCodeManager.cs" />
<Compile Include="util\TcpClient.cs" />
<Compile Include="util\TcpServer.cs" />
......

using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace OnlineStore.Common
{
public class RunLogUtil
{
public static readonly ILog RunLog = LogManager.GetLogger("RunLog");
public static void ErrorLog(ErrorLog log)
{
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Error(jsonStr);
}
public static void MoveLog(MoveLog log)
{
if (log == null || (!log.IsValid()))
{
return;
}
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Info(jsonStr);
}
public static void InoutEndLog(InoutEndLog log)
{
if (log == null || (!log.IsValid()))
{
return;
}
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Info(jsonStr);
}
public static void AxisLog(AxisMoveLog log)
{
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Error(jsonStr);
}
}
public class BaseLog
{
[JsonProperty(Order = 0)]
public string Name { get; set; } = "三楼料仓";
[JsonProperty(Order = 1)]
public string DeviceName { get; set; } = "";
[JsonProperty(Order = 2)]
public string LogType { get; set; } = "";
[JsonProperty(Order = 3)]
public string StartTime { get; set; } = "";
[JsonProperty(Order = 4)]
public string EndTime { get; set; } = "";
[JsonProperty(Order = 5)]
public string timeSpan { get; set; } = "";
}
public class ErrorLog : BaseLog
{
public ErrorLog()
{
this.LogType = "Error";
}
public ErrorLog(string deviceName, string errType, string errMsg, DateTime startTime, DateTime endTime, string operType = "", string posid = "", string barcode = "")
{
if (errType == null) { errType = ""; }
if (errMsg == null) { errMsg = ""; }
if (operType == null) { operType = ""; }
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "Error";
this.DeviceName = deviceName.Trim();
this.ErrorType = errType.Trim();
this.ErrorMsg = errMsg.Trim();
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.OperateType = operType.Trim();
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(LogType) || string.IsNullOrEmpty(ErrorType) || string.IsNullOrEmpty(ErrorMsg))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string ErrorType { get; set; } = "";
[JsonProperty(Order = 12)]
public string ErrorMsg { get; set; } = "";
[JsonProperty(Order = 13)]
public string OperateType { get; set; } = "";
[JsonProperty(Order = 14)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 15)]
public string Barcode { get; set; } = "";
}
public class MoveLog : BaseLog
{
public MoveLog()
{
this.LogType = "Running";
}
public MoveLog(string deviceName, string moveType, string moveMsg, DateTime startTime, DateTime endTime, string posid = "", string barcode = "")
{
if (moveMsg == null) { moveMsg = ""; }
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "Running";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.MoveType = moveType.Trim();
this.MoveMsg = moveMsg.Trim();
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(LogType) || string.IsNullOrEmpty(MoveType) || string.IsNullOrEmpty(MoveMsg))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string MoveType { get; set; } = "";
[JsonProperty(Order = 12)]
public string MoveMsg { get; set; } = "";
[JsonProperty(Order = 13)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 14)]
public string Barcode { get; set; } = "";
}
public class InoutEndLog : BaseLog
{
public InoutEndLog()
{
this.LogType = "InoutEnd";
}
public InoutEndLog(string deviceName, string moveType, DateTime startTime, DateTime endTime, string posid = "", string barcode = "")
{
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "InoutEnd";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.MoveType = moveType.Trim();
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || string.IsNullOrEmpty(MoveType))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string MoveType { get; set; } = "";
[JsonProperty(Order = 12)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 13)]
public string Barcode { get; set; } = "";
}
public class AxisMoveLog : BaseLog
{
public AxisMoveLog()
{
this.LogType = "Axis";
}
public AxisMoveLog(string deviceName, string axisName, string moveType, int targetP, int speed, DateTime startTime, DateTime endTime, string posid = "", string barcode = "")
{
if (moveType == null) { moveType = ""; }
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "Axis";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.MoveType = moveType.Trim();
this.AxisName = axisName;
this.TargetPos = targetP;
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
this.Speed = speed;
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || string.IsNullOrEmpty(MoveType))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string AxisName { get; set; } = "";
[JsonProperty(Order = 12)]
public string MoveType { get; set; } = "";
[JsonProperty(Order = 13)]
public int TargetPos { get; set; } = 0;
[JsonProperty(Order = 14)]
public int Speed { get; set; }
[JsonProperty(Order = 15)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 16)]
public string Barcode { get; set; } = "";
}
}
......@@ -25,7 +25,7 @@ namespace OnlineStore.DeviceLibrary
toolTimer.Elapsed += ToolTimer_Elapsed;
this.box = box;
LogName = box.Name + "校准点位 ";
MoveInfo = new StoreMoveInfo(box.DeviceID);
MoveInfo = new StoreMoveInfo(box.DeviceID,"点位校准");
MoveInfo.NextMoveStep( StoreMoveStep.Wait);
}
......
......@@ -36,6 +36,15 @@ namespace OnlineStore.DeviceLibrary
public BoxBean(BoxConfig config)
{
this.DeviceID = config.DeviceID;
this.baseConfig = config;
this.Config = config;
this.CID = config.CID;
//添加调试
IsDebug = config.ISDebug.Equals(1);
UseCompress_Axis = true;
Name = ("左侧BOX_" + config.GetStoreId() + " ").ToUpper();
Init();
serverConnectTimer = new System.Timers.Timer();
serverConnectTimer.Interval = 1000;
......@@ -54,15 +63,6 @@ namespace OnlineStore.DeviceLibrary
readDITimer.Enabled = false;
readDITimer.Elapsed += ReadDITimer_Elapsed;
this.DeviceID = config.DeviceID;
this.baseConfig = config;
this.Config = config;
this.CID = config.CID;
//添加调试
IsDebug = config.ISDebug.Equals(1);
UseCompress_Axis = true;
Name = ("左侧BOX_" + config.GetStoreId() + " ").ToUpper();
if (config.DeviceID.Equals(2))
{
Name = ("右侧BOX_" + config.GetStoreId() + " ").ToUpper();
......@@ -239,7 +239,7 @@ namespace OnlineStore.DeviceLibrary
{
isNoAirCheck = false;
isInSuddenDown = false;
WarnMsg = "";
SetWarnMsg();
CurrInOutACount = 0;
CurrInOutCount = 0;
......@@ -289,7 +289,7 @@ namespace OnlineStore.DeviceLibrary
storeRunStatus = StoreRunStatus.Reset;
storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(StoreMoveType.StoreReset);
WarnMsg = "";
SetWarnMsg();
if (!OpenAllAxis(true))
{
......@@ -382,7 +382,7 @@ namespace OnlineStore.DeviceLibrary
storeStatus = StoreStatus.StoreOnline;
if (alarmType.Equals(StoreAlarmType.None))
{
WarnMsg = "";
SetWarnMsg();
}
break;
......@@ -411,7 +411,7 @@ namespace OnlineStore.DeviceLibrary
storeRunStatus = StoreRunStatus.Runing;
if (alarmType.Equals(StoreAlarmType.None))
{
WarnMsg = "";
SetWarnMsg();
}
break;
......@@ -508,8 +508,8 @@ namespace OnlineStore.DeviceLibrary
{
AxisManager.instance.ServoOff(axis.DeviceName, axis.GetAxisValue());
int alarmCode = GetAlarmCodeByAxis(axis);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
LogInfo( WarnMsg);
string msg = Name + "打开轴" + axis.Explain + "失败 ";
SetWarnMsg(msg, axis.Explain+"_轴报警");
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
......@@ -554,7 +554,7 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun()
{
WarnMsg = "";
SetWarnMsg();
autoNext = false;
IoCheckTimer.Enabled = false;
serverConnectTimer.Enabled = false;
......@@ -650,7 +650,7 @@ namespace OnlineStore.DeviceLibrary
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,报警急停");
//WarnMsg = Name + "收到急停信号,报警急停";
SetWarnMsg( "收到急停信号,报警急停");
SetWarnMsg( "收到急停信号,报警急停","报警急停");
//报警时会关闭所有轴
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
}
......@@ -707,7 +707,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > StoreManager.Config.AirCheckSeconds)
{
SetWarnMsg( "未检测到气压信号");
SetWarnMsg( "未检测到气压信号", "未检测到气压信号");
preAirValue = IO_VALUE.LOW;
LogInfo( "已持续【" + FormUtil.GetSpanStr(span) + "】未检测到气压信号,报警");
Alarm(StoreAlarmType.NoAirCheck, "2", WarnMsg, StoreMoveType.None);
......@@ -857,7 +857,7 @@ namespace OnlineStore.DeviceLibrary
{
LogInfo( "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
alarmType = StoreAlarmType.None;
WarnMsg = "";
SetWarnMsg();
}
}
}
......@@ -957,7 +957,8 @@ namespace OnlineStore.DeviceLibrary
if (alarmIo == 1)
{
WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警";
string msg = Name + " 运动轴" + axisInfo.Explain + "报警";
SetWarnMsg(msg, axisInfo.Explain + "_轴报警");
info.AlarmIoValue = alarmIo;
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo).ToString(), WarnMsg, StoreMoveType.None);
isInAlarm = true;
......@@ -1271,7 +1272,7 @@ namespace OnlineStore.DeviceLibrary
}
}
CodeMsg = "";
//WarnMsg = "";
//SetWarnMsg();
//状态
boxStatus.status = (int)storeStatus;
if (IsDebug)
......
......@@ -164,7 +164,10 @@ namespace OnlineStore.DeviceLibrary
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
if (wait.IsEnd)
{
RunLogUtil.AxisLog(new AxisMoveLog(Name, wait.AxisInfo.Explain, "回原点", 0, wait.AxisInfo.HomeHighSpeed, MoveInfo.LastSetpTime, DateTime.Now, MoveInfo.MoveParam.PosInfo.PosId, MoveInfo.MoveParam.PosInfo.barcode));
}
if (!wait.IsEnd && (String.IsNullOrEmpty(msg)))
{
//如果原点没完成,且原点亮超过5秒,需要报警
......@@ -188,11 +191,16 @@ namespace OnlineStore.DeviceLibrary
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
if (wait.IsEnd)
{
RunLogUtil.AxisLog(new AxisMoveLog(Name, wait.AxisInfo.Explain, "绝对运动", wait.TargetPosition, wait.TargetSpeed, MoveInfo.LastSetpTime, DateTime.Now, MoveInfo.MoveParam.PosInfo.PosId, MoveInfo.MoveParam.PosInfo.barcode));
}
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
//WarnMsg = msg;
SetWarnMsg(msg, MoveInfo.GetStepDes() + "_轴运动报警", MoveInfo);
Alarm(StoreAlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, MoveInfo.MoveType);
break;
}
......@@ -216,10 +224,11 @@ namespace OnlineStore.DeviceLibrary
if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
{
ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待" + io.DisplayStr + "=" + wait.IoValue + "超时 ";
string msg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待" + io.DisplayStr + "=" + wait.IoValue + "超时 ";
SetWarnMsg(msg, MoveInfo.GetStepDes() + "_超时报警", MoveInfo);
if (WarnMsg.Contains("CheckPos") || WarnMsg.Contains("X03_点检"))
{
WarnMsg = "";
SetWarnMsg();;
break;
}
......@@ -305,14 +314,16 @@ namespace OnlineStore.DeviceLibrary
if (isOk)
{
MoveInfo.EndStepWait();
ClearStepAlarm(MoveInfo.GetStepDes());
}
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
{
WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待超时 [" + NotOkMsg
string msg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待超时 [" + NotOkMsg
+ "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
SetWarnMsg(msg, MoveInfo.GetStepDes() + "_超时报警", MoveInfo);
if (WarnMsg.Contains("CheckPos") || WarnMsg.Contains("X03_点检"))
{
WarnMsg = "";
SetWarnMsg();;
return;
}
......@@ -596,6 +607,8 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - startInStoreTime;
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.PosId : "";
LogInfo( " 【" + posId + "】 整个入库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
RunLogUtil.InoutEndLog(new InoutEndLog(Name, "入库", startInStoreTime, DateTime.Now, MoveInfo.MoveParam.PosInfo.PosId, MoveInfo.MoveParam.PosInfo.barcode));
MoveInfo.EndMove();
storeRunStatus = StoreRunStatus.Runing;
//设备连接,入库后,BOX恢复原始状态
......@@ -941,6 +954,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - startOutStoreTime;
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.PosId : "";
RunLogUtil.InoutEndLog(new InoutEndLog(Name, "出库", startOutStoreTime, DateTime.Now, posId, MoveInfo.MoveParam.PosInfo.barcode));
storeStatus = StoreStatus.StoreOnline;
LogInfo( " 【" + posId + "】 整个出库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
MoveInfo.EndMove();
......
......@@ -43,7 +43,7 @@ namespace OnlineStore.DeviceLibrary
this.Config = lineConfig;
this.DeviceID = lineConfig.DeviceID;
MoveInfo = new StoreMoveInfo(DeviceID);
MoveInfo = new StoreMoveInfo(DeviceID,Name);
Name = (" Store_" + Config.CID + " ").ToUpper();
List<string> ioList = new List<string>();
......@@ -122,7 +122,7 @@ namespace OnlineStore.DeviceLibrary
isInSuddenDown = false;
isNoAirCheck = false;
alarmType = StoreAlarmType.None;
WarnMsg = "";
SetWarnMsg();
foreach (BoxBean box in this.BoxMap.Values)
{
......@@ -187,7 +187,7 @@ namespace OnlineStore.DeviceLibrary
isInSuddenDown = false;
isNoAirCheck = false;
alarmType = StoreAlarmType.None;
WarnMsg = "";
SetWarnMsg();
foreach (BoxBean equip in BoxMap.Values)
{
......
......@@ -25,11 +25,12 @@ namespace OnlineStore.DeviceLibrary
private static bool isInit = false;
public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals("");
public static Dictionary<int, BaseConfig> allConfigMap = new Dictionary<int, BaseConfig>();
public static Dictionary<string, string> StepDesMap = new Dictionary<string, string>();
public StoreManager()
{
}
#region 配置文件加载更新
public static void CheckEnum(Type type)
public static void CheckEnum(Type type, bool isStep=false)
{
if (type.IsEnum)
{
......@@ -44,6 +45,12 @@ namespace OnlineStore.DeviceLibrary
break;
}
valueList.Add(item);
if (isStep)
{
StoreMoveStep en = (StoreMoveStep)item;
string des = EnumDesHelper.GetStepDes(en);
StepDesMap.Add(en.ToString(), des);
}
}
}
}
......@@ -62,7 +69,7 @@ namespace OnlineStore.DeviceLibrary
{
IsConnectServer = false;
}
CheckEnum(typeof(StoreMoveStep));
CheckEnum(typeof(StoreMoveStep),true);
CheckEnum(typeof(StoreStatus));
CheckEnum(typeof(StoreRunStatus));
......
......@@ -291,7 +291,7 @@ namespace OnlineStore.DeviceLibrary
{
if (!isInit)
{
MoveInfo = new StoreMoveInfo(DeviceID);
MoveInfo = new StoreMoveInfo(DeviceID,Name);
mainTimer = new System.Timers.Timer();
mainTimer.Enabled = false;
......@@ -439,19 +439,41 @@ namespace OnlineStore.DeviceLibrary
{
return IOManager.IOValue(IoType, baseConfig.DeviceID);
}
protected void SetWarnMsg(string msg)
public bool IsDoValue(string ioType, IO_VALUE ioValue)
{
return IOValue(ioType).Equals(ioValue);
}
public void LogInfo(string logInfo)
{
LogUtil.info(Name + logInfo);
}
private WarnParam warnParam = new WarnParam();
/// <summary>
/// 设置报警消息,报警类型,清除报警时记录日志
/// </summary>
/// <param name="msg"></param>
/// <param name="logtype"></param>
/// <param name="logseconds"></param>
public void SetWarnMsg(string msg = "", string alarmType = "", StoreMoveInfo moveInfo = null, int logseconds = 10)
{
if (String.IsNullOrEmpty(WarnMsg).Equals(false))
try
{
int logtype = 801;
if (moveInfo != null)
{
logtype = DeviceID * 10000 + (int)moveInfo.MoveStep;
}
if (String.IsNullOrEmpty(msg).Equals(false))
{
if (WarnMsg.Equals(msg))
if (WarnMsg.Equals(msg) || alarmType.Equals(warnParam.AlarmType))
{
if (msg.StartsWith(Name))
{
LogUtil.error(msg, 105);
LogUtil.error(msg, logtype, logseconds);
}
else
{
LogUtil.error(Name + msg, 105);
LogUtil.error(Name + msg, logtype, logseconds);
}
}
else
......@@ -462,22 +484,96 @@ namespace OnlineStore.DeviceLibrary
}
else
{
msg = Name + msg;
LogUtil.error( msg);
LogUtil.error(Name + msg);
}
}
}
if (!warnParam.AlarmType.Equals(alarmType))
{
//报警类型不一致,若之前不是空,记录日志
if (!String.IsNullOrEmpty(warnParam.AlarmType))
{
RunLogUtil.ErrorLog(new ErrorLog(Name, warnParam.AlarmType, WarnMsg, warnParam.StartTime, DateTime.Now, warnParam.OperteType, warnParam.PosId, warnParam.Barcode));
}
//更新开始时间
warnParam.StartTime = DateTime.Now;
if (moveInfo != null)
{
warnParam.PosId = moveInfo.MoveParam?.PosInfo?.PosId;
warnParam.Barcode = moveInfo.MoveParam?.PosInfo?.barcode;
warnParam.OperteType = moveInfo.MoveType.ToString();
}
else
{
warnParam.PosId = "";
warnParam.Barcode = "";
warnParam.OperteType = "";
}
}
}
catch (Exception ex)
{
LogUtil.error("SetWarnMsg Error: " + ex.ToString());
}
WarnMsg = msg;
warnParam.AlarmType = alarmType;
}
public bool IsDoValue(string ioType, IO_VALUE ioValue)
protected void ClearStepAlarm(string stepDes)
{
return IOValue(ioType).Equals(ioValue);
if (isInSuddenDown || isNoAirCheck)
{
return;
}
public void LogInfo(string logInfo)
if (String.IsNullOrEmpty(WarnMsg).Equals(false) && String.IsNullOrEmpty(warnParam.AlarmType).Equals(false))
{
LogUtil.info(Name + logInfo);
if (alarmType.Equals(StoreAlarmType.IoSingleTimeOut))
{
string alarmTypeStr = stepDes + "_超时报警";
if (warnParam.AlarmType.Equals(alarmTypeStr))
{
LogUtil.info(Name + $"步骤{stepDes}结束,清理【{ WarnMsg }】 ");
alarmType = StoreAlarmType.None;
SetWarnMsg("");
}
}
else if (alarmType.Equals(StoreAlarmType.AxisMoveError))
{
string alarmTypeStr = stepDes + "_轴运动报警";
if (warnParam.AlarmType.Equals(alarmTypeStr))
{
LogUtil.info(Name + $"步骤{stepDes}结束,清理【{ WarnMsg }】 ");
alarmType = StoreAlarmType.None;
SetWarnMsg("");
}
}
}
}
}
public class WarnParam
{
public WarnParam()
{
}
public WarnParam(string alarmType, DateTime startTime, string operType, string posId, string barcode)
{
this.AlarmType = alarmType;
this.StartTime = startTime;
this.OperteType = operType;
this.PosId = posId;
this.Barcode = barcode;
}
public string AlarmType = "";
public DateTime StartTime = DateTime.Now;
public string OperteType = "";
public string PosId = "";
public string Barcode = "";
}
}
......@@ -3,6 +3,7 @@ using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
......@@ -14,12 +15,14 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
public class StoreMoveInfo
{
private string Name;
/// <summary>
/// 超时时间
/// </summary>
public int TimeOutSeconds = 60;
public StoreMoveInfo(int storeId)
public StoreMoveInfo(int storeId,string name)
{
this.Name = name;
moveType = StoreMoveType.None;
MoveParam = new InOutParam();
......@@ -96,6 +99,7 @@ namespace OnlineStore.DeviceLibrary
public void NextMoveStep(StoreMoveStep step)
{
stepMoveLog();
PreMoveStep = moveStep;
moveStep = step;
LastSetpTime = DateTime.Now;
......@@ -131,6 +135,7 @@ namespace OnlineStore.DeviceLibrary
}
public void EndMove()
{
stepMoveLog();
this.moveType = StoreMoveType.None;
this.MoveParam = null;
moveStep = StoreMoveStep.Wait;
......@@ -153,8 +158,73 @@ namespace OnlineStore.DeviceLibrary
moveStep = PreMoveStep;
IsInWait = false;
}
private void stepMoveLog()
{
try
{
RunLogUtil.MoveLog(new MoveLog(Name, GetMoveType(), GetStepDes(), LastSetpTime, DateTime.Now, MoveParam.PosInfo?.PosId, MoveParam.PosInfo?.barcode));
}
catch (Exception ex)
{
}
}
public string GetStepDes()
{
string currName = moveStep.ToString();
try
{
if (StoreManager.StepDesMap.ContainsKey(currName))
{
return StoreManager.StepDesMap[currName];
}
}
catch (Exception ex)
{
LogUtil.error("GetStepDes 出错:" + ex.ToString());
}
return currName;
}
public string GetMoveType()
{
switch (moveType)
{
case StoreMoveType.InStore:
return "入料";
break;
case StoreMoveType.OutStore:
return "出料";
break;
case StoreMoveType.StoreReset:
return "复位";
break;
case StoreMoveType.ReturnHome:
return "回原";
break;
}
return "";
}
}
public static class EnumDesHelper
{
public static string GetStepDes(this Enum val)
{
var type = val.GetType();
var memberInfo = type.GetMember(val.ToString());
var attributes = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes == null || attributes.Length != 1)
{
//如果没有定义描述,就把当前枚举值的对应名称返回
return val.ToString();
}
return (attributes.Single() as DescriptionAttribute).Description;
}
}
public class WaitResultInfo
{
private WaitResultInfo()
......
......@@ -66,14 +66,32 @@
<conversionPattern value="[%date][%t]%-5p %m%n" />
</layout>
</appender>
<appender name="RunLog" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="logs/log/RunLog-%property{fname}.log" />
<param name="Encoding" value="UTF-8" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value=" %m%n" />
</layout>
</appender>
<logger name="InOutStore">
<level value="Info" />
<appender-ref ref="InOutStore" />
</logger>
<root>
<!--<root>
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
</root>-->
<logger name="RollingLogFileAppender">
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</logger>
<logger name="RunLog">
<level value="Info" />
<appender-ref ref="RunLog" />
</logger>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!