Commit 93e90cea LN

增加运行日志。

1 个父辈 8e2bada4
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
<Compile Include="util\MyWebClient.cs"> <Compile Include="util\MyWebClient.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="util\RunLogUtil.cs" />
<Compile Include="util\ScanCodeManager.cs" /> <Compile Include="util\ScanCodeManager.cs" />
<Compile Include="util\TcpClient.cs" /> <Compile Include="util\TcpClient.cs" />
<Compile Include="util\TcpServer.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 ...@@ -25,7 +25,7 @@ namespace OnlineStore.DeviceLibrary
toolTimer.Elapsed += ToolTimer_Elapsed; toolTimer.Elapsed += ToolTimer_Elapsed;
this.box = box; this.box = box;
LogName = box.Name + "校准点位 "; LogName = box.Name + "校准点位 ";
MoveInfo = new StoreMoveInfo(box.DeviceID); MoveInfo = new StoreMoveInfo(box.DeviceID,"点位校准");
MoveInfo.NextMoveStep( StoreMoveStep.Wait); MoveInfo.NextMoveStep( StoreMoveStep.Wait);
} }
......
...@@ -36,6 +36,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -36,6 +36,15 @@ namespace OnlineStore.DeviceLibrary
public BoxBean(BoxConfig config) 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(); Init();
serverConnectTimer = new System.Timers.Timer(); serverConnectTimer = new System.Timers.Timer();
serverConnectTimer.Interval = 1000; serverConnectTimer.Interval = 1000;
...@@ -54,15 +63,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -54,15 +63,6 @@ namespace OnlineStore.DeviceLibrary
readDITimer.Enabled = false; readDITimer.Enabled = false;
readDITimer.Elapsed += ReadDITimer_Elapsed; 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)) if (config.DeviceID.Equals(2))
{ {
Name = ("右侧BOX_" + config.GetStoreId() + " ").ToUpper(); Name = ("右侧BOX_" + config.GetStoreId() + " ").ToUpper();
...@@ -239,7 +239,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -239,7 +239,7 @@ namespace OnlineStore.DeviceLibrary
{ {
isNoAirCheck = false; isNoAirCheck = false;
isInSuddenDown = false; isInSuddenDown = false;
WarnMsg = ""; SetWarnMsg();
CurrInOutACount = 0; CurrInOutACount = 0;
CurrInOutCount = 0; CurrInOutCount = 0;
...@@ -289,7 +289,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -289,7 +289,7 @@ namespace OnlineStore.DeviceLibrary
storeRunStatus = StoreRunStatus.Reset; storeRunStatus = StoreRunStatus.Reset;
storeStatus = StoreStatus.ResetMove; storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(StoreMoveType.StoreReset); MoveInfo.NewMove(StoreMoveType.StoreReset);
WarnMsg = ""; SetWarnMsg();
if (!OpenAllAxis(true)) if (!OpenAllAxis(true))
{ {
...@@ -382,7 +382,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -382,7 +382,7 @@ namespace OnlineStore.DeviceLibrary
storeStatus = StoreStatus.StoreOnline; storeStatus = StoreStatus.StoreOnline;
if (alarmType.Equals(StoreAlarmType.None)) if (alarmType.Equals(StoreAlarmType.None))
{ {
WarnMsg = ""; SetWarnMsg();
} }
break; break;
...@@ -411,7 +411,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -411,7 +411,7 @@ namespace OnlineStore.DeviceLibrary
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
if (alarmType.Equals(StoreAlarmType.None)) if (alarmType.Equals(StoreAlarmType.None))
{ {
WarnMsg = ""; SetWarnMsg();
} }
break; break;
...@@ -508,8 +508,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -508,8 +508,8 @@ namespace OnlineStore.DeviceLibrary
{ {
AxisManager.instance.ServoOff(axis.DeviceName, axis.GetAxisValue()); AxisManager.instance.ServoOff(axis.DeviceName, axis.GetAxisValue());
int alarmCode = GetAlarmCodeByAxis(axis); int alarmCode = GetAlarmCodeByAxis(axis);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 "; string msg = Name + "打开轴" + axis.Explain + "失败 ";
LogInfo( WarnMsg); SetWarnMsg(msg, axis.Explain+"_轴报警");
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType); Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType);
return false; return false;
} }
...@@ -554,7 +554,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -554,7 +554,7 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun() public override void StopRun()
{ {
WarnMsg = ""; SetWarnMsg();
autoNext = false; autoNext = false;
IoCheckTimer.Enabled = false; IoCheckTimer.Enabled = false;
serverConnectTimer.Enabled = false; serverConnectTimer.Enabled = false;
...@@ -650,7 +650,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -650,7 +650,7 @@ namespace OnlineStore.DeviceLibrary
isInSuddenDown = true; isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,报警急停"); LogUtil.error(Name + "收到急停信号,报警急停");
//WarnMsg = Name + "收到急停信号,报警急停"; //WarnMsg = Name + "收到急停信号,报警急停";
SetWarnMsg( "收到急停信号,报警急停"); SetWarnMsg( "收到急停信号,报警急停","报警急停");
//报警时会关闭所有轴 //报警时会关闭所有轴
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None); Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
} }
...@@ -707,7 +707,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -707,7 +707,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - lastAirCloseTime; TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > StoreManager.Config.AirCheckSeconds) if (span.TotalSeconds > StoreManager.Config.AirCheckSeconds)
{ {
SetWarnMsg( "未检测到气压信号"); SetWarnMsg( "未检测到气压信号", "未检测到气压信号");
preAirValue = IO_VALUE.LOW; preAirValue = IO_VALUE.LOW;
LogInfo( "已持续【" + FormUtil.GetSpanStr(span) + "】未检测到气压信号,报警"); LogInfo( "已持续【" + FormUtil.GetSpanStr(span) + "】未检测到气压信号,报警");
Alarm(StoreAlarmType.NoAirCheck, "2", WarnMsg, StoreMoveType.None); Alarm(StoreAlarmType.NoAirCheck, "2", WarnMsg, StoreMoveType.None);
...@@ -857,7 +857,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -857,7 +857,7 @@ namespace OnlineStore.DeviceLibrary
{ {
LogInfo( "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!"); LogInfo( "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
alarmType = StoreAlarmType.None; alarmType = StoreAlarmType.None;
WarnMsg = ""; SetWarnMsg();
} }
} }
} }
...@@ -957,7 +957,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -957,7 +957,8 @@ namespace OnlineStore.DeviceLibrary
if (alarmIo == 1) if (alarmIo == 1)
{ {
WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警"; string msg = Name + " 运动轴" + axisInfo.Explain + "报警";
SetWarnMsg(msg, axisInfo.Explain + "_轴报警");
info.AlarmIoValue = alarmIo; info.AlarmIoValue = alarmIo;
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo).ToString(), WarnMsg, StoreMoveType.None); Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo).ToString(), WarnMsg, StoreMoveType.None);
isInAlarm = true; isInAlarm = true;
...@@ -1271,7 +1272,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1271,7 +1272,7 @@ namespace OnlineStore.DeviceLibrary
} }
} }
CodeMsg = ""; CodeMsg = "";
//WarnMsg = ""; //SetWarnMsg();
//状态 //状态
boxStatus.status = (int)storeStatus; boxStatus.status = (int)storeStatus;
if (IsDebug) if (IsDebug)
......
...@@ -164,7 +164,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -164,7 +164,10 @@ namespace OnlineStore.DeviceLibrary
if (wait.IsHomeMove) if (wait.IsHomeMove)
{ {
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg); 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))) if (!wait.IsEnd && (String.IsNullOrEmpty(msg)))
{ {
//如果原点没完成,且原点亮超过5秒,需要报警 //如果原点没完成,且原点亮超过5秒,需要报警
...@@ -188,11 +191,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -188,11 +191,16 @@ namespace OnlineStore.DeviceLibrary
else else
{ {
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg); 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("")) if (!msg.Equals(""))
{ {
isOk = false; isOk = false;
WarnMsg = msg; //WarnMsg = msg;
SetWarnMsg(msg, MoveInfo.GetStepDes() + "_轴运动报警", MoveInfo);
Alarm(StoreAlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, MoveInfo.MoveType); Alarm(StoreAlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, MoveInfo.MoveType);
break; break;
} }
...@@ -216,10 +224,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -216,10 +224,11 @@ namespace OnlineStore.DeviceLibrary
if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs) if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
{ {
ConfigIO io = Config.getWaitIO(wait.IoType); 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_点检")) if (WarnMsg.Contains("CheckPos") || WarnMsg.Contains("X03_点检"))
{ {
WarnMsg = ""; SetWarnMsg();;
break; break;
} }
...@@ -305,14 +314,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -305,14 +314,16 @@ namespace OnlineStore.DeviceLibrary
if (isOk) if (isOk)
{ {
MoveInfo.EndStepWait(); MoveInfo.EndStepWait();
ClearStepAlarm(MoveInfo.GetStepDes());
} }
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds) 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) + "]秒"; + "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
SetWarnMsg(msg, MoveInfo.GetStepDes() + "_超时报警", MoveInfo);
if (WarnMsg.Contains("CheckPos") || WarnMsg.Contains("X03_点检")) if (WarnMsg.Contains("CheckPos") || WarnMsg.Contains("X03_点检"))
{ {
WarnMsg = ""; SetWarnMsg();;
return; return;
} }
...@@ -596,6 +607,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -596,6 +607,8 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - startInStoreTime; TimeSpan span = DateTime.Now - startInStoreTime;
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.PosId : ""; string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.PosId : "";
LogInfo( " 【" + posId + "】 整个入库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!"); LogInfo( " 【" + posId + "】 整个入库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
RunLogUtil.InoutEndLog(new InoutEndLog(Name, "入库", startInStoreTime, DateTime.Now, MoveInfo.MoveParam.PosInfo.PosId, MoveInfo.MoveParam.PosInfo.barcode));
MoveInfo.EndMove(); MoveInfo.EndMove();
storeRunStatus = StoreRunStatus.Runing; storeRunStatus = StoreRunStatus.Runing;
//设备连接,入库后,BOX恢复原始状态 //设备连接,入库后,BOX恢复原始状态
...@@ -941,6 +954,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -941,6 +954,7 @@ namespace OnlineStore.DeviceLibrary
TimeSpan span = DateTime.Now - startOutStoreTime; TimeSpan span = DateTime.Now - startOutStoreTime;
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosInfo.PosId : ""; 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; storeStatus = StoreStatus.StoreOnline;
LogInfo( " 【" + posId + "】 整个出库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!"); LogInfo( " 【" + posId + "】 整个出库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
MoveInfo.EndMove(); MoveInfo.EndMove();
......
...@@ -43,7 +43,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -43,7 +43,7 @@ namespace OnlineStore.DeviceLibrary
this.Config = lineConfig; this.Config = lineConfig;
this.DeviceID = lineConfig.DeviceID; this.DeviceID = lineConfig.DeviceID;
MoveInfo = new StoreMoveInfo(DeviceID); MoveInfo = new StoreMoveInfo(DeviceID,Name);
Name = (" Store_" + Config.CID + " ").ToUpper(); Name = (" Store_" + Config.CID + " ").ToUpper();
List<string> ioList = new List<string>(); List<string> ioList = new List<string>();
...@@ -122,7 +122,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -122,7 +122,7 @@ namespace OnlineStore.DeviceLibrary
isInSuddenDown = false; isInSuddenDown = false;
isNoAirCheck = false; isNoAirCheck = false;
alarmType = StoreAlarmType.None; alarmType = StoreAlarmType.None;
WarnMsg = ""; SetWarnMsg();
foreach (BoxBean box in this.BoxMap.Values) foreach (BoxBean box in this.BoxMap.Values)
{ {
...@@ -187,7 +187,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -187,7 +187,7 @@ namespace OnlineStore.DeviceLibrary
isInSuddenDown = false; isInSuddenDown = false;
isNoAirCheck = false; isNoAirCheck = false;
alarmType = StoreAlarmType.None; alarmType = StoreAlarmType.None;
WarnMsg = ""; SetWarnMsg();
foreach (BoxBean equip in BoxMap.Values) foreach (BoxBean equip in BoxMap.Values)
{ {
......
...@@ -25,11 +25,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -25,11 +25,12 @@ namespace OnlineStore.DeviceLibrary
private static bool isInit = false; private static bool isInit = false;
public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals(""); public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals("");
public static Dictionary<int, BaseConfig> allConfigMap = new Dictionary<int, BaseConfig>(); public static Dictionary<int, BaseConfig> allConfigMap = new Dictionary<int, BaseConfig>();
public static Dictionary<string, string> StepDesMap = new Dictionary<string, string>();
public StoreManager() public StoreManager()
{ {
} }
#region 配置文件加载更新 #region 配置文件加载更新
public static void CheckEnum(Type type) public static void CheckEnum(Type type, bool isStep=false)
{ {
if (type.IsEnum) if (type.IsEnum)
{ {
...@@ -44,6 +45,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -44,6 +45,12 @@ namespace OnlineStore.DeviceLibrary
break; break;
} }
valueList.Add(item); 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 ...@@ -62,7 +69,7 @@ namespace OnlineStore.DeviceLibrary
{ {
IsConnectServer = false; IsConnectServer = false;
} }
CheckEnum(typeof(StoreMoveStep)); CheckEnum(typeof(StoreMoveStep),true);
CheckEnum(typeof(StoreStatus)); CheckEnum(typeof(StoreStatus));
CheckEnum(typeof(StoreRunStatus)); CheckEnum(typeof(StoreRunStatus));
......
...@@ -291,7 +291,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -291,7 +291,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!isInit) if (!isInit)
{ {
MoveInfo = new StoreMoveInfo(DeviceID); MoveInfo = new StoreMoveInfo(DeviceID,Name);
mainTimer = new System.Timers.Timer(); mainTimer = new System.Timers.Timer();
mainTimer.Enabled = false; mainTimer.Enabled = false;
...@@ -439,19 +439,41 @@ namespace OnlineStore.DeviceLibrary ...@@ -439,19 +439,41 @@ namespace OnlineStore.DeviceLibrary
{ {
return IOManager.IOValue(IoType, baseConfig.DeviceID); 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)) if (msg.StartsWith(Name))
{ {
LogUtil.error(msg, 105); LogUtil.error(msg, logtype, logseconds);
} }
else else
{ {
LogUtil.error(Name + msg, 105); LogUtil.error(Name + msg, logtype, logseconds);
} }
} }
else else
...@@ -462,22 +484,96 @@ namespace OnlineStore.DeviceLibrary ...@@ -462,22 +484,96 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
msg = Name + msg; LogUtil.error(Name + msg);
LogUtil.error( 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; 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; ...@@ -3,6 +3,7 @@ using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -14,12 +15,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -14,12 +15,14 @@ namespace OnlineStore.DeviceLibrary
/// </summary> /// </summary>
public class StoreMoveInfo public class StoreMoveInfo
{ {
private string Name;
/// <summary> /// <summary>
/// 超时时间 /// 超时时间
/// </summary> /// </summary>
public int TimeOutSeconds = 60; public int TimeOutSeconds = 60;
public StoreMoveInfo(int storeId) public StoreMoveInfo(int storeId,string name)
{ {
this.Name = name;
moveType = StoreMoveType.None; moveType = StoreMoveType.None;
MoveParam = new InOutParam(); MoveParam = new InOutParam();
...@@ -96,6 +99,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -96,6 +99,7 @@ namespace OnlineStore.DeviceLibrary
public void NextMoveStep(StoreMoveStep step) public void NextMoveStep(StoreMoveStep step)
{ {
stepMoveLog();
PreMoveStep = moveStep; PreMoveStep = moveStep;
moveStep = step; moveStep = step;
LastSetpTime = DateTime.Now; LastSetpTime = DateTime.Now;
...@@ -131,6 +135,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -131,6 +135,7 @@ namespace OnlineStore.DeviceLibrary
} }
public void EndMove() public void EndMove()
{ {
stepMoveLog();
this.moveType = StoreMoveType.None; this.moveType = StoreMoveType.None;
this.MoveParam = null; this.MoveParam = null;
moveStep = StoreMoveStep.Wait; moveStep = StoreMoveStep.Wait;
...@@ -153,8 +158,73 @@ namespace OnlineStore.DeviceLibrary ...@@ -153,8 +158,73 @@ namespace OnlineStore.DeviceLibrary
moveStep = PreMoveStep; moveStep = PreMoveStep;
IsInWait = false; 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 public class WaitResultInfo
{ {
private WaitResultInfo() private WaitResultInfo()
......
...@@ -66,14 +66,32 @@ ...@@ -66,14 +66,32 @@
<conversionPattern value="[%date][%t]%-5p %m%n" /> <conversionPattern value="[%date][%t]%-5p %m%n" />
</layout> </layout>
</appender> </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"> <logger name="InOutStore">
<level value="Info" /> <level value="Info" />
<appender-ref ref="InOutStore" /> <appender-ref ref="InOutStore" />
</logger> </logger>
<root> <!--<root>
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
</root>-->
<logger name="RollingLogFileAppender">
<level value="Info" /> <level value="Info" />
<appender-ref ref="RollingLogFileAppender" /> <appender-ref ref="RollingLogFileAppender" />
</root> </logger>
<logger name="RunLog">
<level value="Info" />
<appender-ref ref="RunLog" />
</logger>
</log4net> </log4net>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!