using IWareCC.CacheInfo;
|
using IWareCC.Properties;
|
using IWareCommon.Enum.Srm;
|
using IWareCommon.Help;
|
using S7.Net;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
namespace IWareCC.SRM.Entity
|
{
|
public class SrmEntity
|
{
|
/// <summary>
|
/// 堆垛机名称
|
/// </summary>
|
public string SrmName { get; set; }
|
/// <summary>
|
/// 设备编号
|
/// </summary>
|
public int DeviceId { get; set; }
|
/// <summary>
|
/// 根据心跳判断堆垛机是否在线
|
/// </summary>
|
public bool IsOnline { get; set; }
|
/// <summary>
|
/// 下线次数
|
/// </summary>
|
public int OffLineTimes { get; set; }
|
|
/// <summary>
|
/// 上一次心跳数
|
/// </summary>
|
public int LastHandShake { get; set; }
|
|
/// <summary>
|
/// 连接PLC读的对象
|
/// </summary>
|
public PlcS7 RS71500 { get; set; }
|
/// <summary>
|
/// 连接PLC写的对象
|
/// </summary>
|
public PlcS7 WS71500 { get; set; }
|
|
#region 写入的堆垛机信息
|
|
/// <summary>
|
/// 心跳
|
/// </summary>
|
public int WHandShake { get; set; }
|
/// <summary>
|
/// 堆垛机编号
|
/// </summary>
|
public int WSrmNo { get; set; }
|
/// <summary>
|
/// 任务类型
|
/// </summary>
|
public int WCommand { get; set; }
|
/// <summary>
|
/// 急停
|
/// </summary>
|
public int WEmergencyStop { get; set; }
|
/// <summary>
|
/// 起始列
|
/// </summary>
|
public int WSourcePosX { get; set; }
|
/// <summary>
|
/// 起始层
|
/// </summary>
|
public int WSourcePosY { get; set; }
|
/// <summary>
|
/// 起始排
|
/// </summary>
|
public int WSourcePosZ { get; set; }
|
/// <summary>
|
/// 目标列
|
/// </summary>
|
public int WDestinationPosX { get; set; }
|
/// <summary>
|
/// 目标层
|
/// </summary>
|
public int WDestinationPosY { get; set; }
|
/// <summary>
|
/// 目标排
|
/// </summary>
|
public int WDestinationPosZ { get; set; }
|
/// <summary>
|
///任务号
|
/// </summary>
|
public int WTaskNo { get; set; }
|
/// <summary>
|
/// 任务完成确认
|
/// </summary>
|
public bool WTaskFinishConfirm { get; set; }
|
/// <summary>
|
/// 解除报警
|
/// </summary>
|
public bool WCancleAlarm { get; set; }
|
|
/// <summary>
|
/// 确认任务已发送的信号
|
/// </summary>
|
public bool WStb { get; set; }
|
|
/// <summary>
|
/// 托盘类型
|
/// </summary>
|
public int WPalletType { get; set; }
|
|
/// <summary>
|
/// 货物高度
|
/// </summary>
|
public int WHigh { get; set; }
|
|
#endregion
|
|
#region 读取到的堆垛机信息
|
/// <summary>
|
/// 读取心跳
|
/// </summary>
|
public int RHandShake { get; set; }
|
/// <summary>
|
/// 设备编号
|
/// </summary>
|
public int RSrmNo { get; set; }
|
/// <summary>
|
/// 是否有报警
|
/// </summary>
|
public bool RAlarm { get; set; }
|
|
/// <summary>
|
/// 载货台是否有货
|
/// </summary>
|
public bool RLiftFull { get; set; }
|
/// <summary>
|
/// 设备模式
|
/// </summary>
|
public int RMode { get; set; }
|
|
/// <summary>
|
/// 当前列
|
/// </summary>
|
public int RPosX { get; set; }
|
/// <summary>
|
/// 当前层
|
/// </summary>
|
public int RPosY { get; set; }
|
/// <summary>
|
/// 当前排
|
/// </summary>
|
public int RPosZ { get; set; }
|
/// <summary>
|
/// 当前列坐标
|
/// </summary>
|
public int RPosXmm { get; set; }
|
/// <summary>
|
/// 当前层坐标
|
/// </summary>
|
public int RPosYmm { get; set; }
|
/// <summary>
|
/// 当前排坐标
|
/// </summary>
|
public int RPosZmm { get; set; }
|
/// <summary>
|
/// 取货完成
|
/// </summary>
|
public bool RPickFinish { get; set; }
|
/// <summary>
|
/// 放货完成
|
/// </summary>
|
public bool RDeliveryFinish { get; set; }
|
/// <summary>
|
/// 任务完成
|
/// </summary>
|
public bool RTaskFinish { get; set; }
|
/// <summary>
|
/// 当前巷道
|
/// </summary>
|
public int RActualLane { get; set; }
|
/// <summary>
|
/// 任务状态
|
/// </summary>
|
public int RState { get; set; }
|
/// <summary>
|
/// 报警代码
|
/// </summary>
|
public int RAlarmCode { get; set; }
|
/// <summary>
|
/// 任务号
|
/// </summary>
|
public int RTaskNo { get; set; }
|
|
/// <summary>
|
/// 确认收到下发的任务信号
|
/// </summary>
|
public bool RAck { get; set; }
|
#endregion
|
|
public OpcReadItem OpcReadItems { get; set; }
|
|
public OpcWriteItem OpcWriteItems { get; set; }
|
|
public SrmEntity() { }
|
|
public SrmEntity(string srmName, int deviceId, PlcS7 plc)
|
{
|
this.SrmName = srmName;
|
this.DeviceId = deviceId;
|
this.WS71500 = plc;
|
|
OpcWriteItems = new OpcWriteItem
|
{
|
HandShake = "DB540.DBW0",
|
SrmNo = "DB540.DBW2",
|
TaskNo = "DB540.DBW34",
|
TaskFinishConfirm = "DB540.DBW24",
|
EmergencyStop = "DB540.DBW20",
|
CancleAlarm = "DB540.DBW22",
|
Command = "DB540.DBW18",
|
SourcePosX = "DB540.DBW6",
|
SourcePosY = "DB540.DBW8",
|
SourcePosZ = "DB540.DBW10",
|
DestinationPosX = "DB540.DBW12",
|
DestinationPosY = "DB540.DBW14",
|
DestinationPosZ = "DB540.DBW16",
|
Stb = "DB540.DBW30",
|
PalletType = "DB540.DBW4",
|
High = "DB540.DBW26",
|
};
|
OpcReadItems = new OpcReadItem
|
{
|
HandShake = "DB541.DBW0",
|
PickFinish = "DB541.DBW28",
|
LiftFull = "DB541.DBW8",
|
Mode = "DB541.DBW4",
|
Alarm = "DB541.DBW6",
|
TaskFinish = "DB541.DBW32",
|
DeliveryFinish = "DB541.DBW30",
|
ActualLane = "DB541.DBW38",
|
SrmNo = "DB541.DBW2",
|
AlarmCode = "DB541.DBW34",
|
State = "DB541.DBW36",
|
PosZ = "DB541.DBW10",
|
PosX = "DB541.DBW12",
|
PosY = "DB541.DBW14",
|
PosXmm = "DB541.DBD16",
|
PosYmm = "DB541.DBD20",
|
PosZmm = "DB541.DBD24",
|
TaskNo = "DB541.DBW40",
|
Ack = "DB540.DBW32"
|
};
|
}
|
|
|
public bool SendTask(int deviceId, int taskId, string sourcePlace, string toPlace, int type, int palltype,int heighttype,out string msg)
|
{
|
try
|
{
|
msg = "";
|
if (!CanSendTask(deviceId, out msg))
|
{
|
return false;
|
}
|
var sourceSplit = sourcePlace.Split('-');
|
var toSplit = toPlace.Split('-');
|
|
bool b1 = this.WriteValue(this.OpcWriteItems.SrmNo, deviceId);
|
bool b2 = this.WriteValue(this.OpcWriteItems.TaskNo, taskId);
|
bool b3 = this.WriteValue(this.OpcWriteItems.SourcePosY, int.Parse(sourceSplit[2]));
|
bool b4 = this.WriteValue(this.OpcWriteItems.SourcePosX, int.Parse(sourceSplit[1]));
|
bool b5 = this.WriteValue(this.OpcWriteItems.SourcePosZ, int.Parse(sourceSplit[0]));
|
bool b6 = this.WriteValue(this.OpcWriteItems.DestinationPosY, int.Parse(toSplit[2]));
|
bool b7 = this.WriteValue(this.OpcWriteItems.DestinationPosX, int.Parse(toSplit[1]));
|
bool b8 = this.WriteValue(this.OpcWriteItems.DestinationPosZ, int.Parse(toSplit[0]));
|
bool b10 = this.WriteValue(this.OpcWriteItems.Command, 1);
|
bool b11 = this.WriteValue(this.OpcWriteItems.PalletType, palltype);//2代表大托盘1小托盘
|
bool b12 = this.WriteValue(this.OpcWriteItems.High, heighttype);//2代表大托盘1小托盘
|
|
if (!(b1 && b2 && b3 && b4 && b5 && b6 && b7 && b8 && b10&&b11&&b12))
|
{
|
msg = string.Format("向堆垛机{0}发送任务{1}失败", SrmName, taskId);
|
return false;
|
}
|
bool b9 = this.WriteValue(this.OpcWriteItems.Stb, 1);
|
if (b9)
|
{
|
return true;
|
}else
|
{
|
return false;
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "SendTask", msg);
|
return false;
|
}
|
}
|
/// <summary>
|
/// 移动任务
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="taskId"></param>
|
/// <param name="toPlace"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public bool SendMove(int deviceId, int taskId, string sourcePlace, string toPlace, out string msg)
|
{
|
try
|
{
|
msg = "";
|
if (!CanDoMove(deviceId, out msg))
|
{
|
return false;
|
}
|
var toSplit = toPlace.Split('-');
|
var sourSplit = sourcePlace.Split('-');
|
|
bool b1 = this.WriteValue(this.OpcWriteItems.SrmNo, deviceId);
|
bool b2 = this.WriteValue(this.OpcWriteItems.TaskNo, taskId);
|
bool b3 = this.WriteValue(this.OpcWriteItems.SourcePosY, int.Parse(sourSplit[2]));
|
bool b4 = this.WriteValue(this.OpcWriteItems.SourcePosX, int.Parse(sourSplit[1]));
|
bool b5 = this.WriteValue(this.OpcWriteItems.SourcePosZ, int.Parse(sourSplit[0]));
|
bool b6 = this.WriteValue(this.OpcWriteItems.DestinationPosY, int.Parse(toSplit[2]));
|
bool b7 = this.WriteValue(this.OpcWriteItems.DestinationPosX, int.Parse(toSplit[1]));
|
bool b8 = this.WriteValue(this.OpcWriteItems.DestinationPosZ, int.Parse(toSplit[0]));
|
bool b9 = this.WriteValue(this.OpcWriteItems.Stb, 1);
|
bool b10 = this.WriteValue(this.OpcWriteItems.Command, 1);
|
bool b11 = this.WriteValue(this.OpcWriteItems.PalletType, 2);//2代表大托盘1小托盘
|
bool b12 = this.WriteValue(this.OpcWriteItems.High, 1);//2代表大托盘1小托盘
|
if (!(b1 && b2 && b3 && b4 && b5 && b6 && b7 && b8 && b9 && b10))
|
{
|
msg = string.Format("向堆垛机{0}发送移动指令{1}失败", SrmName, taskId);
|
return false;
|
}
|
return true;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "SendMove", msg);
|
return false;
|
}
|
}
|
/// <summary>
|
/// 任务召回
|
/// </summary>
|
/// <param name="srmNo"></param>
|
/// <param name="taskId"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public bool SendCallBackTask(int deviceId, int taskId, out string msg)
|
{
|
try
|
{
|
msg = "";
|
|
if (!IsOnline)
|
{
|
msg = string.Format("堆垛机{0}不在线", this.SrmName);
|
return false;
|
}
|
|
if (RMode != (int)ESrmMode.自动模式)
|
{
|
msg = string.Format("堆垛机{0}非自动模式", this.SrmName);
|
return false;
|
}
|
|
if (RAlarm)
|
{
|
msg = string.Format("堆垛机{0}报警中", this.SrmName);
|
return false;
|
}
|
|
if (RLiftFull)
|
{
|
msg = string.Format("堆垛机{0}叉齿有货", this.SrmName);
|
return false;
|
}
|
|
if (RState != (int)ESrmState.空闲)
|
{
|
msg = string.Format("堆垛机{0}非空闲", this.SrmName);
|
return false;
|
}
|
bool b1 = this.WriteValue(this.OpcWriteItems.SrmNo, deviceId);
|
bool b2 = this.WriteValue(this.OpcWriteItems.TaskNo, taskId);
|
bool b3 = this.WriteValue(this.OpcWriteItems.Command, (int)ESrmCmd.召回);
|
if (!(b1 && b2 && b3))
|
{
|
msg = string.Format("向堆垛机{0}发送召回任务{1}失败", SrmName, taskId);
|
return false;
|
}
|
return true;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "SendCallBackTask", msg);
|
return false;
|
}
|
}
|
/// <summary>
|
/// 任务删除
|
/// </summary>
|
/// <param name="srmNo"></param>
|
/// <param name="taskId"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public bool SendDelTask(int deviceId, int taskId, out string msg)
|
{
|
try
|
{
|
msg = "";
|
|
//if (!IsOnline)
|
//{
|
// msg = string.Format("堆垛机{0}不在线", this.SrmName);
|
// return false;
|
//}
|
|
//if (RMode != (int)ESrmMode.自动模式)
|
//{
|
// msg = string.Format("堆垛机{0}非自动模式", this.SrmName);
|
// return false;
|
//}
|
|
//if (RState != (int)ESrmState.空闲)
|
//{
|
// msg = string.Format("堆垛机{0}非空闲", this.SrmName);
|
// return false;
|
//}
|
|
bool b1 = this.WriteValue(this.OpcWriteItems.SrmNo, deviceId);
|
bool b2 = this.WriteValue(this.OpcWriteItems.TaskNo, taskId);
|
bool b3 = this.WriteValue(this.OpcWriteItems.Command, (int)ESrmCmd.任务删除);
|
if (!(b1 && b2 && b3))
|
{
|
msg = string.Format("向堆垛机{0}发送召回任务{1}失败", SrmName, taskId);
|
return false;
|
}
|
return true;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "SendCallBackTask", msg);
|
return false;
|
}
|
}
|
/// <summary>
|
/// 是否可以发送出入库任务
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public bool CanSendTask(int deviceId, out string msg)
|
{
|
msg = "";
|
if (!IsOnline)
|
{
|
msg = string.Format("堆垛机{0}不在线", this.SrmName);
|
return false;
|
}
|
|
if (RMode != (int)ESrmMode.自动模式)
|
{
|
msg = string.Format("堆垛机{0}非自动模式", this.SrmName);
|
return false;
|
}
|
|
if (RAlarm)
|
{
|
msg = string.Format("堆垛机{0}报警中", this.SrmName);
|
return false;
|
}
|
|
if (RLiftFull)
|
{
|
msg = string.Format("堆垛机{0}叉齿有货", this.SrmName);
|
return false;
|
}
|
|
if (RState != (int)ESrmState.空闲)
|
{
|
msg = string.Format("堆垛机{0}非空闲", this.SrmName);
|
return false;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 是否可以发送移库任务
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public bool CanDoMove(int deviceId, out string msg)
|
{
|
msg = "";
|
if (!IsOnline)
|
{
|
msg = string.Format("堆垛机{0}不在线", this.SrmName);
|
return false;
|
}
|
|
if (RMode != (int)ESrmMode.自动模式)
|
{
|
msg = string.Format("堆垛机{0}非自动模式", this.SrmName);
|
return false;
|
}
|
|
if (RAlarm)
|
{
|
msg = string.Format("堆垛机{0}报警中", this.SrmName);
|
return false;
|
}
|
|
if (RLiftFull)
|
{
|
msg = string.Format("堆垛机{0}叉齿有货", this.SrmName);
|
return false;
|
}
|
|
if (RState != (int)ESrmState.空闲)
|
{
|
msg = string.Format("堆垛机{0}非空闲", this.SrmName);
|
return false;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 向设备写入指令
|
/// </summary>
|
/// <param name="p1"></param>
|
/// <param name="p2"></param>
|
/// <returns></returns>
|
public bool WriteValue(string addr, object value)
|
{
|
string msg = string.Empty;
|
if (!string.IsNullOrEmpty(addr))
|
{
|
try
|
{
|
if (!this.WS71500.IsConnected)
|
{
|
this.WS71500.Close();
|
Thread.Sleep(100);
|
this.WS71500.Open();
|
}
|
|
msg = this.WS71500.Write(addr, value).ToString();
|
if (msg != "NoError")
|
{
|
string msg1 = this.WS71500.Write(addr, value).ToString();
|
if (msg1 != "NoError")
|
{
|
this.WS71500.Close();
|
Thread.Sleep(100);
|
this.WS71500.Open();
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), this.SrmName + "WriteValue" + addr, msg);
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
else
|
{
|
return true;
|
}
|
}
|
catch
|
{
|
|
msg = addr + "写入失败 ";
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), this.SrmName + "WriteValue", msg);
|
return false;
|
}
|
}
|
else
|
{
|
msg = addr + "写入失败 ";
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), this.SrmName+"WriteValue", msg);
|
return false;
|
}
|
}
|
}
|
}
|