XiangdianStockerExcute.cs
11.8 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HHECS.Bll;
using HHECS.Model;
using HHECS.OPC;
using S7.Net;
namespace HHECS.Common
{
/// <summary>
/// todo:湘电单叉双伸位堆垛机处理函数
/// </summary>
public class XiangdianStockerExcute : IStockerExcute
{
#region 接口实现
/// <summary>
/// 标记这个堆垛机处理类所处理的设备类型
/// </summary>
public EquipmentType EquipmentType { get; set; }
public BllResult Excute(List<Equipment> stockers, List<Plc> plcs)
{
try
{
foreach (var stocker in stockers)
{
//一般根据堆垛机的位置来决定是否执行入库任务 hack:这里默认堆垛机在站台旁时列为0
if (stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "CurrentColumn").Value == "0")
{
//先处理入库
ExcuteTaskIn(stocker, plcs.Find(t => t.IP == stocker.IP));
}
//处理出库
ExcuteTaskOut(stocker, plcs.Find(t => t.IP == stocker.IP));
//先处理入库
ExcuteTaskIn(stocker, plcs.Find(t => t.IP == stocker.IP));
//处理巷道内移库
ExcuteTaskTransferInRoadway(stocker, plcs.Find(t => t.IP == stocker.IP));
//处理堆垛机任务完成
ExcuteTaskComplete(stocker, plcs.Find(t => t.IP == stocker.IP));
//任务下发错误处理
ExcuteTaskError(stocker, plcs.Find(t => t.IP == stocker.IP));
}
return BllResultFactory.Sucess();
}
catch (Exception ex)
{
Logger.Log($"堆垛机处理过程中出现异常:{ex.Message}", LogLevel.Exception);
return BllResultFactory.Error();
}
}
public BllResult ExcuteTaskError(Equipment stocker, Plc plc)
{
throw new NotImplementedException();
}
public BllResult ExcuteTaskComplete(Equipment stocker, Plc plc)
{
throw new NotImplementedException();
}
public BllResult ExcuteTaskIn(Equipment stocker, Plc plc)
{
try
{
//校验入库条件
if (ValidateStockerIn(stocker).Success)
{
//找出入库状态的任务
var tasksResult = AppSession.Bll.GetCommonModelByCondition<TaskEntity>($"where status = {(int)TaskEntityStatus.响应接入口位置到达}");
if (tasksResult.Success)
{
//找出同巷道的任务
var locationsResult = AppSession.Bll.GetAllLocations(null, null, null, null, stocker.RoadWay, null, null);
if (locationsResult.Success)
{
var task = tasksResult.Data.FirstOrDefault(t => locationsResult.Data.Count(a => a.Code == t.DestinationLocation) > 0);
if (task != null)
{
var location = locationsResult.Data.Find(t => t.Code == task.DestinationLocation);
//todo:说明找到了则下发
BllResult sendResult = SendTaskToStocker(stocker,plc,"1","3","0","0","0",task.Station.ToString(),task.Id.ToString());
if (sendResult.Success)
{
//更改任务状态
//手动标记堆垛机为不可用状态,以免被再次响应
}
else
{
//记录日志
}
}
}
}
}
return BllResultFactory.Sucess();
}
catch (Exception ex)
{
Logger.Log($"堆垛机{stocker.Name}处理[入库任务]过程中出现异常:{ex.Message}", LogLevel.Exception);
return BllResultFactory.Error();
}
}
private BllResult SendTaskToStocker(Equipment stocker,Plc plc, string forkAction,string forkTaskFlag,string forkRow,string forkColumn,string forkLayer,string forkStation,string taskNo)
{
try
{
List<EquipmentProp> propsToWriter = new List<EquipmentProp>();
var props = stocker.EquipmentProps;
var action = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSForkAction");
action.Value = forkAction;
var taskFlag = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1TaskFlag");
taskFlag.Value = forkTaskFlag;
var row = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Row");
row.Value = forkRow;
var column = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Column");
column.Value = forkColumn;
var layer = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Layer");
layer.Value = forkLayer;
var station = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Station");
station.Value = forkStation;
var task = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Task");
task.Value = taskNo;
propsToWriter.AddRange(new List<EquipmentProp>() { action, taskFlag,row,column,layer,station,task });
return S7Helper.PlcSplitWrite(plc, propsToWriter, 20);
}
catch (Exception ex)
{
return BllResultFactory.Error($"下发任务出现异常:{ex.Message}");
}
}
public BllResult ExcuteTaskOut(Equipment stocker, Plc plc)
{
throw new NotImplementedException();
}
public BllResult ExcuteTaskTransferInRoadway(Equipment stocker, Plc plc)
{
throw new NotImplementedException();
}
public BllResult ValidateStockerForCompleteTask(Equipment stocker)
{
throw new NotImplementedException();
}
public BllResult ValidateStockerIn(Equipment stocker)
{
try
{
//判断条件,这里没有判断货叉故障和堆垛机故障,这特么怎么判断,这么多字段
//1.操作模式 = 5 联机;
//2.双货叉原位,任务货叉上无货;
//3.任务货叉无故障无任务;
//4.堆垛机无故障
//5.对应货叉任务类型:0 - 无任务
//6.对应货叉任务标志:1待机
//WCS交换区无任务
if (stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "OperationModel").Value == "5" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1ForkHasPallet").Value == "False" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskNo").Value == "0" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskType").Value == "0" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskExcuteStatus").Value == "1"&& stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1TaskFlag").Value == "0")
{
return BllResultFactory.Sucess();
}
else
{
return BllResultFactory.Error();
}
}
catch (Exception ex)
{
Logger.Log($"校验堆垛机{stocker.Name}入库条件异常:{ex.Message}", LogLevel.Exception);
return BllResultFactory.Error();
}
}
public BllResult ValidateStockerOut(Equipment stocker)
{
try
{
//判断条件,这里没有判断货叉故障和堆垛机故障,这特么怎么判断,这么多字段
//1.操作模式:5 联机;
//2.任务限制:不等于3;
//3.双货叉原位,任务货叉上有货;
//4.任务货叉无故障无任务;
//5.堆垛机无故障
//5.对应货叉任务类型:0 - 无任务
//6.对应货叉任务标志:1待机
if (stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "OperationModel").Value == "5" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1ForkHasPallet").Value == "False" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskNo").Value == "0" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskType").Value == "0" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskExcuteStatus").Value == "1" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "TaskLimit").Value != "3"&& stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1TaskFlag").Value == "0")
{
return BllResultFactory.Sucess();
}
else
{
return BllResultFactory.Error();
}
}
catch (Exception ex)
{
Logger.Log($"校验堆垛机{stocker.Name}出库条件异常:{ex.Message}", LogLevel.Exception);
return BllResultFactory.Error();
}
}
public BllResult ValidateStockerTransferInRoadway(Equipment stocker)
{
try
{
//这个同巷道内的移库任务,判断条件与出库一致
//判断条件,这里没有判断货叉故障和堆垛机故障,这特么怎么判断,这么多字段
//1.操作模式:5 联机;
//2.任务限制:不等于3;
//3.双货叉原位,任务货叉上有货;
//4.任务货叉无故障无任务;
//5.堆垛机无故障
//5.对应货叉任务类型:0 - 无任务
//6.对应货叉任务标志:1待机
if (stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "OperationModel").Value == "5" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1ForkHasPallet").Value == "False" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskNo").Value == "0" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskType").Value == "0" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Fork1TaskExcuteStatus").Value == "1" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "TaskLimit").Value != "3" && stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1TaskFlag").Value == "0")
{
return BllResultFactory.Sucess();
}
else
{
return BllResultFactory.Error();
}
}
catch (Exception ex)
{
Logger.Log($"校验堆垛机{stocker.Name}移库条件异常:{ex.Message}", LogLevel.Exception);
return BllResultFactory.Error();
}
}
#endregion
}
}