X_RAY_Equip_Partial.cs
40.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
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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
partial class X_RAY_Equip
{
public delegate void GetImage(Bitmap bitmap);
public event GetImage GetImageEvent;
#region Label
public override bool StartLabelling(WorkParam param)
{
return false;
}
protected override void LabellingProcess()
{
}
private bool CountIsOk()
{
return false;
}
#endregion
#region 工作
public override bool StartWorking(WorkParam param)
{
if (!MoveInfo.MoveType.Equals(RobotMoveType.None))
{
return false;
}
//出口有料
if (IOValue(IO_Type.X_ReelCheck).Equals(IO_VALUE.HIGH))
{
runStatus = RobotRunStatus.Busy;
MoveInfo.NewMove(RobotMoveType.Working);
MoveInfo.MoveParam.SetReelInfo(Work_ReelInfo);
if (Work_ReelInfo.WareCount <= 0)
{
MoveInfo.NextMoveStep(StepEnum.XW06_WaitTime);
WorkLog("扫描区有料[" + Work_ReelInfo.ToStr() + "],还未进行点料,开始处理");
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
}
else
{
MoveInfo.NextMoveStep(StepEnum.XW21_WaitOutNoReel);
WorkLog("扫描区有料[" + Work_ReelInfo.ToStr() + "],点料已完成,准备放出料盘");
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
}
else if (IOValue(IO_Type.X_InLine_Check).Equals(IO_VALUE.HIGH))
{
runStatus = RobotRunStatus.Busy;
MoveInfo.NewMove(RobotMoveType.Working);
MoveInfo.MoveParam.SetReelInfo(In_ReelInfo);
MoveInfo.NextMoveStep(StepEnum.XW01_WaitInReel);
WorkLog("入口皮带线有料[" + In_ReelInfo.ToStr() + "],开始处理");
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_InLine_Check, IO_VALUE.HIGH));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.LOW));
}
return false;
}
public bool Out_TrayCheck_force = false;
bool saveone = false;
protected override void WorkingProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
if (MoveInfo.IsStep(StepEnum.XW01_WaitInReel))
{
MoveInfo.NextMoveStep(StepEnum.XW02_InDoorOpen);
WorkLog("料盘处理:左侧门打开,挡停下降", 0);
CylinderMove(MoveInfo, IO_Type.X_InDoor_Up, IO_Type.X_InDoor_Down);
CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Up, IO_Type.X_StopCylinder_Down);
MoveInfo.NextMoveStep(StepEnum.XW04_InLineRun);
WorkLog("料盘处理:入口和中间皮带线转动", 0);
IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
MoveInfo.NextMoveStep(StepEnum.XW05_WaitMCheck);
WorkLog("料盘处理:等待扫描区域信号检测", 0);
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
}
else if (MoveInfo.IsStep(StepEnum.XW02_InDoorOpen))
{
}
else if (MoveInfo.IsStep(StepEnum.XW04_InLineRun))
{
//MoveInfo.NextMoveStep(StepEnum.XW05_WaitMCheck);
//WorkLog("料盘处理:等待扫描区域信号检测", 0);
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
}
else if (MoveInfo.IsStep(StepEnum.XW05_WaitMCheck))
{
MoveInfo.NextMoveStep(StepEnum.XW06_WaitTime);
Work_ReelInfo = In_ReelInfo.GetReelInfo();
MoveInfo.MoveParam.SetReelInfo(Work_ReelInfo);
In_ReelInfo = new ReelInfo();
WorkLog("料盘处理:更新Work_ReelInfo【" + Work_ReelInfo.ToStr() + "】,清空 In_ReelInfo,左侧皮带线先停止,右侧皮带线再转动4秒钟");
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
}
else if (MoveInfo.IsStep(StepEnum.XW06_WaitTime))
{
if (IOValue(IO_Type.X_ReelCheck).Equals(IO_VALUE.HIGH))
{
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:停止入口皮带线,中间皮带线");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH, 550);//皮带延时,控制料盘位置
}
else if (MoveInfo.IsTimeOut(20))
{
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:未检测到料盘,直接执行送出动作");
Work_ReelInfo.IsNgReel = true;
Work_ReelInfo.NgMsg = "未检测到料盘";
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
}
}
else if (MoveInfo.IsStep(StepEnum.XW07_InLineStop))
{
if (Work_ReelInfo.PlateH <= 0)
{
Work_ReelInfo.IsNgReel = true;
Work_ReelInfo.NgMsg = "无高度信息";
}
else if (String.IsNullOrEmpty(Work_ReelInfo.WareCode))
{
Work_ReelInfo.IsNgReel = true;
Work_ReelInfo.NgMsg = "无有效条码";
}
//MoveInfo.MoveParam.SetReelInfo(In_ReelInfo);
//判断是否需要点料
if (Work_ReelInfo.IsNgReel)
{
MoveInfo.NextMoveStep(StepEnum.XW21_WaitOutNoReel);
WorkLog("扫描区NG料 [" + Work_ReelInfo.ToStr() + "],直接放行料盘");
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
else
{
MoveInfo.NextMoveStep(StepEnum.XW08_DoorClose);
// WorkLog("料盘处理:左侧门关闭,右侧门关闭,准备开始点料");
WorkLog("料盘处理:左侧门关闭,右侧门关闭,挡停放行,准备开始点料");
CylinderMove(MoveInfo, IO_Type.X_InDoor_Down, IO_Type.X_InDoor_Up);
CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up);
CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Down, IO_Type.X_StopCylinder_Up);
}
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
#region 点料处理
else if (MoveInfo.IsStep(StepEnum.XW08_DoorClose))
{
if (!OpenXLine)
{
MoveInfo.NextMoveStep(StepEnum.XW15_GetResult);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
int count = 99999;
InXWork = false;
WorkLog("点料:未启用X射线点料,模拟点料结果:" + count + "");
if (Work_ReelInfo.WareCount <= 0)
{
Work_ReelInfo.WareCount = count;
MoveInfo.MoveParam.SetReelInfo(Work_ReelInfo);
}
}
else if (IOValue(IO_Type.X_Lock_On).Equals(IO_VALUE.HIGH))
{
MoveInfo.NextMoveStep(StepEnum.XW11_StartCount);
WorkLog("点料:启用X射线点料,等待X射线可以启动");
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
CylinderMove(MoveInfo, IO_Type.X_InDoor_Down, IO_Type.X_InDoor_Up);
CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_Lock_On, IO_VALUE.HIGH));
}
else if (MoveInfo.IsTimeOut(120))
{
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待 X互锁信号打开 超时[" + FormUtil.GetSpanStr(MoveInfo.StepSpan()) + "]";
LogUtil.error(WarnMsg, SecMoveInfo.ErrorLogType, SecMoveInfo.logSeconds());
Alarm(AlarmType.IoSingleTimeOut);
}
}
else if (MoveInfo.IsStep(StepEnum.XW11_StartCount))
{
if (xRayCanStart && (IOValue(IO_Type.X_Lock_On).Equals(IO_VALUE.HIGH)))
{
ClearTimeoutAlarm("可以打开X射线");
ClearTimeoutAlarm("X互锁信号打开");
XW12_XRayStart();
}
else if (MoveInfo.IsTimeOut(120))
{
if (!xRayCanStart)
{
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待 可以打开X射线 超时[" + FormUtil.GetSpanStr(MoveInfo.StepSpan()) + "]";
}
else
{
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待 X互锁信号打开 超时[" + FormUtil.GetSpanStr(MoveInfo.StepSpan()) + "]";
}
LogUtil.error(WarnMsg, SecMoveInfo.ErrorLogType, SecMoveInfo.logSeconds());
Alarm(AlarmType.IoSingleTimeOut);
}
}
else if (MoveInfo.IsStep(StepEnum.XW12_XRayStart))
{
TickLog("打开xray", true);
MoveInfo.NextMoveStep(StepEnum.XW13_GetXRayImage);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(8000));
WorkLog("点料:清理" + path1_tif + "内容,开始获取X射线图形 ");
if (string.IsNullOrEmpty(CapImage()))
{
//Alarm(AlarmType.IoSingleTimeOut);
}
MoveInfo.EndStepWait();
}
else if (MoveInfo.IsStep(StepEnum.XW13_GetXRayImage))
{
XW15_GetResult();
}
else if (MoveInfo.IsStep(StepEnum.XW15_GetResult))
{
if (xRay.IsRayOpen)
{
xRay.Stop();
}
MoveInfo.NextMoveStep(StepEnum.XW16_EndCount);
WorkLog("料盘处理:点料结束,关闭X关机互锁信号,等待出口无料盘");
IOMove(IO_Type.X_Lock_On, IO_VALUE.LOW);
MoveInfo.TimeOutSeconds = 120;
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_Lock_On, IO_VALUE.LOW));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
#endregion
else if (MoveInfo.IsStep(StepEnum.XW16_EndCount))
{
MoveInfo.NextMoveStep(StepEnum.XW21_WaitOutNoReel);
MoveInfo.TimeOutSeconds = 120;
WorkLog("料盘处理:等待出口无料盘", 0);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
else if (MoveInfo.IsStep(StepEnum.XW21_WaitOutNoReel))
{
//判断取料机构是否正转夹料
bool ingetWare = RobotManager.robot.outputEquip.IsInGetWare();
if (!ingetWare)
{
ClearTimeoutAlarm("取料机构取料完成");
MoveInfo.NextMoveStep(StepEnum.XW22_OutDoorOpen);
WorkLog("料盘处理:右侧门打开,挡停放行", 0);
CylinderMove(MoveInfo, IO_Type.X_OutDoor_Up, IO_Type.X_OutDoor_Down);
CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Down, IO_Type.X_StopCylinder_Up);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
else if (MoveInfo.IsTimeOut(120))
{
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待 取料机构取料完成 超时[" + FormUtil.GetSpanStr(MoveInfo.StepSpan()) + "]";
LogUtil.error(WarnMsg, SecMoveInfo.ErrorLogType, SecMoveInfo.logSeconds());
Alarm(AlarmType.IoSingleTimeOut);
}
}
else if (MoveInfo.IsStep(StepEnum.XW22_OutDoorOpen))
{
if (IOValue(IO_Type.Out_TrayCheck).Equals(IO_VALUE.HIGH))
{
MoveInfo.NextMoveStep(StepEnum.XW21_WaitOutNoReel);
MoveInfo.TimeOutSeconds = 120;
WorkLog("料盘处理:XW22_OutDoorOpen后发现出口有料,再次等待出口无料盘");
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
else
{
MoveInfo.NextMoveStep(StepEnum.XW23_OutLineRun);
WorkLog("料盘处理:中间皮带线,出口皮带线转动", 1);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
IOMove(IO_Type.X_OLine_Run, IO_VALUE.HIGH);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.LOW));
}
}
else if (MoveInfo.IsStep(StepEnum.XW23_OutLineRun))
{
MoveInfo.NextMoveStep(StepEnum.XW24_WaitOutCheck);
WorkLog("料盘处理:继续转动3秒后,等待出口皮带线检测到料盘", 1);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
IOMove(IO_Type.X_OLine_Run, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
saveone = true;
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.HIGH));
}
else if (MoveInfo.IsStep(StepEnum.XW24_WaitOutCheck))
{
if (IOValue(IO_Type.Out_TrayCheck).Equals(IO_VALUE.HIGH) || Out_TrayCheck_force)
{
MoveInfo.NextMoveStep(StepEnum.XW25_WaitTime);
WorkLog("料盘处理: 中间皮带线先停止,出口皮带线 再转动3秒,挡停先下降");
IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_OLine_Run, IO_VALUE.HIGH, 3000);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.HIGH));
CylinderMove(null, IO_Type.X_StopCylinder_Up, IO_Type.X_StopCylinder_Down);
}
else if (MoveInfo.IsTimeOut(10))
{
MoveInfo.NextMoveStep(StepEnum.XW24_WaitOutCheck);
WorkLog("料盘处理:Out_TrayCheck X57没有检测到料盘");
var hasplate = TestPlate.TestIt(RobotManager.robot.outputEquip.Config.CameraName, saveone);
saveone = false;
if (!hasplate[0] && !hasplate[1])
{
WorkLog("料盘处理:图像没有检测到料盘,结束点料处理");
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_OLine_Run, IO_VALUE.LOW);
//CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up);
//CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Up, IO_Type.X_StopCylinder_Down);
//MoveInfo.NextMoveStep(StepEnum.XW26_OutLineStop);
}
else {
WorkLog("料盘处理:图像检测到料盘,当作有料处理");
//Out_TrayCheck_force = true;
}
}
}
else if (MoveInfo.IsStep(StepEnum.XW25_WaitTime))
{
if (GetResultTask == null || GetResultTask.IsCompleted)
{
ClearTimeoutAlarm("获取点料结果结束");
MoveInfo.NextMoveStep(StepEnum.XW26_OutLineStop);
Out_ReelInfo = Work_ReelInfo.GetReelInfo();
Work_ReelInfo = new ReelInfo();
WorkLog("料盘处理:清空 Work_ReelInfo,更新Out_ReelInfo【" + Out_ReelInfo.ToStr() + "】 ,中间皮带线,出口皮带线停止,出口门关闭,挡停下降");
IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_OLine_Run, IO_VALUE.LOW);
CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up);
CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Up, IO_Type.X_StopCylinder_Down);
}
else if (MoveInfo.IsTimeOut(120))
{
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待 获取点料结果结束 超时[" + FormUtil.GetSpanStr(MoveInfo.StepSpan()) + "]";
LogUtil.error(WarnMsg, SecMoveInfo.ErrorLogType, SecMoveInfo.logSeconds());
Alarm(AlarmType.IoSingleTimeOut);
}
}
else if (MoveInfo.IsStep(StepEnum.XW26_OutLineStop))
{
TimeSpan span = DateTime.Now - MoveInfo.MoveStartTime;
runStatus = RobotRunStatus.Runing;
TickLog("点料完成");
WorkLog("料盘处理:料盘处理结束,耗时(" + FormUtil.GetSpanStr(span) + ")");
MoveInfo.EndMove();
}
}
private void XW12_XRayStart()
{
MoveInfo.NextMoveStep(StepEnum.XW12_XRayStart);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
InXWork = true;
bool result = xRay.Start();
WorkLog("料盘处理:启动X射线[" + result + "],等待1秒");
}
#endregion
#region 点料处理
private Task GetResultTask = null;
private string lastFileName = "";
private void XW15_GetResult()
{
if (IOValue(IO_Type.X_Lock_On).Equals(IO_VALUE.LOW))
{
LogUtil.error("XW15_GetResult 方法,X_Lock_On=LOW,直接返回");
return;
}
MoveInfo.NextMoveStep(StepEnum.XW15_GetResult);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
GetResultTask = Task.Factory.StartNew(delegate
{
try
{
if (xRay.IsRayOpen)
{
xRay.Stop();
}
InXWork = false;
WorkLog("点料:停止X射线,设置 InXWork = false,开始获取点料结果");
bool isNg = false;
string NgMsg = "";
int count = 0;
CountParam lastParam = ParamManager.GetParamByCode(Work_ReelInfo.WareCode);
if (lastParam == null)
{
lastParam = new CountParam("", ThresholdValue, 3);
WorkLog("点料:" + "NG:未找到元器件类型,PN[" + ParamManager.GetCodeStrPN(Work_ReelInfo.WareCode) + "]");
BackNoConfigImg(ParamManager.GetCodeStrPN(Work_ReelInfo.WareCode));
}
var splitindex = MoveInfo.MoveParam.WareCode.IndexOf(";");
if (splitindex > 0)
{
var pn = MoveInfo.MoveParam.WareCode.Substring(0, splitindex);
if (!OldPNList.HasPN(pn))
{
WorkLog(" 【" + MoveInfo.MoveParam.WareCode + "】是以前没有过的PN:NG处理");
isNg = true;
NgMsg = "未匹配算法的新PN盘,NG.";
BackNGImg(Work_ReelInfo.WareCode);
}
}
string resfile = "";
if (!isNg)
{
string fileP = path1_tif + @"\" + lastFileName;
count = GetCountResult(fileP, lastParam, out resfile);
if (count < ResultMinCount)
{
isNg = true;
NgMsg = "NG:点料结果小于" + ResultMinCount;
}
WorkLog("点料: 调用 GetCountResult 获取点料结果 【" + count + "】 " + lastParam.ToStr() + ", " + NgMsg);
if (Work_ReelInfo.WareCount <= 0)
{
MoveInfo.MoveParam.WareCount = count;
Work_ReelInfo.WareCount = count;
}
}
if (!isNg && SServerManager.CanConnect())
{
// string msg = "暂不上传";
string factoryCode;
string msg = SServerManager.Return_Material(Name, Work_ReelInfo.WareCode, Work_ReelInfo.WareCount, out factoryCode);
MoveInfo.MoveParam.FactoryCode = factoryCode;
Work_ReelInfo.FactoryCode = factoryCode;
if (!String.IsNullOrEmpty(msg))
{
LogUtil.error(Name + "上传【" + Work_ReelInfo.ToStr() + "】点料结果失败:" + msg + ",更新状态为NG");
isNg = true;
NgMsg = msg;
}
}
if (isNg && Work_ReelInfo.WareCount > 0)
{
//BackNGImg(Work_ReelInfo.WareCode);
}
string outF = resfile;
if (!isNg)
{
ReadOutMsg(outF);
}
else
{
MoveInfo.MoveParam.IsNgReel = true;
Work_ReelInfo.IsNgReel = true;
//Work_ReelInfo.FactoryCode = MoveInfo.MoveParam.FactoryCode;
MoveInfo.MoveParam.NgMsg = NgMsg;
Work_ReelInfo.NgMsg = NgMsg;
outF = NgMsg;
}
int c = RobotManager.robot.sQLite.Insert(Work_ReelInfo.WareCode, Work_ReelInfo.PlateW, Work_ReelInfo.PlateH, count, outF);
LogUtil.info("插入数据【" + Work_ReelInfo.WareCode + "】【" + count + "】【" + outF + "】结果:" + c + " ," + RobotManager.robot.sQLite.ErrInfo);
}
catch (Exception ex)
{
LogUtil.error("XW15_GetResult出错:" + ex.ToString());
}
finally {
}
});
//MoveInfo.EndStepWait();
}
private bool ReadOutMsg(string outF)
{
try
{
if (System.IO.File.Exists(outF))
{
WorkLog("点料:读取结果图片【" + outF + "】");
Bitmap img = (Bitmap)Image.FromFile(outF).Clone();
GetImageEvent?.Invoke(img);
return true;
}
else
{
LogUtil.error("点料:未找到结果图片【" + outF + "】");
}
}
catch (Exception ex)
{
LogUtil.error("读取结果图片【" + outF + "】出错:" + ex.ToString());
}
return false;
}
int Get48bImageErrorCount = 0;
public string CapImage()
{
try
{
string lastData = DateTime.Now.ToString("yyyy-MM-dd");
if (ConfigAppSettings.GetValue(Setting_Init.XRay_Data)!= lastData)
{
ConfigAppSettings.SaveValue(Setting_Init.XRay_Data, lastData);
}
ClearFilePath();
//取图失败关掉重开。
bool imgResult = xrayImage.GetImage(5,3000);
if (!imgResult)
{
bool closeR = xrayImage.Close();
if (!closeR)
LogUtil.error(Name + "carerayImage.GetImage 获取图片失败 = " + imgResult + ", carerayImage.Close 失败");
Thread.Sleep(500);
bool openR = xrayImage.Open();
Thread.Sleep(500);
if (openR)
{
imgResult = xrayImage.GetImage(5, 3000);
LogUtil.error(Name + "carerayImage.GetImage 第2次获取图片 = " + imgResult + "");
}
else {
LogUtil.error(Name + "carerayImage.Open 第2次open = " + openR + "");
}
}
carerayImageError = !imgResult;
xrayImage.WindowWidth = Config.WindowWidth;
xrayImage.WindowLevel = Config.WindowLevel;
if (imgResult)
{
Bitmap bmp = xrayImage.Get48bImage();
if (bmp != null)
{
Get48bImageErrorCount = 0;
lastFileName = Work_ReelInfo.GetImgName();
string fileP = path1_tif + @"\" + lastFileName;
var n = DateTime.Now;
string backDir = Path.Combine(path_XRAY, "back", n.Year.ToString() + "-" + n.Month.ToString(), n.Day.ToString(), n.Hour.ToString());
Directory.CreateDirectory(backDir);
string backFile = Path.Combine(backDir, lastFileName);
try
{
bmp.Save(fileP, System.Drawing.Imaging.ImageFormat.Png);
bmp.Save(backFile, System.Drawing.Imaging.ImageFormat.Png);
}
catch (Exception ex)
{
LogUtil.error("X图片备份到【" + backFile + "】错误:" + ex.ToString());
}
WorkLog("点料:获取X射线图形,保存到: " + fileP + ",备份到:" + backFile + ",记录时间" + lastData + ",停止X射线");
GetImageEvent?.Invoke(bmp);
}
else
{
WorkLog("点料:获取X射线图形,获取图片失败,carerayImage.Get48bImage()=null");
LogUtil.error(Name + " 获取图片失败,carerayImage.Get48bImage()=null");
lastFileName = "";
Get48bImageErrorCount++;
if (Get48bImageErrorCount>3)
carerayImageError = true;
}
}
else
{
WorkLog("点料:获取X射线图形,获取图片失败,carerayImage.GetImage()=" + imgResult);
LogUtil.error(Name + " 获取图片失败,carerayImage.GetImage()=" + imgResult);
lastFileName = "";
}
bool result = xRay.Stop();
if (!result)
{
LogUtil.error(" xRay.Stop() 第一次失败,再次调用Stop");
result = xRay.Stop();
if (!result)
{
LogUtil.error(" xRay.Stop()失败:" + result);
}
}
}
catch (Exception ex)
{
LogUtil.error(" CapImage 出错:" + ex.ToString());
}
return lastFileName;
}
public string CapImage2()
{
try
{
string lastData = DateTime.Now.ToString("yyyy-MM-dd");
if (ConfigAppSettings.GetValue(Setting_Init.XRay_Data) != lastData)
{
ConfigAppSettings.SaveValue(Setting_Init.XRay_Data, lastData);
}
//取图失败关掉重开。
bool imgResult = xrayImage.GetImage(5, 3000);
if (!imgResult)
{
bool closeR = xrayImage.Close();
if (!closeR)
LogUtil.error(Name + "carerayImage.GetImage 获取图片失败 = " + imgResult + ", carerayImage.Close 失败");
Thread.Sleep(500);
bool openR = xrayImage.Open();
Thread.Sleep(500);
if (openR)
{
imgResult = xrayImage.GetImage(5, 3000);
LogUtil.error(Name + "carerayImage.GetImage 第2次获取图片 = " + imgResult + "");
}
else
{
LogUtil.error(Name + "carerayImage.Open 第2次open = " + openR + "");
}
}
carerayImageError = !imgResult;
xrayImage.WindowWidth = Config.WindowWidth;
xrayImage.WindowLevel = Config.WindowLevel;
if (imgResult)
{
//eyemLib.EyemImage eyemImage = xrayImage.GetRawBufferHandle();
lastFileName = Work_ReelInfo.GetRawName();
var n = DateTime.Now;
string backDir = Path.Combine(path_XRAY, "back", n.Year.ToString() + "-" + n.Month.ToString(), n.Day.ToString(), n.Hour.ToString());
Directory.CreateDirectory(backDir);
string backFile = Path.Combine(backDir, lastFileName);
xrayImage.SaveRAW(backFile);
}
else
{
WorkLog("点料:获取X射线图形,获取图片失败,carerayImage.GetImage()=" + imgResult);
LogUtil.error(Name + " 获取图片失败,carerayImage.GetImage()=" + imgResult);
lastFileName = "";
Get48bImageErrorCount++;
if (Get48bImageErrorCount > 3)
carerayImageError = true;
}
bool result = xRay.Stop();
if (!result)
{
LogUtil.error(" xRay.Stop() 第一次失败,再次调用Stop");
result = xRay.Stop();
if (!result)
{
LogUtil.error(" xRay.Stop()失败:" + result);
}
}
}
catch (Exception ex)
{
LogUtil.error(" CapImage 出错:" + ex.ToString());
}
return lastFileName;
}
private void ClearFilePath()
{
try
{
if (System.IO.Directory.Exists(path1_tif))
{
System.IO.Directory.Delete(path1_tif, true);
}
}
catch (Exception ex)
{
LogUtil.error("清除文件夹【" + path1_tif + "】内容出错:" + ex.ToString());
}
try
{
System.IO.Directory.CreateDirectory(path1_tif + @"\");
}
catch (Exception ex)
{
LogUtil.error("创建文件夹【" + path1_tif + "】出错:" + ex.ToString());
}
}
private void BackNoConfigImg(string pn)
{
//将未找到料号配置的图片保存到新的文件夹
string fileP = path1_tif + @"\" + lastFileName;
string backPath = ParamManager.NoConfigPath ;
string backFile = Path.Combine(backPath, pn + Path.GetExtension(lastFileName));
try
{
if (!Directory.Exists(backPath))
{
Directory.CreateDirectory(backPath);
}
if (!File.Exists(backFile))
{
System.IO.File.Copy(fileP, backFile);
LogUtil.info("BackNoConfigImg 【" + fileP + "】 -> 【" + backFile + "】");
}
}
catch (Exception ex)
{
LogUtil.error("X图片备份到【" + backFile + "】错误:" + ex.ToString());
}
}
private void BackNGImg(string wearcode)
{
//将未找到料号配置的图片保存到新的文件夹
string fileP = path1_tif + @"\" + lastFileName;
string backFile = Path.Combine(path_XRAY_NGBck, wearcode + Path.GetExtension(lastFileName));
try
{
if (!Directory.Exists(path_XRAY_NGBck))
{
Directory.CreateDirectory(path_XRAY_NGBck);
}
if (!File.Exists(backFile))
{
System.IO.File.Copy(fileP, backFile);
LogUtil.info("BackNGImg 【" + fileP + "】 -> 【" + backFile + "】");
}
}
catch (Exception ex)
{
LogUtil.error("X图片备份到【" + backFile + "】错误:" + ex.ToString());
}
}
public int GetCountResult(string fileP, CountParam param, out string resfile)
{
//返回的数量是string类型,count = "4000,3000,3500,2000"
int count = 0;
resfile = "";
//tpDstImg = new API.EyemImage();
try
{
Bitmap dst = null;
int[] countStr = new int[4];
int result = 0;
CountParam.SignType type = param.Sign;
int threshold = param.Threshold;
int windowsize = param.WindowSize; ;
if (param.Sign == CountParam.SignType.AUTO)
{
result = XrayImage.GetLocalCount(fileP, 50, out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCount 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
}
else {
result = XrayImage.GetLocalCountIrregular(fileP, 50, type.ToString(), out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCountIrregular 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
}
if (dst != null)
{
dst.Save("ResOut\\" + Path.GetFileNameWithoutExtension(fileP) + "-Mark.png");
dst.Dispose();
}
if (countStr != null)
{
count = (from a in countStr where a > 0 select a).FirstOrDefault();
}
else {
count = 0;
}
if (result == 0)
{
string resfilename = Path.GetFileNameWithoutExtension(fileP) + "-Mark.png";
string root = Path.Combine(Application.StartupPath, "ResOut");
var n = DateTime.Now;
string destdir = Path.Combine(root, n.Year.ToString() + "-" + n.Month.ToString(), n.Day.ToString(), n.Hour.ToString());
Directory.CreateDirectory(destdir);
resfile = Path.Combine(destdir, resfilename);
if (File.Exists(resfile))
File.Delete(resfile);
Directory.Move(Path.Combine(root, resfilename), resfile);
}
}
catch (Exception ex)
{
LogUtil.error("GetCountResult 出错: " + ex.ToString());
}
return count;
}
public int GetCountResult(eyemLib.EyemImage eyemImage, string fileP, CountParam param, out string resfile)
{
//返回的数量是string类型,count = "4000,3000,3500,2000"
int count = 0;
resfile = "";
//tpDstImg = new API.EyemImage();
try
{
Bitmap dst = null;
int[] countStr = new int[4];
int result = 0;
CountParam.SignType type = param.Sign;
int threshold = param.Threshold;
int windowsize = param.WindowSize; ;
if (param.Sign == CountParam.SignType.AUTO)
{
result = XrayImage.GetLocalCount(eyemImage, 250,Path.GetFileNameWithoutExtension(fileP), out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCount 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
}
else
{
result = XrayImage.GetLocalCountIrregular(eyemImage, 250,Path.GetFileNameWithoutExtension(fileP), type.ToString(), out countStr, out dst);
LogUtil.info("GetCountResult " + type + " 调用 GetLocalCountIrregular 【" + fileP + "】【" + threshold + "】【" + windowsize + "】,返回【" + result + "】,结果【" + string.Join(",", countStr) + "】");
}
if (dst != null)
{
dst.Save("ResOut\\" + Path.GetFileNameWithoutExtension(fileP) + "-Mark.png");
dst.Dispose();
}
if (countStr != null)
{
count = (from a in countStr where a > 0 select a).FirstOrDefault();
}
else
{
count = 0;
}
if (result == 0)
{
string resfilename = Path.GetFileNameWithoutExtension(fileP) + "-Mark.png";
string root = Path.Combine(Application.StartupPath, "ResOut");
var n = DateTime.Now;
string destdir = Path.Combine(root, n.Year.ToString() + "-" + n.Month.ToString(), n.Day.ToString(), n.Hour.ToString());
Directory.CreateDirectory(destdir);
resfile = Path.Combine(destdir, resfilename);
if (File.Exists(resfile))
File.Delete(resfile);
Directory.Move(Path.Combine(root, resfilename), resfile);
}
}
catch (Exception ex)
{
LogUtil.error("GetCountResult 出错: " + ex.ToString());
}
return count;
}
public Bitmap ImgChange(Asa.eyemLib.EyemImage tpDstImg)
{
Bitmap bit = null;
return bit;
}
#endregion
}
}