StationExecute.cs
10.3 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
using HaHRCS.Rcs.Executor.Enums;
using HaHRCS.Rcs.Model.Entities;
using HHECS.BllModel;
using HHECS.Communication;
using Rcs.Executor.PLC;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection.Metadata;
using System.Threading;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace HaHRCS.Rcs.Executor.PLC
{
/// <summary>
/// 站台顶层抽象类
/// </summary>
public abstract class StationExecute
{
#region 属性
/// <summary>
/// 用于标记站台的类型
/// </summary>
public EquipmentType EquipmentType { get; set; }
/// <summary>
/// 用于记录错误文本
/// </summary>
public string ErrorText { get; set; }
/// <summary>
/// 中控的http请求的head中的origin(中控的安全校验会校验head)
/// </summary>
public string origin;
/// <summary>
/// 中控的http请求的head中的referer(中控的安全校验会校验head)
/// </summary>
public string referer;
/// <summary>
/// 叫料的URL
/// </summary>
public string callMaterialUrl;
/// <summary>
/// 工位的叫料的处理结果
/// </summary>
Dictionary<string, List<string>> dicCallInfo = new Dictionary<string, List<string>>();
#endregion
protected StationExecute(EquipmentType equipmentType)
{
EquipmentType = equipmentType;
//this.origin= origin;
//this.referer = referer;
//this.callMaterialUrl = callMaterialUrl;
//this.dicCallInfo = dicCallInfo;
}
/// <summary>
/// 具体的站台实现逻辑
/// </summary>
/// <param name="stations"></param>
/// <param name="plcs"></param>
/// <returns></returns>
public virtual void Excute(List<Equipment> stations, EquipmentCommunicationHub equipmentCommunicationHub, List<Equipment> allEquipments)
{
try
{
foreach (var station in stations)
{
BllResult result = BllResultFactory.Success();
//var OperationModel = station[StationProps.OperationModel.ToString()];
//var TotalError = station[StationProps.TotalError.ToString()];
//if (OperationModel.Value != OperationModelFlag.Online.GetIndexString() || TotalError.Value != TotalErrorFlag.Normal.GetIndexString())
//{
// result = BllResultFactory.Create(BllResultCode.Info, $"处理工位【{station.WorkStationCode}】的设备【{station.Name}】失败,请保持设备的联机并且无故障");
// continue;
//}
#region 判断PLC地址请求
#region 清除放货信号
var PutRequest = station[StationProps.PutRequest.ToString()];
var PutRuning = station[StationProps.PutRuning.ToString()];
var PutDone = station[StationProps.PutDone.ToString()];
var PutConveyorReady = station[StationProps.PutConveyorReady.ToString()];
var AllowPut = station[StationProps.AllowPut.ToString()];
//放货
if (PutRequest != null && PutRuning != null && PutDone != null && PutConveyorReady != null && AllowPut !=null)
{
if (PutRequest.Value == "False" && PutRuning.Value == "False" && PutDone.Value == "True" && PutConveyorReady.Value == "False" && AllowPut.Value == "False")
{
//清除PutDone
result = ExcutePutClear(equipmentCommunicationHub, station);
}
else
{
BllResultFactory.Error("等待电气清除信号");
}
}
#endregion
#region 清除取货信号
//取货
var PickRequest = station[StationProps.PickRequest.ToString()];
var PickRuning =station[StationProps.PickRuning.ToString()];
var PickDone = station[StationProps.PickDone.ToString()];
var PickConveyorReady = station[StationProps.PickConveyorReady.ToString()];
var AllowPick = station[StationProps.AllowPick.ToString()];
if (PickRequest != null && PickRuning != null && PickDone != null && PickConveyorReady != null && AllowPick != null)
{
if (PickRequest.Value == "False" && PickRuning.Value == "False" && PickDone.Value =="True" && PickConveyorReady.Value == "False" && AllowPick.Value == "False")
{
result = ExcutePickClear(equipmentCommunicationHub,station);
}
else
{
BllResultFactory.Error("等待电气清除信号");
}
}
#region 清除缩回信号
var Retracted = station[CylinderProps.Retracted.ToString()];
if (Retracted != null)
{
if (Retracted.Value == "True")
{
result = ExcutConvingClear(equipmentCommunicationHub, station);
}
}
#endregion
var Extended = station[CylinderProps.Extended.ToString()];
if (Extended != null)
{
if (Extended.Value == "True")
{
result = ExcutConvingTClear(equipmentCommunicationHub, station);
}
}
#endregion
#endregion
}
}
catch (Exception ex)
{
BllResultFactory.Create(BllResultCode.Exception, ex, $"程序处理逻辑类出现异常:{ex.Message}", "Error04");
}
}
#region 实现逻辑的方法
/// <summary>
/// 放货信号完成清除信号
/// </summary>
/// <param name="plc"></param>
/// <param name="station"></param>
/// <returns></returns>
private BllResult ExcutePutClear(EquipmentCommunicationHub plc, Equipment station)
{
List<EquipmentProp> props = new List<EquipmentProp>();
SetStationPropList(props, station, StationProps.PutDone, "0");
return plc.Writes(props.ToArray());
}
/// <summary>
/// 取货信号完成清除信号
/// </summary>
/// <param name="plc"></param>
/// <param name="station"></param>
/// <returns></returns>
private BllResult ExcutePickClear(EquipmentCommunicationHub plc, Equipment station)
{
List<EquipmentProp> props = new List<EquipmentProp>();
SetStationPropList(props, station, StationProps.PickDone, "0");
return plc.Writes(props.ToArray());
}
/// <summary>
/// 缩回请求信号清除
/// </summary>
/// <param name="plc"></param>
/// <param name="station"></param>
/// <returns></returns>
private BllResult ExcutConvingClear(EquipmentCommunicationHub plc, Equipment station)
{
List<EquipmentProp> props = new List<EquipmentProp>();
SetStationPropListTo(props, station, CylinderProps.AirExtended, "0");
return plc.Writes(props.ToArray());
}
/// <summary>
/// 伸出请求信号清除
/// </summary>
/// <param name="plc"></param>
/// <param name="station"></param>
/// <returns></returns>
private BllResult ExcutConvingTClear(EquipmentCommunicationHub plc, Equipment station)
{
List<EquipmentProp> props = new List<EquipmentProp>();
SetStationPropListTo(props, station, CylinderProps.AirRetracted, "0");
return plc.Writes(props.ToArray());
}
/// <summary>
/// 设置设备属性列表
/// </summary>
/// <param name="list">设备属性列表</param>
/// <param name="station">设备</param>
/// <param name="propKey">要设置的属性Key</param>
/// <param name="propValue">要设置的属性值</param>
/// <param name="insert">是否用Inset插入到列表,默认为Add方法</param>
public void SetStationPropList(List<EquipmentProp> list, Equipment station, StationProps propKey, string propValue, bool insertFirst = false)
{
var propItem = station[propKey.ToString()];
if (propItem != null && propValue != null)
{
propItem.Value = propValue;
if (insertFirst)
{
list.Insert(0, propItem);
}
else
{
list.Add(propItem);
}
}
}
/// <summary>
/// 设置设备属性列表
/// </summary>
/// <param name="list">设备属性列表</param>
/// <param name="station">设备</param>
/// <param name="propKey">要设置的属性Key</param>
/// <param name="propValue">要设置的属性值</param>
/// <param name="insert">是否用Inset插入到列表,默认为Add方法</param>
public void SetStationPropListTo(List<EquipmentProp> list, Equipment station, CylinderProps propKey, string propValue, bool insertFirst = false)
{
var propItem = station[propKey.ToString()];
if (propItem != null && propValue != null)
{
propItem.Value = propValue;
if (insertFirst)
{
list.Insert(0, propItem);
}
else
{
list.Add(propItem);
}
}
}
#endregion
}
}