XiangdianOutStationExcute.cs
11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HHECS.Model;
using HHECS.Bll;
using HHECS.OPC;
using S7.Net;
namespace HHECS.Common
{
/// <summary>
/// todo:湘电出库站台处理类
/// </summary>
public class XiangdianOutStationExcute : IStationExcute
{
public EquipmentType EquipmentType { get; set; }
public BllResult Excute(List<Equipment> stations, List<Plc> plcs)
{
try
{
foreach(var station in stations)
{
//出库站台的处理逻辑:
//step1: 查看是否有出库请求
if(station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="RequestMessage").Value=="1")
{
//step2: 判断是否已经处理 06表示处理
if(station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="WCSReplyMessage").Value!="6")
{
//step3: 根据条码获取对应的任务类型、以及相应的任务状态
var tasksResult = AppSession.Bll.GetCommonModelByCondition<TaskEntity>($"where station={station.Code} and firstStatus = {(int)TaskEntityStatus.响应堆垛机库外放货任务完成}");
if(tasksResult.Success)
{
//step4: 回复PLC相关信息
TaskEntity taskEntity=tasksResult.Data[0];
if(taskEntity!=null)
{
List<EquipmentProp> propsToWriter = new List<EquipmentProp>();
//回复PLC考虑标志位 放置最后 控制数据传递的完整性
var number= station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="WCSReplyNumber");
number.Value=station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="RequestNumber").Value;//地址编码
var loadStatus= station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="WCSReplayLoadStatus");
loadStatus.Value=station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="RequestLoadStatus").Value;//装载状态
var barcode=station.EquipmentProps.Find(t=>t.EquipmentTypePropTemplateCode=="WCSReplayBarcode");
barcode.Value=taskEntity.ContainerCode;//容器条码
var weight = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyWeight");
weight.Value = "0";
var length = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyLength");
length.Value="0";//长
var width = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyWidth");
width.Value="0";//宽
var height = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyHeight");
height.Value="0";//高
var address = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyAddress");
address.Value=taskEntity.Port.ToString();//目标地址
var backup = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyBackUp");
backup.Value="0";//备用
var flag = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplayMessage");
flag.Value="6";//报文名称
propsToWriter.AddRange(new List<EquipmentProp>() { number, loadStatus,barcode,weight,length,width,height,address,backup,flag });
//判断是那个对应plc
Plc plc=plcs.FirstOrDefault(t=>t.IP==station.IP);
BllResult result=S7Helper.PlcSplitWrite(plc, propsToWriter, 20);
if(result.Success)// 写入成功后更新任务状态为
{
//todo: 后续更改
taskEntity.FirstStatus=(int)TaskEntityStatus.响应接出口站台地址请求;
AppSession.Bll.UpdateCommonModel<TaskEntity>(taskEntity);
LogExecute.WriteInfoLog(String.Format("任务ID:{0} 到达出库站台:{1} 即将去向出入库口:{2}处理并更新任务状态为:{3}",taskEntity.Id,taskEntity.Station,taskEntity.Port,taskEntity.FirstStatus));
}
}
else
{
LogExecute.WriteLog("出库站台",string.Format("获取站台{0}对应的请求任务转实体类失败",station.Code));
}
}
else
{
LogExecute.WriteLog("出库站台",string.Format("获取站台{0}对应的请求任务未查询到",station.Code));
}
}
}
//位置到达处理逻辑
// step1: 查看是否有位置到达信号请求
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveMessage").Value == "2")
{
//step2: 判断是否已经回复 08标识已回复
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKMessage").Value == "8")
{
//step3: 根据条码获取对应的任务类型、以及相应的任务状态
string containerCode = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveBarcode").Value;
var tasksResult = AppSession.Bll.GetCommonModelByCondition<TaskEntity>($"where containerCode={containerCode} and firstStatus = {(int)TaskEntityStatus.响应接出口站台地址请求}");
if (tasksResult.Success)
{
//step4: 回复PLC相关信息
TaskEntity taskEntity = tasksResult.Data[0];
if (taskEntity != null)
{
List<EquipmentProp> propsToWriter = new List<EquipmentProp>();
//判断是否成功
var AllcationAddress = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveAllcationAddress");
var ArriveResult = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveResult");
var ArriveRealAddress= station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveRealAddress");
if (ArriveResult.Value == "1")//成功
{
//回复PLC考虑标志位 放置最后 控制数据传递的完整性
var number = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKNumber");
number.Value = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveRealAddress").Value;//地址编码
var loadStatus = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKLoadStatus");
loadStatus.Value = "1";//装载状态 到达1 控制2
var backup = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyBackUp");
backup.Value = "0";//备用
var flag = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKMessage");
flag.Value = "8";//报文名称
propsToWriter.AddRange(new List<EquipmentProp>() { number, loadStatus, backup, flag });
//判断是那个对应plc
Plc plc = plcs.FirstOrDefault(t => t.IP == station.IP);
BllResult result = S7Helper.PlcSplitWrite(plc, propsToWriter, 20);
if (result.Success)// 写入成功后更新任务状态为
{
//todo: 后续更改
taskEntity.FirstStatus = (int)TaskEntityStatus.任务完成;
AppSession.Bll.UpdateCommonModel<TaskEntity>(taskEntity);
LogExecute.WriteInfoLog(String.Format("任务ID:{0} 到达出库站台:{1} 到达出入库口:{2}处理并更新任务状态为:{3}", taskEntity.Id, taskEntity.Station, taskEntity.Port, taskEntity.FirstStatus));
}
}
else if (ArriveResult.Value == "2")//失败 不是分拣线 不考虑
{
}
}
else
{
LogExecute.WriteLog("出库站台", string.Format("获取站台{0}对应的请求任务转实体类失败", station.Code));
}
}
else
{
LogExecute.WriteLog("出库站台", string.Format("获取站台{0}对应的请求任务未查询到", station.Code));
}
}
}
}
return BllResultFactory.Sucess();
}
catch(Exception ex)
{
Logger.Log($"出库站台处理过程中出现异常:{ex.Message}", LogLevel.Exception);
return BllResultFactory.Error();
}
}
}
}