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
{
///
/// 1Srm编号
///
public int SrmNo { get; set; }
///
/// 2运行模式
///
public int Mode { get; set; }
///
/// 3告警信号
///
public int Alarm { get; set; }
///
/// 4载货工位是否有货
///
public int LiftFull { get; set; }
///
/// 5当前列
///
public int PosX { get; set; }
///
/// 6当前层
///
public int PosY { get; set; }
///
/// 7货叉位置
///
public int PosZ { get; set; }
///
/// 8当前列坐标
///
public int PosXmm { get; set; }
///
/// 9当前层坐标
///
public int PosYmm { get; set; }
///
/// 10当前货叉坐标
///
public int PosZmm { get; set; }
///
/// 11完成取货信号
///
public int PickFinish { get; set; }
///
/// 12完成放货信号
///
public int DeliveryFinish { get; set; }
///
/// 13任务完成
///
public int TaskFinish { get; set; }
///
/// 14任务号
///
public int TaskNo { get; set; }
///
/// 15运行状态
///
public int State { get; set; }
///
/// 16当前巷道号
///
public int ActualLane { get; set; }
///
/// 17告警代码
///
public int AlarmNumber { get; set; }
///
/// 18心跳
///
public int HandShake { get; set; }
///
/// 1Srm编号
///
public int WSrmNo { get; set; }
///
/// 2任务号
///
public int WTaskNo { get; set; }
///
/// 3源列
///
public int WSourcePosX { get; set; }
///
/// 4源层
///
public int WSourcePosY { get; set; }
///
/// /5源排
///
public int WSourcePosZ { get; set; }
///
/// 6宿列
///
public int WDestinationPosX { get; set; }
///
/// 7宿层
///
public int WDestinationPosY { get; set; }
///
/// 8宿排
///
public int WDestinationPosZ { get; set; }
///
/// 9发送命令
///
public int WCommand { get; set; }
///
/// 10紧急停止
///
public int WEmergencyStop { get; set; }
///
/// 11解除告警
///
public int WAlarmAck { get; set; }
///
/// 12WCS通讯位
///
public int WStb { get; set; }
///
///13SRM 应答位
///
public int WAck { get; set; }
///
/// 14心跳
///
public int WHandShake { get; set; }
///
/// 15批次(0:否;1:是)
///
public int WLots { get; set; }
///
/// 是否在线
///
public bool IsOnline { get; set; }
///
/// 下线次数
///
public int OffLineTimes { get; set; }
///
/// 上一次心跳数
///
public int LastHandShake { get; set; }
///
/// 设备实体
///
public EquipmentEntity Equipment { get; private set; }
///
/// WCS需要写入的OPC地址
///
public OpcWriteItem OpcWriteItems { get; set; }
///
/// WCS需要读取的OPC地址
///
public OpcReadItem OpcReadItems { get; set; }
///
/// 构造函数
///
/// 设备实体
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心跳
};
}
///
/// 发送任务
///
/// 任务号
/// 堆垛机号
/// 起始列
/// 起始层
/// 起始排
/// 目标列
/// 目标层
/// 目标排
/// 是否发送成功
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;
}
}
///
/// 是否能够生成堆垛机任务
///
/// 异常错误消息
/// 是否能够发送任务
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;
}
}
}
///
/// 是否能够生成堆垛机任务
///
/// 异常错误消息
/// 是否能够发送任务
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;
}
}
}
}
}