using iWareCc.Cache.Entity;
|
using iWareCcTest.Properties;
|
using iWareCommon.Common.EnumType;
|
using iWareCommon.Utils;
|
using iWareDataCore.DEV.Entity;
|
using iWareDataCore.DEV.EnumType;
|
using iWareDataCore.ORM;
|
using iWareDataCore.TASK.EnumType;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareCc.Srm.Entity
|
{
|
public class StackerEntity
|
{
|
/// <summary>
|
/// 1Srm编号
|
/// </summary>
|
|
public int SrmNo { get; set; }
|
|
/// <summary>
|
/// 2运行模式
|
/// </summary>
|
public int Mode { get; set; }
|
|
|
/// <summary>
|
/// 3告警信号
|
/// </summary>
|
|
public int Alarm { get; set; }
|
|
|
/// <summary>
|
/// 4载货工位是否有货
|
/// </summary>
|
public int LiftFull { get; set; }
|
|
|
/// <summary>
|
/// 5当前列
|
/// </summary>
|
public int PosX { get; set; }
|
|
/// <summary>
|
/// 6当前层
|
/// </summary>
|
public int PosY { get; set; }
|
|
|
/// <summary>
|
/// 7货叉位置
|
/// </summary>
|
public int PosZ { get; set; }
|
|
|
/// <summary>
|
/// 8当前列坐标
|
/// </summary>
|
public int PosXmm { get; set; }
|
|
|
/// <summary>
|
/// 9当前层坐标
|
/// </summary>
|
public int PosYmm { get; set; }
|
|
|
/// <summary>
|
/// 10当前货叉坐标
|
/// </summary>
|
public int PosZmm { get; set; }
|
|
|
/// <summary>
|
/// 11完成取货信号
|
/// </summary>
|
public int PickFinish { get; set; }
|
|
|
/// <summary>
|
/// 12完成放货信号
|
/// </summary>
|
public int DeliveryFinish { get; set; }
|
|
|
/// <summary>
|
/// 13任务完成
|
/// </summary>
|
public int TaskFinish { get; set; }
|
|
|
/// <summary>
|
/// 14任务号
|
/// </summary>
|
public int TaskNo { get; set; }
|
|
|
/// <summary>
|
/// 15运行状态
|
/// </summary>
|
public int State { get; set; }
|
|
|
|
/// <summary>
|
/// 16当前巷道号
|
/// </summary>
|
|
public int ActualLane { get; set; }
|
|
/// <summary>
|
/// 17告警代码
|
/// </summary>
|
|
public int AlarmNumber { get; set; }
|
|
|
/// <summary>
|
/// 18心跳
|
/// </summary>
|
public int HandShake { get; set; }
|
|
|
|
/// <summary>
|
/// 1Srm编号
|
/// </summary>
|
|
public int WSrmNo { get; set; }
|
|
|
/// <summary>
|
/// 2任务号
|
/// </summary>
|
public int WTaskNo { get; set; }
|
|
/// <summary>
|
/// 3源列
|
/// </summary>
|
public int WSourcePosX { get; set; }
|
|
/// <summary>
|
/// 4源层
|
/// </summary>
|
public int WSourcePosY { get; set; }
|
|
/// <summary>
|
/// /5源排
|
/// </summary>
|
public int WSourcePosZ { get; set; }
|
|
/// <summary>
|
/// 6宿列
|
/// </summary>
|
public int WDestinationPosX { get; set; }
|
|
/// <summary>
|
/// 7宿层
|
/// </summary>
|
public int WDestinationPosY { get; set; }
|
|
|
/// <summary>
|
/// 8宿排
|
/// </summary>
|
public int WDestinationPosZ { get; set; }
|
|
/// <summary>
|
/// 9发送命令
|
/// </summary>
|
public int WCommand { get; set; }
|
|
/// <summary>
|
/// 10紧急停止
|
/// </summary>
|
public int WEmergencyStop { get; set; }
|
|
/// <summary>
|
/// 11解除告警
|
/// </summary>
|
public int WAlarmAck { get; set; }
|
|
/// <summary>
|
/// 12WCS通讯位
|
/// </summary>
|
public int WStb { get; set; }
|
|
///<summary>
|
///13SRM 应答位
|
///</summary>
|
public int WAck { get; set; }
|
|
|
/// <summary>
|
/// 14心跳
|
/// </summary>
|
public int WHandShake { get; set; }
|
|
/// <summary>
|
/// 15批次(0:否;1:是)
|
/// </summary>
|
public int WLots { get; set; }
|
|
/// <summary>
|
/// 是否在线
|
/// </summary>
|
public bool IsOnline { get; set; }
|
|
/// <summary>
|
/// 下线次数
|
/// </summary>
|
public int OffLineTimes { get; set; }
|
|
/// <summary>
|
/// 上一次心跳数
|
/// </summary>
|
public int LastHandShake { get; set; }
|
|
/// <summary>
|
/// 设备实体
|
/// </summary>
|
public EquipmentEntity Equipment { get; private set; }
|
|
/// <summary>
|
/// WCS需要写入的OPC地址
|
/// </summary>
|
public OpcWriteItem OpcWriteItems { get; set; }
|
|
|
/// <summary>
|
/// WCS需要读取的OPC地址
|
/// </summary>
|
public OpcReadItem OpcReadItems { get; set; }
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="equipment">设备实体</param>
|
public StackerEntity(EquipmentEntity equipment)
|
{
|
this.Equipment = equipment;
|
|
var name = this.Equipment.EquipName;
|
|
OpcWriteItems = CacheEntity.IsRealMode ? new OpcWriteItem
|
{
|
SrmNo = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W2" : "S7:[S7_Connection_3]DB540,W2",// 1Srm编号
|
TaskNo = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W34" : "S7:[S7_Connection_3]DB540,DINT38",// 2任务号
|
SourcePosX = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W6" : "S7:[S7_Connection_3]DB540,W6",// 3源列
|
SourcePosY = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W8" : "S7:[S7_Connection_3]DB540,W8",// 4源层
|
SourcePosZ = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W10" : "S7:[S7_Connection_3]DB540,W10",//5源排
|
DestinationPosX = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W12" : "S7:[S7_Connection_3]DB540,W12",// 6宿列
|
DestinationPosY = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W14" : "S7:[S7_Connection_3]DB540,W14",// 7宿层
|
DestinationPosZ = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W16" : "S7:[S7_Connection_3]DB540,W16",// 8宿排
|
Command = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W18" : "S7:[S7_Connection_3]DB540,W18",// 9发送命令
|
EmergencyStop = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W20" : "S7:[S7_Connection_3]DB540,W20",// 10紧急停止
|
AlarmAck = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W22" : "S7:[S7_Connection_3]DB540,W22",// 11解除告警
|
Stb = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W30" : "S7:[S7_Connection_3]DB540,W30",// 12WCS通讯位
|
Ack = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W32" : "S7:[S7_Connection_3]DB540,W32",// 13SRM 应答位
|
HandShake = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W0" : "S7:[S7_Connection_3]DB540,W0",// 14心跳
|
Lots = name == "stacker1" ? "S7:[S7_Connection_1]DB540,W4" : "S7:[S7_Connection_3]DB540,W4"// 15是否批量
|
} : new OpcWriteItem
|
{
|
SrmNo = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W0" : "S7:[@LOCALSERVER]DB1,W70",// 1Srm编号
|
TaskNo = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,DINT6422" : "S7:[@LOCALSERVER]DB1,DINT6430",// 2任务号
|
SourcePosX = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W4" : "S7:[@LOCALSERVER]DB1,W74",// 3源列
|
SourcePosY = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W6" : "S7:[@LOCALSERVER]DB1,W76",// 4源层
|
SourcePosZ = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W8" : "S7:[@LOCALSERVER]DB1,W78",//5源排
|
DestinationPosX = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W10" : "S7:[@LOCALSERVER]DB1,W80",// 6宿列
|
DestinationPosY = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W12" : "S7:[@LOCALSERVER]DB1,W82",// 7宿层
|
DestinationPosZ = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W14" : "S7:[@LOCALSERVER]DB1,W84",// 8宿排
|
Command = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W16" : "S7:[@LOCALSERVER]DB1,W86",// 9发送命令
|
EmergencyStop = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W18" : "S7:[@LOCALSERVER]DB1,W88",// 10紧急停止
|
AlarmAck = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W20" : "S7:[@LOCALSERVER]DB1,W90",// 11解除告警
|
Stb = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W22" : "S7:[@LOCALSERVER]DB1,W92",// 12WCS通讯位
|
Ack = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W24" : "S7:[@LOCALSERVER]DB1,W94",// 13SRM 应答位
|
HandShake = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W26" : "S7:[@LOCALSERVER]DB1,W96"// 14心跳
|
};
|
|
OpcReadItems = CacheEntity.IsRealMode ? new OpcReadItem
|
{
|
SrmNo = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W2" : "S7:[S7_Connection_3]DB541,W2",// 1Srm编号
|
Mode = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W4" : "S7:[S7_Connection_3]DB541,W4",// 2模式
|
Alarm = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W6" : "S7:[S7_Connection_3]DB541,W6",// 3告警
|
LiftFull = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W8" : "S7:[S7_Connection_3]DB541,W8",// 4载货工位是否有货
|
PosX = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W10" : "S7:[S7_Connection_3]DB541,W10",// 5当前列
|
PosY = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W12" : "S7:[S7_Connection_3]DB541,W12",// 6当前层
|
PosZ = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W14" : "S7:[S7_Connection_3]DB541,W14", // 7货叉位置
|
PosXmm = name == "stacker1" ? "S7:[S7_Connection_1]DB541,DINT16" : "S7:[S7_Connection_3]DB541,DINT16",// 8当前列坐标
|
PosYmm = name == "stacker1" ? "S7:[S7_Connection_1]DB541,DINT20" : "S7:[S7_Connection_3]DB541,DINT20",// 9当前层坐标
|
PosZmm = name == "stacker1" ? "S7:[S7_Connection_1]DB541,DINT24" : "S7:[S7_Connection_3]DB541,DINT24",// 10当前货叉坐标
|
PickFinish = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W28" : "S7:[S7_Connection_3]DB541,W28",// 11完成取货信号
|
DeliveryFinish = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W30" : "S7:[S7_Connection_3]DB541,W30",// 12完成放货信号
|
TaskFinish = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W32" : "S7:[S7_Connection_3]DB541,W32",// 13任务完成
|
TaskNo = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W48" : "S7:[S7_Connection_3]DB541,DINT48",// 14当前任务号
|
State = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W36" : "S7:[S7_Connection_3]DB541,W36",// 15当前任务执行状态
|
ActualLane = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W38" : "S7:[S7_Connection_3]DB541,W38",// 16当前巷道号
|
AlarmNumber = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W40" : "S7:[S7_Connection_3]DB541,W40",// 17告警代码
|
HandShake = name == "stacker1" ? "S7:[S7_Connection_1]DB541,W0" : "S7:[S7_Connection_3]DB541,W0"// 18心跳
|
} : new OpcReadItem
|
{
|
SrmNo = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W28" : "S7:[@LOCALSERVER]DB1,W98",// 1Srm编号
|
Mode = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W30" : "S7:[@LOCALSERVER]DB1,W100",// 2模式
|
Alarm = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W32" : "S7:[@LOCALSERVER]DB1,W102",// 3告警
|
LiftFull = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W34" : "S7:[@LOCALSERVER]DB1,W104",// 4载货工位是否有货
|
PosX = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W36" : "S7:[@LOCALSERVER]DB1,W106",// 5当前列
|
PosY = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W38" : "S7:[@LOCALSERVER]DB1,W108",// 6当前层
|
PosZ = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W40" : "S7:[@LOCALSERVER]DB1,W110", // 7货叉位置
|
PosXmm = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,DINT42" : "S7:[@LOCALSERVER]DB1,DINT112",// 8当前列坐标
|
PosYmm = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,DINT46" : "S7:[@LOCALSERVER]DB1,DINT116",// 9当前层坐标
|
PosZmm = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,DINT50" : "S7:[@LOCALSERVER]DB1,DINT120",// 10当前货叉坐标
|
PickFinish = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W54" : "S7:[@LOCALSERVER]DB1,W124",// 11完成取货信号
|
DeliveryFinish = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W56" : "S7:[@LOCALSERVER]DB1,W126",// 12完成放货信号
|
TaskFinish = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W58" : "S7:[@LOCALSERVER]DB1,W128",// 13任务完成
|
TaskNo = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,DINT6426" : "S7:[@LOCALSERVER]DB1,DINT6434",// 14当前任务号
|
State = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W62" : "S7:[@LOCALSERVER]DB1,W132",// 15当前任务执行状态
|
ActualLane = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W64" : "S7:[@LOCALSERVER]DB1,W134",// 16当前巷道号
|
AlarmNumber = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W66" : "S7:[@LOCALSERVER]DB1,W136",// 17告警代码
|
HandShake = name == "stacker1" ? "S7:[@LOCALSERVER]DB1,W68" : "S7:[@LOCALSERVER]DB1,W138"// 18心跳
|
};
|
|
}
|
|
/// <summary>
|
/// 发送任务
|
/// </summary>
|
/// <param name="taskNo">任务号</param>
|
/// <param name="srmNo">堆垛机号</param>
|
/// <param name="sourcePosX">起始列</param>
|
/// <param name="sourcePosY">起始层</param>
|
/// <param name="sourcePosZ">起始排</param>
|
/// <param name="destinationPosX">目标列</param>
|
/// <param name="destinationPosY">目标层</param>
|
/// <param name="destinationPosZ">目标排</param>
|
/// <returns>是否发送成功</returns>
|
public bool SendTask(int taskNo, int srmNo, int sourcePosX, int sourcePosY, int sourcePosZ, int destinationPosX, int destinationPosY, int destinationPosZ,int maintasktype,int lots)
|
{
|
try
|
{
|
int conmd = (int)ESrmCommand.搬运;//正常情况下的任务
|
if (maintasktype == 4)
|
{
|
conmd = (int)ESrmCommand.移动;//只移动不实际取货
|
}
|
var flag1 = CacheEntity.OpcWcfServiceClient.WriteValues(new string[]
|
{
|
this.OpcWriteItems.TaskNo,
|
this.OpcWriteItems.SrmNo,
|
this.OpcWriteItems.SourcePosX,
|
this.OpcWriteItems.SourcePosY,
|
this.OpcWriteItems.SourcePosZ,
|
this.OpcWriteItems.DestinationPosX,
|
this.OpcWriteItems.DestinationPosY,
|
this.OpcWriteItems.DestinationPosZ,
|
this.OpcWriteItems.Command,
|
this.OpcWriteItems.Stb,
|
this.OpcWriteItems.Lots
|
},
|
|
new object[] { taskNo, srmNo, sourcePosX, sourcePosY, sourcePosZ, destinationPosX, destinationPosY, destinationPosZ, conmd, (int)EYesOrNo.是, lots});
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "发送堆垛机批次状态" + lots.ToString(), "地址块"+this.OpcWriteItems.Lots.ToString());
|
var ack = false;
|
|
while (!ack)
|
{
|
ack = int.Parse(CacheEntity.OpcWcfServiceClient.ReadValue(this.OpcWriteItems.Ack).ToString()) > 0;
|
}
|
|
var flag2 = CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.Stb, (int)EYesOrNo.否);
|
|
return flag1 && flag2;
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "SendTask", ex.Message);
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 是否能够生成堆垛机任务
|
/// </summary>
|
/// <param name="msg">异常错误消息</param>
|
/// <returns>是否能够发送任务</returns>
|
public bool CanParseTask(out string msg)
|
{
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
msg = "";
|
if (!this.IsOnline)
|
{
|
msg = "堆垛机不在线";
|
return false;
|
}
|
|
if (this.Mode != (int)ESrmMode.自动模式)
|
{
|
msg = "堆垛机不是自动模式";
|
return false;
|
}
|
|
if (this.Alarm != (int)EYesOrNo.否)
|
{
|
msg = string.Format("堆垛机报警:{0}", (ESrmAlarm)this.AlarmNumber);
|
return false;
|
}
|
|
if (this.State != (int)ESrmState.堆垛机空闲)
|
{
|
msg = "堆垛机忙碌中";
|
return false;
|
}
|
|
var count = 0;
|
count = dbModel.TASKPartTasks.Where(x => x.isreleased == (int)EYesOrNo.是 && x.isfinished == (int)EYesOrNo.否 && x.type == (int)EPartTaskType.堆垛机任务).Count();
|
|
if (count > 0)
|
{
|
msg = string.Format("堆垛机{0}还有任务未完成", this.Equipment.EquipName);
|
return false;
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
return false;
|
|
}
|
}
|
}
|
|
/// <summary>
|
/// 是否能够生成堆垛机任务
|
/// </summary>
|
/// <param name="msg">异常错误消息</param>
|
/// <returns>是否能够发送任务</returns>
|
public bool CanDecomposeTask(out string msg)
|
{
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
msg = "";
|
if (!this.IsOnline)
|
{
|
msg = "堆垛机不在线";
|
return false;
|
}
|
|
if (this.Mode != (int)ESrmMode.自动模式)
|
{
|
msg = "堆垛机不是自动模式";
|
return false;
|
}
|
|
if (this.Alarm != (int)EYesOrNo.否)
|
{
|
msg = string.Format("堆垛机报警:{0}", (ESrmAlarm)this.AlarmNumber);
|
return false;
|
}
|
|
if (this.State != (int)ESrmState.堆垛机空闲)
|
{
|
msg = "堆垛机忙碌中";
|
return false;
|
}
|
|
var count = 0;
|
if (CacheEntity.DeviceRunningMode == null || CacheEntity.DeviceRunningMode.Mode == (int)EDeviceMode.双堆垛机模式)
|
{
|
count = dbModel.TASKPartTasks.Where(x => x.isfinished == (int)EYesOrNo.否 && x.type == (int)EPartTaskType.堆垛机任务 && x.equipname == this.Equipment.EquipName).Count();
|
}
|
else
|
{
|
count = dbModel.TASKPartTasks.Where(x => x.isfinished == (int)EYesOrNo.否 && x.type == (int)EPartTaskType.堆垛机任务).Count();
|
}
|
|
if (count > 0)
|
{
|
msg = string.Format("堆垛机{0}还有任务未完成", this.Equipment.EquipName);
|
return false;
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
return false;
|
|
}
|
}
|
}
|
|
}
|
}
|