StationForStockerOutExcute.cs
8.47 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HHECS.Bll;
using HHECS.Model;
using HHECS.Model.BllModel;
using HHECS.Model.Common;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using HHECS.OPC;
using S7.Net;
namespace HHECS.EquipmentExcute
{
/// <summary>
/// 标准堆垛机接出站台处理
/// </summary>
public class StationForStockerOutExcute : StationExcute
{
private List<Equipment> equipments = null;
public override BllResult Excute(List<Equipment> equipments, OPCHelp plc)
{
this.equipments = equipments;
List<Equipment> stations = equipments.Where(x => x.EquipmentType.Id == this.EquipmentType.Id).ToList();
foreach (var station in stations)
{
InnerExcute(station, plc);
}
return BllResultFactory.Sucess();
}
private void InnerExcute(Equipment station, OPCHelp plc)
{
//如果PLC标记为3,则表示解析有误,这里报警
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Flag").Value == "3")
{
Logger.Log("PLC解析站台" + station.Name + "数据失败,请检查基础数据!", LogLevel.Error);
return;
}
//PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Flag").Value == "1" &&
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFlag").Value == "1")
{
return;
}
//PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Flag").Value != "1" &&
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFlag").Value == "1")
{
var result = WriteWCSStationDataAddress(station, plc, "0", "0", "0", "0", "0", "0", "", "0", "0");
if (result.Success)
{
Logger.Log("清空" + station.Name + "WCS区地址成功", LogLevel.Success);
}
else
{
Logger.Log("清空" + station.Name + "WCS区地址失败:" + result.Msg, LogLevel.Error);
}
return;
}
//PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC
//加入地址校验,防止PLC写入与WCS读取冲突;堆垛机接出站台,地址请求时时没有带条码的,需要我们写入
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Flag").Value == "1"
&& station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFlag").Value != "1"
&& station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Type").Value != "0"
&& station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "PLCNo").Value != "0"
&& station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "StationNo").Value != "0"
)
{
//判断报文类型
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Type").Value == "1")
{
//表示地址请求
//hack:假设没有移库任务
//获取任务状态为35的任务
var taskResult = AppSession.Bll.GetCommonModelByCondition<TaskEntity>($"where lastStatus = {TaskEntityStatus.响应堆垛机库外放货任务完成.GetIndexInt()}");
if (!taskResult.Success)
{
Logger.Log("未找到【" + station.Name + "】站台对应状态为【响应堆垛机库外放货任务完成】的任务,无法响应地址请求", LogLevel.Error);
return;
}
int roadWay = Convert.ToInt32(station.RoadWay);
string palletCode = "";
TaskEntity task = null;
foreach (var item in taskResult.Data)
{
var locationResult = AppSession.Bll.GetAllLocations(item.ContainerCode, null, null, null, null, null, null);
if (locationResult.Success)
{
var locationEntity = locationResult.Data[0];
if (locationEntity.Roadway == roadWay)
{
//说明这个任务是这个巷道的,则获取他的托盘号
palletCode = item.ContainerCode;
task = item;
break;
}
}
}
if (string.IsNullOrEmpty(palletCode))
{
Logger.Log("未找到【" + station.Name + "】站台对应的任务所对应的托盘号,无法响应地址请求", LogLevel.Error);
return;
}
//判断是不是移库,如果是移库则是去堆垛机接入站台
if (task.Type == 800)
{
//todo:移库堆垛机接入站台处理
}
else
{
int flag = 0;
if (task.Type == TaskType.整盘出库.GetIndexInt() || task.Type == TaskType.空容器出库.GetIndexInt())
{
flag = 1;
}
//获取一个站台
var equipment = equipments.FirstOrDefault(x => x.EquipmentType.Code == "StationOut" || x.EquipmentType.Code == "StationInOrOut");
if (equipment != null)
{
var plcNo = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "PLCNo").Value;
var stationNo = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "StationNo").Value;
var taskNo = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "TaskNo").Value;
//写入响应数据
var result = WriteWCSStationDataAddress(station, plc, "1", "6", plcNo, "0", stationNo, taskNo, palletCode, equipment.SelfAddress.ToString(), flag.ToString());
if (result.Success)
{
//更新任务状态为28,表示这条任务已经响应了地址请求
AppSession.Bll.SetTaskStatus(task.Id, TaskEntityStatus.响应接出口站台地址请求.GetIndexInt());
Logger.Log("写入" + station.Name + "WCS区地址成功", LogLevel.Success);
}
else
{
Logger.Log("写入" + station.Name + "WCS区地址失败:" + result.Msg, LogLevel.Error);
}
}
else
{
Logger.Log("未找到出库站台", LogLevel.Error);
}
}
}
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Type").Value == "2")
{
//地址请求
Logger.Log("堆垛机接入站台" + station.Name + "暂时没有实现位置到达请求", LogLevel.Warning);
return;
}
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Type").Value == "3")
{
//地址请求
Logger.Log("堆垛机接入站台" + station.Name + "暂时没有实现控制指令请求", LogLevel.Warning);
return;
}
}
}
}
}