MainMachine.cs
29.6 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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace DeviceLibrary
{
public partial class MainMachine : IRobot
{
public bool LoadOk = false;
public string Name { get; set; } = "OutBound";
private bool _canRunning = true;
public bool canRunning
{
get { return _canRunning; }
set
{
if (_canRunning != value) {
Msg.setlogones();
}
_canRunning = value;
}
}
public bool isBusy { get; set; } = false;
public bool isAlarm { get; set; } = false;
public RunStatus runStatus { get; set; } = RunStatus.Stop;
public Robot_Config Config { get; set; }
public bool UserPause { get; set; } = false;
public MoveInfo ResetMoveInfo;
public MoveInfo StoreMoveInfo;
public MoveInfo AIOTMoveInfo;
public delegate void ProcessMsg(List<Msg> msg);
public event ProcessMsg ProcessMsgEvent;
public event EventHandler<ErrInfo> ButtenEvent;
internal AxisBean Middle_Axis;
public AxisBean UpDown_Axis;
internal AxisBean InOut_Axis;
internal AxisBean Comp_Axis;
ReelTransport boxTransport;
public bool boxTransportIsFree { get => boxTransport.IsComplateOrFree; }
public event Action<string, StoreMoveType, bool> InOutEndProcessEvent;
public ServerCommunication ServerCM;
//string CID = ServerCommunication.CID;
/// <summary>
/// 开始运行的时间
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
public List<InReelBean> inReelBeans = new List<InReelBean>();
public Dictionary<string, OutShelfBean> outShelfBeans = new Dictionary<string, OutShelfBean>();
public Dictionary<string, ReelParam> NgPosMap = new Dictionary<string, ReelParam>();
public MainMachine(Robot_Config _config) {
Config = _config;
Name = "出料机构";
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
StoreMoveInfo = new MoveInfo("移库调度");
StoreMoveInfo.SetStateDelegate(StoreState);
ResetMoveInfo = new MoveInfo("重置");
AIOTMoveInfo = new MoveInfo("移库测试");
ServerCM = new ServerCommunication();
//ServerCM.InStoreEvent += ServerCM_InStoreEvent1;
//ServerCM.OutStoreEvent += ServerCM_OutStoreEvent;
#region 初始化led灯
RunningLed = new Led(Config.DOList[IO_Type.Run_Led].GetIOAddr(),LedColor.green);
StandbyLed = new Led(Config.DOList[IO_Type.Standby_Led].GetIOAddr(), LedColor.yellow);
AlarmLed = new Led(Config.DOList[IO_Type.Alarm_Led].GetIOAddr(), LedColor.red);
#endregion
#region 初始化伺服轴
Middle_Axis = new AxisBean(Config.Middle_Axis, Name);
Middle_Axis.ForceSafeCheck = true;
Middle_Axis.interference += Middle_Axis_interference;
UpDown_Axis = new AxisBean(Config.UpDown_Axis, Name);
UpDown_Axis.interference += UpDown_Axis_interference;
InOut_Axis = new AxisBean(Config.InOut_Axis, Name);
InOut_Axis.ForceSafeCheck = true;
InOut_Axis.interference += InOut_Axis_interference;
Comp_Axis = new AxisBean(Config.Comp_Axis, Name);
Crc_LanguageChangeEvent(null, EventArgs.Empty);
#endregion
boxTransport = new ReelTransport(Config, this);
boxTransport.InOutEndProcessEvent += delegate (string posid, StoreMoveType storeMoveType, bool arg4)
{
InOutEndProcessEvent?.Invoke(posid, storeMoveType, arg4);
};
AlarmBuzzer.SetOnOffAction(() =>{ IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.HIGH); }, () => { IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.LOW); });
IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, Reset_BTN, 2500,100);
IOMonitor.RegisterIO(IO_Type.Reset_BTN, Config, IO_VALUE.HIGH, HomeReset_BTN, 2500, 3000);
//NG门打开又关闭后,需要清空NG库位信息
IOMonitor.RegisterIO(IO_Type.Left_NGDoor_Close_Check, Config,IO_VALUE.LOW, LeftNgDoorOpen, 2500, 500);
IOMonitor.RegisterIO(IO_Type.Right_NGDoor_Close_Check, Config, IO_VALUE.LOW, RightNgDoorOpen, 2500, 500);
for(int i = 1; i <= 2; i++)
{
InReelBean inReel = new InReelBean("IN_"+i);
inReelBeans.Add(inReel);
}
outShelfBeans.Add("U1", new OutShelfBean("U1", Config.RFID_U1));
outShelfBeans.Add("U2", new OutShelfBean("U2", Config.RFID_U2));
outShelfBeans.Add("U3", new OutShelfBean("U3", Config.RFID_U3));
outShelfBeans.Add("U4", new OutShelfBean("U4", Config.RFID_U4));
LedProcessInit();
LoadOk = true;
}
public OutShelfBean getOutShelf(string name)
{
OutShelfBean result = null;
outShelfBeans.TryGetValue(name, out result);
return result;
}
public InReelBean getInReelBean(string name)
{
foreach(InReelBean inReel in inReelBeans)
{
if (inReel.Name.Equals(name))
{
return inReel;
}
}
return null;
}
//private void ServerCM_OutStoreEvent(JobInfo jobInfo)
//{
// AddOutStoreTask(jobInfo.WareNum, jobInfo.PosId, jobInfo.plateW, jobInfo.plateH);
//}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
StoreMoveInfo.Name = crc.GetString(L.store_manage_equipment, "进出库调度");
ResetMoveInfo.Name = crc.GetString(L.reset_equipment, "重置");
AIOTMoveInfo.Name = crc.GetString(L.autotest_inout_equipment, "出入库测试");
}
private (bool, string) InOut_Axis_interference(int from, int to)
{
return (false, "");
}
private (bool, string) Middle_Axis_interference(int from, int to)
{
if (RobotManage.DisableUpdownProtect)
return (false, "");
if (InOut_Axis.IsInPosition(Config.InOut_P1))
return (false, "");
return (true, crc.GetString(L.Middle_Axis_interference_01, "进出轴不在待机点时无法移动旋转轴"));
}
private (bool, string) UpDown_Axis_interference(int from, int to)
{
if (RobotManage.DisableUpdownProtect)
return (false, "");
if (InOut_Axis.IsInPosition(Config.InOut_P1))
return (false, "");
return (true, crc.GetString(L.UpDown_Axis_interference_01, "进出轴不在待机点时无法移动升降轴"));
}
public bool hasAlarm = false;
/// <summary>
/// 整机启动变量,设置为false后将退出线程,只在停止时调用
/// </summary>
bool mstart=true;
public void Run() {
mstart = true;
while (mstart) {
try
{
canRunning = DeviceCheck();
if (canRunning)
{
BtnProcess();
canRunning = SafeCheck();
}
Thread.Sleep(200);
if (!canRunning || !mstart)
continue;
if (runStatus == RunStatus.Running)
{
ioMonitor();
boxTransport.Process();
if (RobotManage.InoutDebugMode)
AutoInOutTestProcess();
else
StoreProcess();
foreach(InReelBean bean in inReelBeans)
{
bean.Process();
}
foreach (OutShelfBean bean in outShelfBeans.Values)
{
bean.Process();
}
ShelfEmptyProcess();
}
else if (runStatus == RunStatus.HomeReset)
{
HomeReset();
}
}
catch (Exception ex)
{
Msg.add(ex.ToString(), MsgLevel.warning);
Msg.setlogones();
}
finally {
var m = Msg.get();
ProcessMsgEvent?.Invoke(m);
ServerCM.ProcessMsg(m);
StoreStatus currnetstoreStatus= StoreStatus.None;
if (m.Find((aa) => aa.msgLevel == MsgLevel.alarm) == null)
{
hasAlarm = false;
AlarmBuzzer.OFF();
if (ServerCM.storeStatus != StoreStatus.InStoreExecute
&& ServerCM.storeStatus != StoreStatus.OutStoreExecute
&& ServerCM.storeStatus != StoreStatus.ResetMove && ServerCM.storeStatus != StoreStatus.StoreOnline)
{
LogUtil.info($"test storeStatus is {ServerCM.storeStatus} change to StoreOnline");
currnetstoreStatus = StoreStatus.StoreOnline;
}
}
else {
hasAlarm = true;
AlarmBuzzer.ON();
currnetstoreStatus = isInSuddenDown ? StoreStatus.SuddenStop : StoreStatus.Warning;
}
//ProcessMoveinfoEvent?.Invoke(MoveInfo.List);
if (!UserPause)
Msg.clear();
else
currnetstoreStatus = StoreStatus.Debugging;
if (currnetstoreStatus!=StoreStatus.None)
ServerCM.storeStatus = currnetstoreStatus;
}
}
ServerCM.storeStatus = StoreStatus.None;
LogUtil.info("主线程已退出.");
}
public void Start() {
ServerCM.StartConnectServer();
Run();
}
public void Stop() {
mstart = false;
SafetyDevice.PauseAll();
AutoInOutTest = false;
ServerCM.StopConnectServer();
Thread.Sleep(300);
Alarm(AlarmType.None);
StopMove(true);
LedProcess(null);
}
public bool BeginHomeReset(bool firstRun=false) {
if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
Msg.add("急停未开,回原失败", MsgLevel.alarm, ErrInfo.SuddenStop);
return false;
}
if (!firstRun)
{
StopMove();
Thread.Sleep(500);
}
OpenAllServo();
boxTransport.Unlock();
Alarm(AlarmType.None);
runStatus = RunStatus.HomeReset;
ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
ResetMoveInfo.log("开始回原");
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
foreach (InReelBean bean in inReelBeans)
{
bean.Reset();
}
foreach (OutShelfBean bean in outShelfBeans.Values)
{
bean.Reset();
}
return true;
}
//强制回原
bool forceHome=true;
void HomeReset()
{
if (CheckWait(ResetMoveInfo))
return;
switch (ResetMoveInfo.MoveStep)
{
case MoveStep.H01_HomeReset:
ResetMoveInfo.log("开始回原");
ServerCM.storeStatus = StoreStatus.ResetMove;
Msg.add("", MsgLevel.info, ErrInfo.X09_Clear);
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset_01);
break;
case MoveStep.H02_HomeReset_01:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
ResetMoveInfo.log("进出轴 回原 ");
InOut_Axis.HomeMove(ResetMoveInfo, forceHome);
break;
case MoveStep.H02_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
break;
case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H04_HomeReset);
ResetMoveInfo.log("旋转轴,升降轴,回原,料叉P1待机点");
InOut_Axis.AbsMove(ResetMoveInfo, Config.InOut_P1, Config.InOut_P1_speed);
Middle_Axis.HomeMove(ResetMoveInfo, forceHome);
UpDown_Axis.HomeMove(ResetMoveInfo, forceHome);
break;
case MoveStep.H04_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
break;
case MoveStep.H05_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H06_HomeReset);
ResetMoveInfo.log("旋转轴,升降轴,到P1待机点");
Middle_Axis.AbsMove(ResetMoveInfo, Config.Middle_P1, Config.Middle_P1_speed);
UpDown_Axis.AbsMove(ResetMoveInfo, Config.UpDown_P1, Config.UpDown_P1_speed);
break;
case MoveStep.H06_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H07_HomeReset);
ResetMoveInfo.log("压紧轴回原");
Comp_Axis.HomeMove(ResetMoveInfo, forceHome);
break;
case MoveStep.H07_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H08_HomeReset);
ResetMoveInfo.log("旋转轴,升降轴,到P2,压紧轴p1");
Comp_Axis.AbsMove(ResetMoveInfo, Config.Comp_P1, Config.Comp_P1_speed);
break;
case MoveStep.H08_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H09_HomeReset);
var TrayCheck_Fixture = IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH);
if (TrayCheck_Fixture)
{
//ResetMoveInfo.log($"回原时检测到又滞留物料:TrayCheck_Fixture={TrayCheck_Fixture}");
//StoreMoveInfo.MoveParam.TargetPos = Setting_Init.Runtime_PosID;
//StoreMoveInfo.MoveParam.PlateH = Setting_Init.Runtime_PlateH;
//StoreMoveInfo.MoveParam.PlateW = Setting_Init.Runtime_PlateW;
//StoreMoveInfo.MoveParam.WareCode = Setting_Init.Runtime_WareCode;
//StoreMoveInfo.MoveParam.IsNg = Setting_Init.Runtime_IsNg;
//StoreMoveInfo.MoveParam.NgMsg = Setting_Init.Runtime_NgMsg;
//if (Setting_Init.Runtime_IsInStore)
//{
// ResetMoveInfo.log("入库物料:" + StoreMoveInfo.MoveParam.ToStr());
// if (TrayCheck_Fixture)
// StoreMoveInfo.MoveParam.ReelOnFixture = true;
// StoreMoveInfo.NextMoveStep(MoveStep.StoreIn02);
//}
//else if (TrayCheck_Fixture)
//{
// ResetMoveInfo.log("出库物料在料叉上:" + StoreMoveInfo.MoveParam.ToStr());
// StoreMoveInfo.MoveParam.ReelOnFixture = true;
// StoreMoveInfo.NextMoveStep(MoveStep.StoreOut10);
//}
//else
//{
// ResetMoveInfo.log("出库物料在门口:" + StoreMoveInfo.MoveParam.ToStr());
// StoreMoveInfo.NextMoveStep(MoveStep.StoreOut_WaitMT);
//}
}
//else if (!string.IsNullOrEmpty(Setting_Init.Runtime_PlateInFix.Val)) {
// var ac = CSVPositionReader<ACStorePosition>.GetPositon(StoreMoveInfo.MoveParam.TargetPos);
// var dc = CSVPositionReader<ACStorePosition>.GetPositon(Setting_Init.Runtime_PlateInFix);
// boxTransport.Start(new BoxStorePosition(Config, dc, StoreMoveInfo.MoveParam), new BoxStorePosition(Config, ac, StoreMoveInfo.MoveParam), StoreMoveType.InStore, true);
// ResetMoveInfo.log($"开始转运料盘:{Setting_Init.Runtime_PlateInFix}=>{StoreMoveInfo.MoveParam.TargetPos}");
// StoreMoveInfo.NextMoveStep(MoveStep.StoreOut11);
//}
//else
{
StoreMoveInfo.NewMove(MoveStep.Wait);
}
forceHome = false;
boxTransport.Reset();
ResetMoveInfo.log("回原完成");
ResetMoveInfo.EndMove();
runStatus = RunStatus.Running;
ServerCM.storeStatus = StoreStatus.StoreOnline;
break;
case MoveStep.H09_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H10_HomeReset);
break;
case MoveStep.H10_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H11_HomeReset);
break;
case MoveStep.H14_HomeReset:
break;
case MoveStep.H15_HomeReset:
break;
case MoveStep.H16_HomeReset:
break;
case MoveStep.HEND_HomeReset:
forceHome = false;
StoreMoveInfo.NewMove(MoveStep.Wait);
boxTransport.Reset();
ResetMoveInfo.log("回原完成");
ResetMoveInfo.EndMove();
runStatus = RunStatus.Running;
ServerCM.storeStatus = StoreStatus.StoreOnline;
break;
}
}
bool _IgnoreSafecheck = false;
public bool IgnoreSafecheck
{
get => _IgnoreSafecheck; set
{
_IgnoreSafecheck = value;
}
}
public bool IgnoreGratingSignal = false;
bool lastSafeCheckStatus = true;
bool SafeCheck() {
bool ok = true;
var ignorestring = "[" + crc.GetString(L.ignored, "已忽略") + "]";
if (IOValue(IO_Type.Left_NGDoor_Close_Check).Equals(IO_VALUE.LOW))
{
if (!IgnoreSafecheck)
{
ok = false;
DeviceSuddenStop();
UserPause = true;
}
Msg.add("左侧NG料门没有关闭" + (ok ? ignorestring : ""), MsgLevel.alarm);
}
if (IOValue(IO_Type.Right_NGDoor_Close_Check).Equals(IO_VALUE.LOW))
{
if (!IgnoreSafecheck)
{
ok = false;
DeviceSuddenStop();
UserPause = true;
}
Msg.add("右侧NG料门没有关闭" + (ok ? ignorestring : ""), MsgLevel.alarm);
}
if (!lastSafeCheckStatus && ok)
{
SafetyDevice.ResumeAll();
}
lastSafeCheckStatus = ok;
return ok;
}
void DeviceSuddenStop() {
if (lastSafeCheckStatus)
{
AxisBean.StopMultiAxis(AxisBean.List);
MoveInfo.List.ForEach((m) => { m.CanWhileCount = 5; });
SafetyDevice.PauseAll();
if (runStatus == RunStatus.HomeReset)
{
ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
}
}
}
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
DateTime lastAirCloseTime = DateTime.MinValue;
internal DateTime checkAlarmTime = DateTime.Now;
public bool DeviceCheck() {
bool ok = true;
isInSuddenDown = IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW);
if (UserPause)
{
Msg.add(crc.GetString(L.system_pause, "系统暂停"), MsgLevel.warning);
DeviceSuddenStop();
lastSafeCheckStatus = false;
ok = false;
return ok;
}
else if (isInSuddenDown)
{
//Alarm(AlarmType.SuddenStop);
Msg.add(crc.GetString(L.in_suddenstop, "急停中"), MsgLevel.alarm, ErrInfo.SuddenStop);
ButtenEvent?.Invoke(null, ErrInfo.SuddenStop);
lastSafeCheckStatus = false;
ok = false;
}
else if (alarmType != AlarmType.None) {
//if (IOValue(IO_Type.Right_BTN).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.Left_BTN).Equals(IO_VALUE.HIGH))
//{
// Alarm(AlarmType.None);
//}
//else
{
Msg.add(crc.GetString(L.system_need_reset, "系统需要重置"), MsgLevel.alarm,ErrInfo.SuddenStop);
ButtenEvent?.Invoke(null, ErrInfo.SuddenStop);
ok = false;
}
}
if (ok && !AxisBean.RunMultiAxis(true, out string msg, AxisBean.List))
{
ok = false;
Msg.add(msg, MsgLevel.warning);
}
if (RobotManage.InoutDebugMode)
{
Msg.add(crc.GetString(L.store_inout_debug_mode, "进出库调试模式"), MsgLevel.info);
//ok = false;
}
if (alarmType!=AlarmType.SuddenStop)
{
TimeSpan span = DateTime.Now - checkAlarmTime;
if (span.TotalSeconds > 2)
{
checkAlarmTime = DateTime.Now;
foreach (ConfigMoveAxis configMoveAxis in Config.moveAxisList)
{
if (AxisManager.GetAlarmStatus(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue()) == 1)
{
if (configMoveAxis.DeviceName == "Comp_Axis")
{
if (runStatus == RunStatus.Running || ResetMoveInfo.IsStep(MoveStep.H06_HomeReset))
{
Msg.add(crc.GetString(configMoveAxis.ProName, configMoveAxis.Explain) + $"[{configMoveAxis.GetAxisValue()}]:"
+ crc.GetString(L.motion_alarm, "运动报警"), MsgLevel.alarm);
RobotManage.UserPause(crc.GetString("Res0016","压紧轴报警"), true);
AxisManager.AlarmClear(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue());
Thread.Sleep(2000);
}
}
else
{
Msg.add(crc.GetString(configMoveAxis.ProName, configMoveAxis.Explain) + $"[{configMoveAxis.GetAxisValue()}]:"
+ crc.GetString(L.motion_alarm, "运动报警"), MsgLevel.alarm, ErrInfo.SuddenStop);
ButtenEvent?.Invoke(null, ErrInfo.SuddenStop);
}
LogUtil.error(string.Join(",", HuichuanLibrary.HCBoardManager.GetAxisErrorDetail(configMoveAxis.GetAxisValue())));
ok = false;
}
}
}
}
return ok;
}
public void IgnoreX09() {
boxTransport.IgnoreX09 = true;
LogUtil.info("按下X09忽略");
}
private void clearNgPos(string ngType)
{
List<string> allPosList = CSVPositionReader<ACStorePosition>.getPositionKeyList();
List<string> leftNgPos = (from m in allPosList where m.StartsWith(ngType) select m).ToList();
if (leftNgPos.Count > 0)
{
foreach (string pos in leftNgPos)
{
if (NgPosMap.ContainsKey(pos))
{
ReelParam reelParam = NgPosMap[pos];
LogUtil.info($"NG门打开,清理NG库位[{pos}]的物料信息:{reelParam.ToStr()}");
}
}
}
}
private string getNextNgPos(int size = 7)
{
string ngType = "NG_" + size;
List<string> allPosList = CSVPositionReader<ACStorePosition>.getPositionKeyList();
List<string> leftNgPos = (from m in allPosList where m.StartsWith(ngType) select m).ToList();
if (leftNgPos.Count > 0)
{
foreach (string pos in leftNgPos)
{
if (!NgPosMap.ContainsKey(pos))
{
LogUtil.info($"获取下一个{size}寸盘的NG库位号: {pos}");
return pos;
}
}
}
return "";
}
private void UpdateNgPos(string ngPos,ReelParam reelParam)
{
if (NgPosMap.ContainsKey(ngPos))
{
ReelParam reel = NgPosMap[ngPos];
NgPosMap.Remove(ngPos);
}
NgPosMap.Add(ngPos, reelParam);
LogUtil.info($"更新NG库位[{ngPos}]的物料信息:{reelParam.ToStr()}");
}
public string getReadyShelf(string split= ",")
{
string rfid = "";
foreach(OutShelfBean bean in outShelfBeans.Values)
{
if (bean.ShelfValid())
{
rfid += bean.CurrShelf.realRFID;
}
}
return rfid;
}
private DateTime lastEmptyTime = DateTime.Now;
private void ShelfEmptyProcess()
{
//2秒钟获取一次
TimeSpan span = DateTime.Now - lastEmptyTime;
if (span.TotalSeconds < 3)
{
return;
}
try
{
lastEmptyTime = DateTime.Now;
string shelfRfid = getReadyShelf();
if (String.IsNullOrEmpty(shelfRfid))
{
return;
}
Dictionary<string, int> emptyMap = HttpServer.getShelfEmptySlot(shelfRfid);
//需要取放料,且料架已准备好
if (emptyMap != null)
{
List<string> keys = new List<string>(outShelfBeans.Keys);
foreach (string key in keys)
{
ShelfInfo shelf = outShelfBeans[key].CurrShelf;
if (outShelfBeans[key].ShelfValid())
{
string realRfid = outShelfBeans[key].CurrShelf.rfid;
if (emptyMap.TryGetValue(realRfid, out int emptyP))
{
outShelfBeans[key].CurrShelf.EmptyPos = emptyP;
if (emptyP <= 0)
{
outShelfBeans[key].CurrShelf.IsNeedLeave=true;
LogUtil.error(outShelfBeans[key] + "的料架 【" + realRfid + "】剩余空位【" + emptyP + "】更改料架状态为需要离开");
}
}
}
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "ShelfEmptyProcess:" + ex.ToString());
}
}
internal string GetShelfPosId(TrayInfo tray)
{
string targetPosName = "";
if (tray != null)
{
foreach (OutShelfBean obj in outShelfBeans.Values)
{
if (obj.IsRightShelf(tray, out targetPosName))
{
//判断库位号是否存在
ACStorePosition position = CSVPositionReader<ACStorePosition>.GetPositon(targetPosName);
if (position == null)
{
LogUtil.error(Name + " " + tray.ToStr() + " 找到匹配料架,但未找到库位号:" + position) ;
WarnMsg = tray.barcode+"未找到库位号:"+position;
targetPosName = "";
break;
}
obj.StartPutReel();
LogUtil.info(Name + " " + tray.ToStr() + " 使用料架:" + targetPosName + ",更改料架为忙碌状态,开始放料");
break;
}
}
}
return targetPosName;
}
public void MsgEvent(List<Msg> msgs)
{
ProcessMsgEvent?.Invoke(msgs);
}
}
}