VerticalStoreBean_InOut.cs
18.4 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
using DeviceLib;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
partial class VerticalStoreBean
{
public bool WaitCanCloseDoor = false;
public bool CanCloseDoor = false;
private Stopwatch moveWatch = new Stopwatch();
#region 自动出入库参数
private int CurrInOutCount = 0;
private int CurrInOutACount = 0;
public List<string> PositionNumList = new List<string>();
public bool autoNext = false;
public int autoJiange = 3;
public int autoPositionIndex = 0;
public string autoMsg = "";
public int AutoStartIndex = -1;
#endregion
#region CheckWait
private void CheckWait()
{
List<WaitResultInfo> list = MoveInfo.WaitList;
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
string NotOkMsg = "";
if (list.Count <= 0)
{
MoveInfo.EndStepWait();
return;
}
bool isOk = true;
if (MoveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType == 1)
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = AxisBean.HomeMoveIsEnd(MoveInfo, wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = AxisBean.ACAxisMoveIsEnd(MoveInfo, wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(StoreAlarmType.AxisMoveError, wait.AxisInfo.ProName, WarnMsg, MoveInfo.MoveType);
break;
}
}
else if (wait.WaitType == 2)
{
wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
int timeOutMs = Config.IOSingle_TimerOut;
if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
{
ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + " 等待信号" + io.DisplayStr + "=" + wait.IoValue + "超时!";
Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(Name + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 14);
isOk = false;
break;
}
}
else if (wait.WaitType == 3)
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(7))
{
wait.IsEnd =( CanCloseDoor);
}
if (wait.IsEnd)
{
if (MoveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
}
else
{
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
if (isOk)
{
MoveInfo.EndStepWait();
}
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
{
WarnMsg = Name + "【" + MoveInfo.MoveType + "】【" + MoveInfo.MoveStep + "】等待超时 [" + NotOkMsg
+ "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 100);
Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnMsg, MoveInfo.MoveType);
}
}
#endregion
#region 入库
public override bool StartInStore(InOutParam param)
{
WaitCanCloseDoor = false;
param.paramType = MoveType.InStore;
string posId = param != null ? param.PosId : "";
if (runStatus.Equals(StoreRunStatus.Runing) && MoveInfo.MoveType.Equals(MoveType.None))
{
if (param.Position == null)
{
LogUtil.error(Name + " 启动 " + param.LogName + "失败,找不到库位信息");
return false;
}
LogUtil.info(Name + " 启动 " + param.LogName);
moveWatch.Restart();
runStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.InStoreExecute;
MoveInfo.NewMove(MoveType.InStore, param);
MoveInfo.NextMoveStep(StoreMoveStep.SI_01_Wait);
InStoreLog("开始入库:等待光栅未被遮挡");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SafetyLightCurtains, IO_VALUE.HIGH));
return true;
}
else
{
LogUtil.error(Name + " 启动 " + param.LogName + "出错,当前状态:[" + runStatus + "],[" + MoveInfo.MoveType + "]");
return false;
}
}
protected override void InStoreProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.IsStep(StoreMoveStep.SI_01_Wait))
{
MoveInfo.NextMoveStep(StoreMoveStep.SI_02_CloseDoor);
InStoreLog(" 关闭升降门,关闭所有灯");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
DoorBean.StartClose(MoveInfo);
LEDManager.GetLedModule(Config.LED_IP).AllLightOff();
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_02_CloseDoor))
{
MoveInfo.NextMoveStep(StoreMoveStep.SI_03_MiddleToP2);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
InStoreLog(" 旋转轴到P2点");
MiddleAxis.AbsMove(MoveInfo, MoveInfo.MoveParam.Position.MiddleAxis_P2, Config.MiddleAxis_P2_Speed);
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_03_MiddleToP2))
{
MoveInfo.NextMoveStep(StoreMoveStep.SI_04_OpenDoor);
InStoreLog(" 打开升降门,打开库位灯蓝色 ,更新状态为入仓完成 ");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
DoorBean.StartOpen(MoveInfo);
List<Light> lights = new List<Light>();
foreach(int index in MoveInfo.MoveParam.Position.GetLedList())
{
lights.Add(Light.BlueLight(MoveInfo.MoveParam.Position.LedDmx, index));
}
LEDManager.GetLedModule(Config.LED_IP).OnlyLightOn(lights.ToArray<Light>());
UpdateLastStatus(StoreStatus.InStoreEnd);
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_04_OpenDoor))
{
MoveInfo.NextMoveStep(StoreMoveStep.SI_05_WaitCloseDoor);
InStoreLog(" 等待关门 ");
WaitCanCloseDoor = true;
CanCloseDoor = false;
MoveInfo.WaitList.Add(WaitResultInfo.WaitCloseDoor());
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_05_WaitCloseDoor))
{
MoveInfo.NextMoveStep(StoreMoveStep.SI_06_CloseDoor);
InStoreLog(" 开始关门 ");
WaitCanCloseDoor = false;
CanCloseDoor = false;
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
DoorBean.StartClose(MoveInfo);
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_06_CloseDoor))
{
TimeSpan span = moveWatch.Elapsed;
moveWatch.Stop();
LogUtil.info(Name + " 【" + MoveInfo.MoveParam.LogName + "】 结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
MoveInfo.EndMove();
runStatus = StoreRunStatus.Runing;
//设备连接,入库后,BOX恢复原始状态
storeStatus = StoreStatus.StoreOnline;
InOutEndProcess(MoveType.InStore);
}
else
{
LogUtil.info(Name + " 入库," + MoveInfo.MoveStep + ",没有对应的处理!");
}
}
#endregion
#region 出库
public override bool StartOutStore(InOutParam param)
{
WaitCanCloseDoor = false;
param.paramType = MoveType.OutStore;
if (runStatus.Equals(StoreRunStatus.Runing) && MoveInfo.MoveType.Equals(MoveType.None))
{
if (param.Position == null)
{
LogUtil.error(Name + " 启动 " + param.LogName + "失败,找不到库位信息");
return false;
}
moveWatch.Restart();
LogUtil.info(Name + "启动 " + param.LogName + " ");
runStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.OutStoreExecute;
MoveInfo.NewMove(MoveType.OutStore, param);
MoveInfo.NextMoveStep(StoreMoveStep.SO_01_Wait);
InStoreLog("开始出库:等待光栅未被遮挡");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SafetyLightCurtains, IO_VALUE.HIGH));
return true;
}
else
{
LogUtil.error(Name + " 启动 " + param.LogName + "出错,当前状态:[" + runStatus + "],[" + MoveInfo.MoveType + "]");
return false;
}
}
protected override void OutStoreProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.IsStep(StoreMoveStep.SO_01_Wait))
{
MoveInfo.NextMoveStep(StoreMoveStep.SO_02_CloseDoor);
InStoreLog(" 关闭升降门,关闭所有灯");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
DoorBean.StartClose(MoveInfo);
LEDManager.GetLedModule(Config.LED_IP).AllLightOff();
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_02_CloseDoor))
{
MoveInfo.NextMoveStep(StoreMoveStep.SO_03_MiddleToP2);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
InStoreLog(" 旋转轴到P2点");
MiddleAxis.AbsMove(MoveInfo, MoveInfo.MoveParam.Position.MiddleAxis_P2, Config.MiddleAxis_P2_Speed);
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_03_MiddleToP2))
{
MoveInfo.NextMoveStep(StoreMoveStep.SO_04_OpenDoor);
InStoreLog(" 打开升降门,打开库位灯绿色 ,更新状态为出仓完成 ");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
DoorBean.StartOpen(MoveInfo);
List<Light> lights = new List<Light>();
foreach (int index in MoveInfo.MoveParam.Position.GetLedList())
{
lights.Add(Light.GreenLight(MoveInfo.MoveParam.Position.LedDmx, index));
}
LEDManager.GetLedModule(Config.LED_IP).OnlyLightOn(lights.ToArray<Light>());
UpdateLastStatus(StoreStatus.OutStoreBoxEnd);
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_04_OpenDoor))
{
MoveInfo.NextMoveStep(StoreMoveStep.SO_05_WaitCloseDoor);
InStoreLog(" 等待关门 ");
WaitCanCloseDoor = true;
CanCloseDoor = false;
MoveInfo.WaitList.Add(WaitResultInfo.WaitCloseDoor());
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_05_WaitCloseDoor))
{
MoveInfo.NextMoveStep(StoreMoveStep.SO_06_CloseDoor);
InStoreLog(" 开始关门 ");
WaitCanCloseDoor = false;
CanCloseDoor = false;
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
DoorBean.StartClose(MoveInfo);
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_06_CloseDoor))
{
TimeSpan span = moveWatch.Elapsed;
moveWatch.Stop();
LogUtil.info(Name + " 【" + MoveInfo.MoveParam.LogName + "】 结束,耗时【" + FormUtil.GetSpanStr(span) + "】!");
MoveInfo.EndMove();
runStatus = StoreRunStatus.Runing;
//设备连接,入库后,BOX恢复原始状态
storeStatus = StoreStatus.StoreOnline;
InOutEndProcess(MoveType.OutStore);
}
else
{
LogUtil.info(Name + " 出库," + MoveInfo.MoveStep + ",没有对应的处理!");
}
}
#endregion
public void SureCloseDoor()
{
if (MoveInfo.MoveType.Equals(MoveType.InStore) && MoveInfo.MoveStep.Equals(StoreMoveStep.SI_05_WaitCloseDoor))
{
CanCloseDoor = true;
}
else if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.MoveStep.Equals(StoreMoveStep.SO_05_WaitCloseDoor))
{
CanCloseDoor = true;
}
}
private void UpdateLastStatus(StoreStatus status)
{
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
lastPosId = posId;
lastPosIdStatus = status;
storeStatus = status;
LogUtil.info(Name + "更新 LastStatus [" + lastPosIdStatus + "] [" + lastPosId + "] ");
}
private void InOutEndProcess(MoveType storeMoveType)
{
try
{
CurrInOutCount++;
CurrInOutACount++;
//是否自动进入出库状态
if (!autoNext)
{
return;
}
if (storeMoveType.Equals(MoveType.InStore))
{
int newIndex = autoPositionIndex - 1;
if (newIndex < 0)
{
if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
{
newIndex = AutoStartIndex;
LogUtil.info(Name + "下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】");
}
else
{
autoNext = false;
autoMsg = "自动出入库结束!";
LogUtil.info(Name + "下一个索引不存在,自动 出入库结束!");
}
}
else
{
autoPositionIndex = newIndex;
string posid = PositionNumList[autoPositionIndex];
InOutParam newParam = new InOutParam(MoveType.OutStore, posid);
LogUtil.info(Name + "自动进入下一个出库:posid=" + posid);
autoMsg = "自动出库:" + posid;
StartOutStore(newParam);
}
}
else if (storeMoveType.Equals(MoveType.OutStore))
{
int newIndex = autoPositionIndex - autoJiange;
if (newIndex < 0)
{
if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
{
newIndex = AutoStartIndex;
LogUtil.info(Name + "下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】");
}
else
{
autoNext = false;
autoMsg = "自动出入库结束!";
LogUtil.info(Name + "下一个索引不存在,自动 出入库结束!");
}
}
else
{
string posid = PositionNumList[newIndex];
InOutParam newParam = new InOutParam(MoveType.InStore, posid, "AAAAA");
LogUtil.info(Name + "自动进入下一个入库:posid=" + posid);
autoMsg = "自动入库:" + posid;
StartInStore(newParam);
}
}
}
catch (Exception ex)
{
LogUtil.error(ex.ToString());
}
}
private void InStoreLog(string msg)
{
string LogName = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.LogName : "";
LogUtil.info("" + LogName + " ["+MoveInfo.MoveStep+"]" + msg);
}
private void OutStoreLog(string msg)
{
string LogName = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.LogName : "";
LogUtil.info("" + LogName + " [" + MoveInfo.MoveStep + "]" + msg);
}
private void ResetLog(string msg)
{
LogUtil.info(Name+" "+MoveInfo.MoveType+ " ["+MoveInfo.MoveStep+"] " + msg);
}
}
}