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;
}
......@@ -595,7 +606,9 @@ namespace OnlineStore.DeviceLibrary
{
TimeSpan span = DateTime.Now - startInStoreTime;
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();
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;
......@@ -437,47 +437,143 @@ namespace OnlineStore.DeviceLibrary
}
public IO_VALUE IOValue(string IoType)
{
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)
{
if (String.IsNullOrEmpty(WarnMsg).Equals(false))
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)
{
try
{
if (WarnMsg.Equals(msg))
int logtype = 801;
if (moveInfo != null)
{
logtype = DeviceID * 10000 + (int)moveInfo.MoveStep;
}
if (String.IsNullOrEmpty(msg).Equals(false))
{
if (msg.StartsWith(Name))
if (WarnMsg.Equals(msg) || alarmType.Equals(warnParam.AlarmType))
{
LogUtil.error(msg, 105);
if (msg.StartsWith(Name))
{
LogUtil.error(msg, logtype, logseconds);
}
else
{
LogUtil.error(Name + msg, logtype, logseconds);
}
}
else
{
LogUtil.error(Name + msg, 105);
if (msg.StartsWith(Name))
{
LogUtil.error(msg);
}
else
{
LogUtil.error(Name + msg);
}
}
}
else
if (!warnParam.AlarmType.Equals(alarmType))
{
if (msg.StartsWith(Name))
//报警类型不一致,若之前不是空,记录日志
if (!String.IsNullOrEmpty(warnParam.AlarmType))
{
LogUtil.error(msg);
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
{
msg = Name + msg;
LogUtil.error( msg);
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);
}
public void LogInfo(string logInfo)
if (isInSuddenDown || isNoAirCheck)
{
return;
}
if (String.IsNullOrEmpty(WarnMsg).Equals(false) && String.IsNullOrEmpty(warnParam.AlarmType).Equals(false))
{
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()
{
LogUtil.info(Name + logInfo);
}
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 = "";
}
}
......@@ -4,6 +4,7 @@ using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.IO.Ports;
......@@ -130,24 +131,29 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 料仓原点返回和重置步骤,轴三先相对走3000
/// </summary>
[Description("复位_进出轴原点返回")]
BOX_H_InOutMove = 011,
/// <summary>
/// 料仓原点返回和重置步骤,,轴三进出轴先返回原点
/// </summary>
[Description("复位_压紧轴,旋转轴,上下轴原点返回")]
BOX_H_InOutBack = 012,
/// <summary>
/// 料仓原点返回和重置步骤,,轴三返回P1点
/// </summary>
[Description("复位_进出轴到待机点P1,关闭舱门")]
BOX_H_InOutToP1 = 013,
/// <summary>
/// 料仓原点返回和重置步骤,,升降轴,旋转轴,压紧轴原点返回
/// 料仓原点返回和重置步骤,,压紧轴,旋转轴,上下轴开始 原点返回,关闭舱门
/// </summary>
[Description("复位_压紧轴,旋转轴,上下轴开始 原点返回,关闭舱门")]
BOX_H_OtherAxisBack = 014,
/// <summary>
/// 旋转轴回好原点等待200
/// </summary>
BOX_H_WaitTime=015,
[Description("复位_旋转轴回好原点等待200")]
BOX_H_WaitTime =015,
///// <summary>
///// 清理轴位置
///// </summary>
......@@ -155,32 +161,39 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 旋转轴返回P1
/// </summary>
[Description("复位_旋转轴返回P1")]
BOX_H_MiddleAxisToP1 = 016,
/// <summary>
/// 叉子先退回P1
/// </summary>
[Description("复位_叉子先退回P1")]
BOX_M_H_InOutToP1 = 018,
/// <summary>
/// 旋转轴回原点
/// </summary>
[Description("复位_旋转轴回原点")]
BOX_M_H_MiddleAxisHome = 019,
/// <summary>
/// 旋转轴等待清理位置
/// </summary>
[Description("复位_旋转轴等待清理位置")]
BOX_M_H_MiddleWait = 020,
/// <summary>
/// 叉子走到P1
/// </summary>
[Description("复位_叉子走到P1")]
BOX_M_H_TOP1_InOutToP1 = 030,
/// <summary>
/// 压紧轴回原点
/// </summary>
[Description("复位_压紧轴回原点")]
BOX_M_H_TOP1_CompressHome = 031,
/// <summary>
/// 关闭门,旋转轴到P1,升降轴到P1
/// </summary>
[Description("复位_关闭门,旋转轴到P1,升降轴到P1")]
BOX_M_H_TOP1_OtherAxisToP1 = 032,
#endregion
......@@ -190,28 +203,36 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
///料仓出库:叉子先运动到P1
/// </summary>
[Description("出库_取料前_进出轴到P1")]
SO_02_InoutBack = 102,
/// <summary>
/// 料仓出库,,所有轴运行到库位, 压紧轴到P3(压紧前点) ,旋转轴到P2( 库位点),升降轴到P5(库位出库前点)
/// </summary>
[Description("出库_取料_压紧轴至P3(压紧前点) ,旋转轴至P2(库位点),升降轴至P5(库位出库前点) ")]
SO_03_ToBagP,
/// <summary>
/// 料仓出库,,叉子进入库位中, 进出轴到P3(库位取放料点)
/// </summary>
[Description("出库_取料_进出轴至P3(库位取放料点)")]
SO_04_InoutToP3,
/// <summary>
///料仓出库,, 库位的物品放入叉子上,升降轴到P6( 库位出料缓冲点),压紧轴到P2(压紧点)
/// </summary>
[Description("出库_取料_升降轴至P6(库位出料缓冲点),压紧轴至P2(压紧点)")]
SO_05_GetWare,
/// <summary>
///料仓出库,,叉子从 库位返回,进出轴到P1( 待机点)
/// </summary>
[Description("出库_取料完成_进出轴至P1(待机点)")]
SO_06_InoutToP1,
SO_07_TrayCheck ,
/// <summary>
/// 出库:等待叉子料盘检测信号
/// </summary>
[Description("出库_等待叉子料盘检测信号")]
SO_07_TrayCheck,
#region 定位处理:先将料放入定位区,再拿起料到仓门口
......@@ -219,44 +240,54 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 出库定位:旋转轴 至P2( 库位点)升降轴到P3(库位入库前点)
/// </summary>
[Description("出库_取料完成_旋转轴 至P2( 库位点)升降轴到P3(库位入库前点)")]
SOL_11_MoveToBag = 110,
/// <summary>
/// 出库定位:进出轴到P3(库位取放料点)
/// </summary>
[Description("出库_出库定位_进出轴到P3(库位取放料点)")]
SOL_12_InoutToP3,
/// <summary>
/// 出库定位: 压紧轴到P3( 压紧前点)
/// </summary>
[Description("出库_出库定位_压紧轴到P3( 压紧前点)")]
SOL_13_ComToP3,
/// <summary>
/// 出库定位:放下物品,升降轴到P4( 库位入料缓冲点)
/// </summary>
[Description("出库_出库定位_升降轴到P4( 库位入料缓冲点)")]
SOL_14_UpdownToP4,
/// <summary>
/// 出库定位:放下物品后等待200
/// </summary>
[Description("出库_出库定位_放下物品后等待200")]
SOL_15_WaitTime,
/// <summary>
/// 出库定位:拿物品,升降轴到P6( 库位出料缓冲点),压紧轴到P2(压紧点)
/// </summary>
[Description("出库_出库定位_升降轴到P6( 库位出料缓冲点),压紧轴到P2(压紧点)")]
SOL_16_GetWare,
/// <summary>
/// 出库定位2:放下物品,升降轴到P4( 库位入料缓冲点)
/// </summary>
[Description("出库_出库定位2_升降轴到P4( 库位入料缓冲点)")]
SOL_17_UpdownToP42,
/// <summary>
/// 出库定位2:放下物品后等待200
/// </summary>
[Description("出库_出库定位2_放下物品后等待200")]
SOL_18_WaitTime2,
/// <summary>
/// 出库定位2:拿物品,升降轴到P6( 库位出料缓冲点),压紧轴到P2(压紧点)
/// </summary>
SOL_19_GetWare2,
[Description("出库_出库定位2_升降轴到P6( 库位出料缓冲点),压紧轴到P2(压紧点)")]
SOL_19_GetWare2,
/// <summary>
/// 出库定位:叉子从 库位返回,进出轴到P1( 待机点)
/// </summary>
[Description("出库_出库定位完成_进出轴到P1( 待机点)")]
SOL_20_InoutToP1,
#endregion
......@@ -265,38 +296,47 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 料仓出库,,所有设备运行到门,,旋转轴到P1( 待机点)升降轴到P2( 进料口出料前点)
/// </summary>
[Description("出库_放料前_旋转轴至P1(待机点)升降轴至P2(进料口出料前点),打开舱门")]
SO_21_ToDoorP = 121,
/// <summary>
/// 等待门口无料盘
/// </summary>
[Description("出库_放料前_等待门口无料盘信号")]
SO_22_WaitNoTray,
/// <summary>
/// 料仓出库,,叉子进出料口,,进出轴到P2( 进料口取料点)
/// /// </summary>
[Description("出库_放料_进出轴到P2( 进料口取料点)")]
SO_23_InoutToP2,
/// <summary>
/// 料仓出库,,把物品放下,,升降轴到P8( 进料口出料缓冲点)压紧轴到P1( 待机点)
/// </summary>
[Description("出库_放料_升降轴到P8( 进料口出料缓冲点)压紧轴到P1( 待机点)")]
SO_24_PutWare,
/// <summary>
/// 料仓出库,,叉子从出料口返回,,轴3( 叉子) 动作至P1( 待机点)
/// </summary>
[Description("出库_放料_进出轴动作至P1(待机点)")]
SO_25_InoutToP1,
/// <summary>
/// 料仓出库,,升降轴返回,, 轴2至P1( 待机点),关闭仓门
/// </summary>
[Description("出库_放料完成_升降轴至P1( 待机点),关闭仓门")]
SO_26_CloseDoor,
/// <summary>
/// 料仓出库,检测料仓门口信号
/// </summary>
[Description("出库_放料完成_检测料仓门口信号")]
SO_27_CheckTray,
/// <summary>
/// 料仓出库,,升降轴返回,, 轴2至P1( 待机点)
/// </summary>
[Description("出库_放料完成_发送出库完成消息给流水线")]
SO_28_GoBack,
/// <summary>
/// 等待拿走物品
/// </summary>
[Description("出库_放料完成_等待拿走物品")]
SO_29_WaitTake,
#endregion
......@@ -305,6 +345,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 入库检测
/// </summary>
[Description("入库_取料前_等待仓门口有料")]
SI_00_TrayCheck = 200,
///// <summary>
///// 入库,。定位气缸下降
......@@ -313,56 +354,69 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 入库。。进出轴(叉子)先返回P1
/// </summary>
[Description("入库_取料_进出轴(叉子)动作至P1,打开舱门")]
SI_02_InOutToP1 = 202,
/// <summary>
/// 入库。。所有轴先回到待机点,轴2、轴1 动作到P1,,轴4动作至P3
/// </summary>
[Description("入库_取料_升降轴到P1,旋转轴到P1 ,压紧轴到P3,打开仓门")]
SI_03_AxisToP1 = 203,
/// <summary>
/// 入库。。压紧物品(有压紧轴的才需要此步骤),压紧轴到P3(压紧前点)
/// </summary>
[Description("入库_取料_叉子即将取料,发现门未上升到位,重新打开门")]
SI_04_ComToP3 = 204,
/// <summary>
/// 入库。。叉子进入入料口,进出轴到P2( 进料口取料点)
/// </summary>
[Description("入库_取料_进出轴至P2(进料口取料点) ")]
SI_05_InoutToP2 = 205,
/// <summary>
/// 入库。。把物品放入叉子上,升降轴到P7( 进料口取料缓冲点),压紧物品(有压紧轴的才需要此步骤),压紧轴到P2(压紧点)
/// </summary>
[Description("入库_取料_压紧轴至P2(压紧点)),升降轴至P7(进料口取料缓冲点)")]
SI_06_GetReel = 206,
/// <summary>
/// 入库。。叉子 从入料口抽出,进出轴到P1( 待机点)
/// </summary>
[Description("入库_取料_进出轴到P1( 待机点)")]
SI_07_InoutBack = 207,
/// <summary>
/// 入库。。,等待检测到料盘
/// </summary>
[Description("入库_取料_等待叉子有料")]
SI_08_TrayCheck = 208,
/// <summary>
/// 入库。。移动到库位点,旋转轴到P2( 库位点)升降轴到P3(库位入库前点)
/// </summary>
[Description("入库_放料_旋转轴至P2(库位点),升降轴至P3(库位入库前点)),关闭舱门")]
SI_09_MoveToBag = 209,
/// <summary>
/// 入库。。叉子进入库位中,进出轴到P3(库位取放料点)
/// </summary>
[Description("入库_放料_进出轴到P3(库位取放料点)")]
SI_11_InoutToP3 = 211,
/// <summary>
/// 入库。。放下物品,升降轴到P4( 库位入料缓冲点)压紧轴到P3( 压紧前点)
/// </summary>
[Description("入库_放料_升降轴到P4( 库位入料缓冲点)压紧轴到P3( 压紧前点)")]
SI_12_PutReel = 212,
/// <summary>
/// 入库。。叉子从库位中返回,轴3( 叉子) 动作至P1( 待机点)
/// </summary>
[Description("入库_放料_进出轴动作至P1(待机点)")]
SI_13_InoutBack,
/// <summary>
/// 入库。。返回待机点,轴2/轴1/轴4动作至P1( 待机点))开始
/// </summary>
[Description("入库_放料完成_轴2/轴1/轴4动作至P1(待机点)),检测门关闭")]
SI_14_GoBack,
/// <summary>
/// 入库。等待叉子无信号
/// </summary>
[Description("入库_放料完成_等待料叉无信号")]
SI_15_WaitNoReel,
#endregion
......@@ -371,18 +425,22 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 盘点 料叉回原点P1
/// </summary>
[Description("盘点_进出轴返回P1")]
SC_01_InOutAxisHome,
/// <summary>
/// 料叉背面移动到库位低点
/// </summary>
[Description("盘点_料叉背面移动到库位低点")]
SC_02_MoveToLBag,
/// <summary>
/// 料叉背面移动到库位高点
/// </summary>
[Description("盘点_料叉背面移动到库位高点")]
SC_03_MoveToHBag,
/// <summary>
/// 盘点仓位
/// </summary>
[Description("盘点_盘点仓位")]
SC_04_Inventory,
#endregion
......@@ -391,30 +449,37 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 校准位置:进出轴回原点
/// </summary>
AP_01_InoutHome=10001,
[Description("校准位置_进出轴回原点")]
AP_01_InoutHome =10001,
/// <summary>
/// 校准位置:升降轴回原点
/// </summary>
[Description("校准位置_升降轴回原点")]
AP_02_UpdownHome,
/// <summary>
/// 位置校准:升降轴移动到开始位置
/// </summary>
[Description("校准位置_升降轴移动到开始位置")]
AP_03_UpdownMove,
/// <summary>
/// 校准位置:旋转轴选择到对应位置
/// </summary>
[Description("校准位置_旋转轴选择到对应位置")]
AP_04_MiddleMove,
/// <summary>
/// 校准位置:进出轴到前进位置
/// </summary>
[Description("校准位置_进出轴到前进位置")]
AP_05_InoutToP,
/// <summary>
/// 校准位置:升降轴开始匀速移动到目标位置
/// </summary>
[Description("校准位置_升降轴开始匀速移动到目标位置")]
AP_06_UpdownMove,
/// <summary>
/// 校准位置:保存当前列位置
/// </summary>
[Description("校准位置_保存当前列位置")]
AP_07_SaveAndNext,
#endregion
......
......@@ -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!