StationInExcute.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
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
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
{
public class StationInExcute : StationExcute
{
public override BllResult Excute(List<Equipment> stations, OPCHelp plc)
{
foreach (var station in stations)
{
InnerExcute(station, plc);
}
return BllResultFactory.Sucess();
}
private void InnerExcute(Equipment station, OPCHelp plc)
{
//判断请求
//PLC有请求,但WCS没有,则WCS还没有响应
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestMessage").Value == "1" && station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyMessage").Value == "0")
{
//
var barcode = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestBarcode").Value;
if (string.IsNullOrWhiteSpace(barcode))
{
Logger.Log($"站台{station.Name}有地址请求但是没有条码信息", LogLevel.Error);
SendBack(station, plc, barcode);
return;
}
else
{
//获取任务
var taskResult = AppSession.Bll.GetCommonModelByCondition<TaskEntity>($"where containerCode = '{barcode}' and lastStatus < {TaskEntityStatus.任务完成.GetIndexInt()} and zoneCode = 'LK'");
if (taskResult.Success)
{
if (taskResult.Data.Count > 1)
{
Logger.Log($"站台{station.Name}根据条码{barcode}查找到了多条任务,请检查数据", LogLevel.Error);
SendBack(station, plc, barcode);
return;
}
else
{
var task = taskResult.Data[0];
var height = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestHeight").Value;
var weight = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWeight").Value;
if (task.Type == TaskType.整盘出库.GetIndexInt() || task.Type == TaskType.空容器出库.GetIndexInt())
{
Logger.Log($"站台{station.Name}不接受整盘出库和空托盘出库任务", LogLevel.Error);
SendBack(station, plc, barcode);
return;
}
//检测是否有去向库位,没有则请求
if (string.IsNullOrWhiteSpace(task.DestinationLocation))
{
var result = AppSession.Bll.GetDestinationLocation<string>(task.Id, height, weight);
if (result.Success)
{
task.DestinationLocation = result.Data;
string code = result.Data;
var locations = AppSession.Bll.GetCommonModelByCondition<Location>($"where `code` = '{code}' and type = 'L'");
if (!locations.Success || locations.Data.Count != 1)
{
//如果库位类型不对,那就是回退处理
Logger.Log($"站台{station.Name},任务{task.Id},获取去向地址:{result.Data}失败,记录数:{locations.Data.Count};请核查库位类型Type字段数据", LogLevel.Success);
SendBack(station, plc, barcode);
return;
}
Location location = locations.Data.First();
task.UserDef3 = location.UserDef1.ToString();
var a = AppSession.Bll.UpdateCommonModel<TaskEntity>(task);
if (a.Success)
{
Logger.Log($"站台{station.Name},任务{task.Id},获取去向地址:{result.Data}成功", LogLevel.Success);
}
else
{
Logger.Log($"站台{station.Name},任务{task.Id},获取去向地址:{result.Data}失败", LogLevel.Success);
SendBack(station, plc, barcode);
}
}
else
{
Logger.Log($"站台:{station.Name},任务{task.Id},未能获取到去向地址:{result.Msg}", LogLevel.Error);
SendBack(station, plc, barcode);
}
}
int tempStatus = task.FirstStatus; //记录原始状态以便回滚
//string weight = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWeight").Value;
//更新任务状态到60
task.FirstStatus = TaskEntityStatus.拣选台回库.GetIndexInt();
task.LastStatus = TaskEntityStatus.拣选台回库.GetIndexInt();
task.Weight = float.Parse(weight);
task.Port = station.BackAddress;// 入库口 没有指定的话 这里需要更新
task.Gateway = station.SelfAddress;
var temp = AppSession.Bll.UpdateCommonModel<TaskEntity>(task);
if (temp.Success)
{
//回复地址请求
temp = SendAddressReplyToPlc(station, plc, "6", "0", station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestNumber").Value,
barcode, weight, station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestLength").Value,
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWidth").Value,
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestHeight").Value, station.GoAddress, station.BackAddress);
if (temp.Success)
{
Logger.Log($"响应站台{station.Name}地址请求成功,条码:{barcode},任务:{task.Id},请进地址:{station.GoAddress}", LogLevel.Info);
//发送左侧LED
AppSession.SendLED(station, task);
return;
}
else
{
Logger.Log($"响应站台{station.Name}地址请求失败,条码{barcode},任务{task.Id},详情:{temp.Msg},回滚任务状态", LogLevel.Error);
task.FirstStatus = tempStatus;
task.LastStatus = tempStatus;
AppSession.Bll.UpdateCommonModel<TaskEntity>(task);
SendBack(station, plc, barcode);
return;
}
}
else
{
Logger.Log($"站台{station.Name},响应请求时更新任务{task.Id}状态失败。详情:{temp.Msg}", LogLevel.Error);
SendBack(station, plc, barcode);
return;
}
}
}
else
{
Logger.Log($"站台{station.Name}根据条码{barcode}没有查询到任务。", LogLevel.Error);
SendBack(station, plc, barcode);
return;
}
}
}
//PLC没有,WCS有,说明PLC已经清除而WCS没有清除
if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestMessage").Value == "0"
&& station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyMessage").Value == "6")
{
var result = SendAddressReplyToPlc(station, plc, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
if (result.Success)
{
Logger.Log($"站台{station.Name}响应地址请求完成后,清除WCS地址区成功", LogLevel.Info);
return;
}
else
{
Logger.Log($"站台{station.Name}响应地址请求完成后,清除WCS地址区失败", LogLevel.Error);
return;
}
}
#region 到达
////判断位置到达
////PLC有位置到达,而WCSACK没有回复,则WCS还没有响应
//if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveMessage").Value == "2" && station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKMessage").Value == "0")
//{
// Logger.Log($"此站台{station.Name}不处理位置到达", LogLevel.Error);
// return;
//}
////PLC没位置到达,而WCSACK有回复,则PLC已经响应但还没有清除
//if (station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "ArriveMessage").Value == "0" && station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKMessage").Value == "8" && station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKLoadStatus").Value == "1")
//{
// var result = SendAckToPlc(station, plc, "0", "0", "0", "0");
// if (result.Success)
// {
// Logger.Log($"站台{station.Name}响应位置到达完成后,清除WCS地址区成功", LogLevel.Info);
// return;
// }
// else
// {
// Logger.Log($"站台{station.Name}响应位置到达完成后,清除WCS地址区失败", LogLevel.Error);
// return;
// }
//}
#endregion
}
}
}