TSAVBean.cs
37.9 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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.LoadCSVLibrary;
namespace TSA_V.DeviceLibrary
{
public partial class TSAVBean
{
public static bool IsDebug = ConfigAppSettings.GetBoolValue(Setting_Init.IsDebug);
public static bool SideCylinderMoveFirst = ConfigAppSettings.GetBoolValue(Setting_Init.SideCylinderMoveFirst);
public static string Name = "MASCOT";
public static int RotateNode_DefaultPosition = ConfigAppSettings.GetIntValue(Setting_Init.RotateNode_DefaultPosition);
public static Dictionary<int, Dictionary<int, NodeInfo>> RotateMap = new Dictionary<int, Dictionary<int, NodeInfo>>();
public static int DefaultPType = ConfigAppSettings.GetIntValue(Setting_Init.DefaultPointType);
public static int DefaultPSize = ConfigAppSettings.GetIntValue(Setting_Init.DefaultPointSize);
public static bool DisableSideCylinder = false;
public static bool DisableBottomCylinder = false;
public static ServerCommunication serverCommunication = null;
private static string warnMsg = "";
public static string WarnMsg
{
get { return warnMsg; }
set
{
if (!warnMsg.Equals(value) && (!String.IsNullOrEmpty(value)))
{
//StatusClient.instance.SendNew(Color.Red, warnMsg);
}
warnMsg = value;
}
}
public static bool IsInPut = false;
public static bool IsInSuddenDown = false;
public static bool NoAirAlarm = false;//无气压报警
/// <summary>
/// 工作模式,0=脚踏模式,1=自动模式
/// </summary>
public static int WorkMode = ConfigAppSettings.GetIntValue(Setting_Init.WorkMode);
/// <summary>
/// 自动模式下,踩脚踏或按按钮, 自动模式暂停,界面显示暂停状态;再次踩脚踏或按按钮,退出暂停状态
/// </summary>
public static bool WorkPause = false;
public static bool canQieHuan = false;
public static int AuToModeSeconds = ConfigAppSettings.GetIntValue(Setting_Init.AuToModeSeconds);
public static TSAVStatus Status = TSAVStatus.Wait;
public static ResetStep resetStep = ResetStep.OpenCan_0;
public static DateTime LastResetChangeTime = DateTime.Now;
private static System.Timers.Timer workTimer = null;
public static WorkInfo Work = new WorkInfo();
public static bool IsNeedAOI = ConfigAppSettings.GetBoolValue(Setting_Init.IsNeedAOI);
public static bool IsCanStepMove = false;
public static int LastStepIndex = 4;
/// <summary>
/// 退出工作界面
/// </summary>
public static void ExitWork()
{
WorkInfo.IsCycleDebug = false;
Work.WorkType = 0;
if (IOBase.NoLine)
return;
IOManager.IOMove(IOManager.SMEMA_Down, IO_VALUE.LOW);
IOManager.IOMove(IOManager.SMEMA_Up, IO_VALUE.LOW);
}
public static string LoadTSAV()
{
LogUtil.info(Name + "开始加载电机配置。。");
DisableSideCylinder = ConfigAppSettings.GetBoolValue(Setting_Init.DisableSideCylinder);
DisableBottomCylinder = ConfigAppSettings.GetBoolValue(Setting_Init.DisableBottomCylinder);
if (workTimer == null)
{
workTimer = new System.Timers.Timer();
workTimer.AutoReset = true;
workTimer.Enabled = false;
workTimer.Interval = 300;
workTimer.Elapsed += workTimer_Elapsed;
}
int count = ConfigAppSettings.GetIntValue(Setting_Init.TSAV_Storage_Count);
RotateMap = new Dictionary<int, Dictionary<int, NodeInfo>>();
int ceng = 5;
string sp = "_";
for (int i = 1; i <= count; i++)
{
RotateMap.Add(i, new Dictionary<int, NodeInfo>());
for (int j = 1; j <= ceng; j++)
{
string str = sp + i + sp + j;
uint nodeid = ConfigAppSettings.getUintValue(Setting_Init.RNode_Addr, str);
if (!(nodeid <= 0))
{
NodeInfo node = new NodeInfo(nodeid, "Node:_" + i + "_" + j, "_" + i + "_" + j);
RotateMap[i].Add(j, node);
}
}
}
if (DefaultPType <= 0 || DefaultPType > 5)
{
DefaultPType = 1;
}
if (DefaultPSize <= 0 || DefaultPSize > 100)
{
DefaultPSize = 4;
}
Task.Factory.StartNew(delegate
{
// bool result = GalvanometerManager.OpenPort(Gal_Port);
Screen[] sc = Screen.AllScreens;
bool result = sc.Length >= 2;
if (!result)
{
LogUtil.error("振镜初始化失败!");
//return ResourceControl.GetString(ResourceControl.InitXFail, "振镜初始化失败");
}
});
AlarmProcess.Init();
serverCommunication = new ServerCommunication();
serverCommunication.StartConnectServer();
return "";
}
public static string GetTime()
{
string date = DateTime.Now.ToString("HH:mm");
return "" + date + " ALARM ";
}
public static string startRunMsg = "";
public static string StartRun()
{
startRunMsg = "";
MesUtil.Open();
if (Status.Equals(TSAVStatus.Wait))
{
LogUtil.debug(Name + " StartRun:开始连接Can协议");
string msg = PUSICANControl.Open();
if (!msg.Equals(""))
{
LogUtil.error(Name + " StartRun 失败:Can协议连接失败:" + msg);
startRunMsg = ResourceControl.GetString(ResourceControl.CanConnectFail, "Can协议连接失败");
warnMsg = startRunMsg;
return startRunMsg;
}
else
{
LogUtil.info(Name + " StartRun:连接Can协议成功");
}
Thread.Sleep(PUSICANControl.SleepMS);
resetStep = ResetStep.OpenCan_0;
LastResetChangeTime = DateTime.Now;
}
//判断IO模块是否连接
if (IOManager.ISConnection().Equals(false))
{
LogUtil.info(Name + " StartRun 失败:IO模块连接失败");
startRunMsg = ResourceControl.GetString(ResourceControl.IOConnectError, "IO模块连接失败");
warnMsg = startRunMsg;
return startRunMsg;
}
StartReset();
//启动定时器
workTimer.Enabled = true;
return "";
}
public static void DeviceCheck()
{
try
{
//验证旋转轴是否上线,未上线弹出提示
LogUtil.info(Name + " DeviceCheck 开始连接Can协议");
string msg = PUSICANControl.Open();
if (!msg.Equals(""))
{
LogUtil.info(Name + " DeviceCheck Can协议连接失败,询问是否进入 过板模式");
WorkModeUtil.SelectMode(Name);
return;
}
Thread.Sleep(PUSICANControl.SleepMS);
LogUtil.info(Name + " DeviceCheck 初始化所有旋转轴 InitNode");
InitNode();
Thread.Sleep(PUSICANControl.SleepMS);
Thread.Sleep(1000);
//验证旋转轴是否上线
bool isAllOk = true;
string timeOutMsg = "";
SLAVE_STATUS rStatus = new SLAVE_STATUS();
int whileCount = 5;
while (true)
{
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
PUSICANControl.PUSICO_GetNodeStatus(node.NodeId, ref rStatus);
if (!rStatus.Equals(SLAVE_STATUS.SLAVESTATUS_WORK))
{
timeOutMsg = ResourceControl.GetString(ResourceControl.RNodeOnLine, " 旋转轴[{0}][{1}]上线", node.NodeId, rStatus);
isAllOk = false;
break;
}
}
}
if (isAllOk)
{
break;
}
whileCount++;
if (whileCount >= 5)
{
break;
}
Thread.Sleep(500);
}
if (!isAllOk)
{
LogUtil.info(Name + "DeviceCheck 检测 " + timeOutMsg + " 上线超时,询问是否进入 过板模式");
WorkModeUtil.SelectMode(Name);
}
else
{
LogUtil.info(Name + " DeviceCheck 检测旋转轴线完成,所有转盘都已连接");
WorkModeUtil.ModeCheckEnd();
}
}
catch (Exception ex)
{
LogUtil.error(Name + " DeviceCheck 出错:" + ex.ToString());
WorkModeUtil.ModeCheckEnd();
}
}
public static void StartReset()
{
if (Status > TSAVStatus.Wait)
{
LogUtil.info(Name + "重置中:重置之前先停止所有运动");
StopMove();
Thread.Sleep(PUSICANControl.SleepMS);
}
WarnMsg = "";
IsInSuddenDown = false;
IOManager.IOMove(IOManager.Line_FStart, IO_VALUE.LOW);
LogUtil.info(Name + "开始重置设备");
LastResetChangeTime = DateTime.Now;
Status = TSAVStatus.Reset;
resetStep = ResetStep.AddNode_1;
Thread.Sleep(PUSICANControl.SleepMS);
if (WorkModeUtil.OnlyGuoBan)
{
LogUtil.info(Name + "重置中 " + resetStep + ": OnlyGuoBan 模式,不需要初始化旋转轴 ");
}
else
{
InitNode();
}
if (!IOBase.NoLine)
{
PUSICANControl.InitNode(LWidthManager.Line_NodeAddr);
}
LogUtil.info(Name + "重置中 "+resetStep+":InitNode 所有节点 ");
}
public delegate bool ShowPointDelegate(ProjectorPInfo p);
public static event ShowPointDelegate ShowPointEvent;
public static void ShowPoint(double x, double y, int type = 1, int sizex = 1, int sizey = 1, int penWidth = 2, string name = "")
{
ProjectorPInfo p = new ProjectorPInfo((int)x, (int)y, type, sizex, sizey, penWidth, name);
ShowPointEvent?.Invoke(p);
}
private static void InitNode()
{
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo nodeid in map.Values)
{
PUSICANControl.InitNode(nodeid.NodeId);
}
}
}
public static void RemoveNode()
{
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo nodeid in map.Values)
{
PUSICANControl.RemoveNode(nodeid.NodeId);
}
}
}
private static void XYHomeMove_3()
{
//初始化所有旋转轴
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
PUSICANControl.InitRNodeConfig(node.NodeId);
Thread.Sleep(10);
}
}
if (!IOBase.NoLine)
{
PUSICANControl.InitRNodeConfig(LWidthManager.Line_NodeAddr, true);
Thread.Sleep(10);
LWidthManager.LineInitOk = true;
LogUtil.info(Name + " LWidthManager.LineInitOk =true");
}
//所有轴原点返回
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
PUSICANControl.HomeMove(node.NodeId);
Thread.Sleep(10);
}
}
// PUSICANControl.HomeMove(LWidthManager.Line_NodeAddr);
resetStep = ResetStep.XYHomeMove_3;
LastResetChangeTime = DateTime.Now;
LogUtil.info(Name + "重置中 " + resetStep + ":所有轴已连接, 旋转轴开始原点返回");
}
private static void ToRunning(string msg)
{
if (String.IsNullOrEmpty(msg))
{
msg = "当前为过板模式,转盘不需要复位,复位完成,进入运行状态";
}
WarnMsg = "";
LogUtil.info(Name + msg);
Status = TSAVStatus.Runing;
}
/// <summary>
/// 重置处理中
/// </summary>
private static void ResetProcess()
{
//判断超时时间
TimeSpan span = DateTime.Now - LastResetChangeTime;
bool isTimeOut = false;
string timeOutMsg = "";
//如果超过一分钟,需要提示;
if (span.TotalMinutes > 1)
{
isTimeOut = true;
}
//LedManager.LedOFFALL();
//if (resetStep.Equals(ResetStep.AddNode_1))
//{
// // LogUtil.info(Name + "重置中:XYNodeOnline_2 XY已经到待机点,判断旋转轴是否上线");
// resetStep = ResetStep.XYNodeOnline_2;
//}
if (resetStep.Equals(ResetStep.AddNode_1))
{
if (span.TotalSeconds > 10)
{
isTimeOut = true;
}
//判断旋转轴是否已经上线
bool isAllOk = true;
bool lineOk = true;
SLAVE_STATUS rStatus = new SLAVE_STATUS();
if (WorkModeUtil.OnlyGuoBan)
{
LogUtil.info(Name + "重置中 " + resetStep + ":InitNode OnlyGuoBan 模式,不需要验证转盘是否在线 ");
}
else
{
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
PUSICANControl.PUSICO_GetNodeStatus(node.NodeId, ref rStatus);
if (!rStatus.Equals(SLAVE_STATUS.SLAVESTATUS_WORK))
{
timeOutMsg = ResourceControl.GetString(ResourceControl.RNodeOnLine, " 旋转轴[{0}][{1}]上线", node.NodeId, rStatus);
isAllOk = false;
break;
}
}
}
}
if (!IOBase.NoLine)
{
PUSICANControl.PUSICO_GetNodeStatus(LWidthManager.Line_NodeAddr, ref rStatus);
if (!rStatus.Equals(SLAVE_STATUS.SLAVESTATUS_WORK))
{
timeOutMsg = ResourceControl.GetString(ResourceControl.RNodeOnLine, " 调宽轴[{0}][{1}]上线", LWidthManager.Line_NodeAddr, rStatus);
isAllOk = false;
lineOk = false;
}
}
if (WorkModeUtil.OnlyGuoBan)
{
if (!IOBase.NoLine)
{
PUSICANControl.InitRNodeConfig(LWidthManager.Line_NodeAddr, true);
Thread.Sleep(10);
LWidthManager.LineInitOk = true;
LogUtil.info(Name + " LWidthManager.LineInitOk =true");
}
if (lineOk)
{
ToRunning("当前为过板模式,转盘不需要复位,复位完成,进入运行状态");
}
}
else if (isAllOk.Equals(true))
{
LogUtil.info(Name + "重置中 " + resetStep + ":所有轴已连接");
//开始回原点
XYHomeMove_3();
}
//else if (isTimeOut)
//{
// if (lineOk)
// {
// WorkModeUtil.SelectMode(Name);
// //如果是过板模式,直接结束复位
// if (WorkModeUtil.OnlyGuoBan)
// {
// ToRunning("当前为过板模式,转盘不需要复位,复位完成,进入运行状态");
// }
// }
//}
}
else if (resetStep.Equals(ResetStep.XYHomeMove_3))
{
//判断是否都原点返回完成
bool isAllOk = true;
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
if (TSAVBean.IsInSuddenDown)
return;
if (!PUSICANControl.IsHomeEnd(node.NodeId))
{
timeOutMsg = ResourceControl.GetString(ResourceControl.RNodeGoHome, " 旋转轴[{0}]原点返回完成", node.NodeId);
isAllOk = false;
break;
}
}
}
if (isAllOk.Equals(true))
{
Thread.Sleep(PUSICANControl.SleepMS);
//初始化所有旋转轴
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
PUSICANControl.DefatutPosMove(node.NodeId, TSAVBean.RotateNode_DefaultPosition, 0);
}
}
resetStep = ResetStep.RNodeOnline_4;
LogUtil.info(Name + "重置中 "+resetStep+":所有旋转轴原点返回完成,开始到待机点:" + TSAVBean.RotateNode_DefaultPosition);
LastResetChangeTime = DateTime.Now;
}
}
else if (resetStep.Equals(ResetStep.RNodeOnline_4))
{
bool isAllOk = true;
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
int position = PUSICANControl.GetPosition(node.NodeId);
if (!(position.Equals(RotateNode_DefaultPosition)))
{
timeOutMsg = ResourceControl.GetString(ResourceControl.RNodeToPosition, " 旋转轴[{0}]走到待机点[{1}]", node.NodeId, RotateNode_DefaultPosition);
isAllOk = false;
break;
}
}
}
//int positiona = PUSICANControl.GetPosition(LWidthManager.Line_NodeAddr);
//if (!(positiona.Equals(LWidthManager.DefaultPosition)))
//{
// timeOutMsg = ResourceControl.GetString(ResourceControl.RNodeToPosition, " 调宽轴[{0}]走到待机点[{1}]", LWidthManager.Line_NodeAddr, LWidthManager.DefaultPosition);
// isAllOk = false;
//}
if (isAllOk.Equals(true))
{
ToRunning("重置完成:所有旋转轴回到待机点");
}
}
if (isTimeOut)
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.TimeOutMsg, "重置等待[{0}]超时{1}分", timeOutMsg, Math.Round(span.TotalMinutes, 1));
LogUtil.error(Name + WarnMsg);
}
}
public static void StartWork(BoardInfo boardInfo)
{
Work.StartWork(boardInfo);
}
public static void StopWork()
{
if (Status.Equals(TSAVStatus.Reset))
{
//Status = TSAVStatus.Wait;
}
else
{
StopMove();
}
}
private static bool IsProcess = false;
private static DateTime preShowImageTime = DateTime.Now;
/// <summary>
/// 工作定时器
/// </summary>
private static void workTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (IsProcess)
{
return;
}
IsProcess = true;
try
{
//判断是否收到急停信号
if ((!Status.Equals(TSAVStatus.Wait)) && IOManager.IOValue(IOManager.SuddenStop).Equals(IO_VALUE.LOW))
{
if (!IsInSuddenDown)
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.SuddenDownMsg, "收到急停信号,停止所有运动,设备断开连接");
LogUtil.error("收到急停信号,停止所有运动,断开can协议连接");
IsInSuddenDown = true;
StopWork();
//StopMove();
//PUSICANControl.Close();
IOManager.IOMove(IOManager.SMEMA_Up, IO_VALUE.LOW);
IOManager.IOMove(IOManager.SMEMA_Down, IO_VALUE.LOW);
}
}
//急停信号恢复,自动复位
else if (IOManager.IOValue(IOManager.SuddenStop).Equals(IO_VALUE.HIGH) && IsInSuddenDown)
{
if (Work.WorkType > 0)
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.AutoResetMsg, "急停恢复,自动重置设备");
LogUtil.error("急停恢复,自动重置设备, 开始连接can协议");
string msg = PUSICANControl.Open();
if (!msg.Equals(""))
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.AutoResetMsg, "急停恢复,自动重置设备") + " " +
ResourceControl.GetString(ResourceControl.CanConnectFail, "Can协议连接失败");
LogUtil.error(Name + "急停恢复,自动重置设备,设备连接失败:" + msg);
}
else
{
LogUtil.info(Name + "连接Can协议成功");
IsInSuddenDown = false;
StartReset();
}
}
}
if (!IsInSuddenDown)
{
if (Status.Equals(TSAVStatus.Reset))
{
ResetProcess();
}
else if (Status.Equals(TSAVStatus.Runing))
{
//正在工作中
if (Work.IsWorking)
{
WorkProcess();
}
else if (LineStep.moveType.Equals(1))
{
LineProcess();
}
else
{
StartLineCheck();
}
}
CheckPusicanAlarm();
AirCheckPro();
}
// IOManager.IOMove(IOManager.Warmer_Work, IO_VALUE.LOW);
}
catch (Exception ex)
{
LogUtil.error("workTimer_Elapsed出现错误:" + ex.ToString());
}
IsProcess = false;
}
private static void AirCheckPro()
{
if (IOManager.IOValue(IOManager.AirCheck_Single).Equals(IO_VALUE.LOW))
{
if (!NoAirAlarm)
{
NoAirAlarm = true;
LogUtil.error("未检测到气压信号");
}
}
else
{
if (NoAirAlarm)
{
NoAirAlarm = false;
LogUtil.error("自动解除:未检测到气压信号");
}
}
}
private static void WorkProcess()
{
if (Work.IsWaitMove)
{
//判断是否正在运动
CheckWorkWait();
}
if (!(Work.IsWaitMove))
{
TimeSpan span = DateTime.Now - Work.endWorkTime;
//bool IsFootOk = IOManager.IOValue(IOManager.Footrest_Single).Equals(IO_VALUE.HIGH) && (WorkMode.Equals(0));
bool IsFootOk = IOManager.IOValue(IOManager.Footrest_Single).Equals(IO_VALUE.HIGH) ;
if (Work.WorkType.Equals(1))
{
if (WorkMode.Equals(1))
{
if (IsFootOk)
{
if (canQieHuan)
{
if (WorkPause)
{
LogUtil.info("自动模式下 已暂停:再次踩脚踏信号,退出暂停状态,重置Work.endWorkTime");
Work.endWorkTime = new DateTime();
WorkPause = false;
}
else
{
LogUtil.info("自动模式下:收到脚踏信号,自动模式暂停,重置Work.endWorkTime");
Work.endWorkTime = new DateTime();
WorkPause = true;
}
canQieHuan = false;
}
}
else
{
if (!canQieHuan)
{
canQieHuan = true;
LogUtil.info("自动模式下:脚踏信号灭,设置 canQieHuan = true");
}
}
if (WorkPause)
{
//暂停中
}
else
{
//自动模式
if ((span.TotalSeconds > AuToModeSeconds && IsDebug)
|| (span.TotalSeconds > AuToModeSeconds && WorkMode.Equals(1))
)
{
Work.MoveToNextPoint(true);
}
}
}
else
{
//脚踏模式
if (IsFootOk
|| (span.TotalSeconds > AuToModeSeconds && IsDebug))
{
Work.MoveToNextPoint(true);
}
}
////等待脚踏板信号
//if (IsFootOk
// || (span.TotalSeconds > AuToModeSeconds && IsDebug)
// || (span.TotalSeconds > AuToModeSeconds && WorkMode.Equals(1))
// )
//{
// Work.MoveToNextPoint(true);
//}
}
else if (Work.WorkType.Equals(2) || Work.WorkType.Equals(3))
{
if (Work.WorkType.Equals(2))
{
if (IsFootOk || (span.TotalSeconds > Work.currPoint.WeldTime + 6 && IsDebug
|| (span.TotalSeconds > Work.currPoint.WeldTime + 6 && WorkMode.Equals(1))))
{
Work.MoveToNextPoint(true);
}
}
else if (Work.WorkType.Equals(3))
{
if (IsFootOk || (span.TotalSeconds > 8 && IsDebug
|| (span.TotalSeconds > 8 && WorkMode.Equals(1))))
{
Work.MoveToNextPoint(true);
}
}
}
}
}
private static DateTime preCheckTime = DateTime.Now;
/// <summary>
/// 验证是否 堵转,堵转需要断电
/// </summary>
private static void CheckPusicanAlarm()
{
if (IsInSuddenDown)
{
return;
}
TimeSpan span = DateTime.Now - preCheckTime;
if (span.TotalSeconds < 10)
{ return; }
preCheckTime = DateTime.Now;
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo node in map.Values)
{
if (PUSICANControl.IsDuZhuan(node.NodeId))
{
LogUtil.error(Name + " 发现旋转轴[" + node.NodeId + "]堵转,清除一下控制器状态,重新读取一下堵转状态");
Thread.Sleep(PUSICANControl.SleepMS);
//清除一下状态,在重新读一次
if (!TSAVBean.Status.Equals(TSAVStatus.Reset))
{
PUSICANControl.ClearStatus(node.NodeId);
}
Thread.Sleep(PUSICANControl.SleepMS);
if (PUSICANControl.IsDuZhuan(node.NodeId))
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.DuZhuanMsg, " 旋转轴[{0}]堵转,需要重置", node.NodeId);
LogUtil.error(Name + " " + WarnMsg);
return;
}
}
}
}
}
public static bool NextPoint(bool isNext, bool isResetBoard)
{
if (Status.Equals(TSAVStatus.Runing))
{
if (!Work.IsWorking)
{
//StartWork(BoardManager.CurrBoard);
return false;
}
if (Work.IsWaitMove)
{
//判断是否正在运动
CheckWorkWait();
}
if (!(Work.IsWaitMove))
{
Work.MoveToNextPoint(isNext, isResetBoard);
return true;
}
}
return false;
}
public static void StopRun()
{
StopMove();
//停止红外线灯
// IOManager.IOMove(IOManager.Inerared_Lamp, IO_VALUE.LOW);
IOManager.IOMove(IOManager.SMEMA_Down, IO_VALUE.LOW);
IOManager.IOMove(IOManager.SMEMA_Up, IO_VALUE.LOW);
workTimer.Enabled = false;
//PUSICANControl.Close();
Status = TSAVStatus.Wait;
MesUtil.Close();
}
public static void StopMove()
{
LogUtil.info("StopMove,停止所有运动");
BottomCylinderDown(false);
CylinderMove(IOManager.StopCylinder_Down, IOManager.StopCylinder_Up, false);
SideCyliderBack(false);
Work.StopWork();
LineStep.EndMove();
IOManager.IOMove(IOManager.Line_FStart, IO_VALUE.LOW);
LogUtil.info("StopMove,开始停止所有旋转轴");
if (WorkModeUtil.OnlyGuoBan)
{
LogUtil.info("StopMove,仅过板模式,不需要停止旋转轴");
}
else
{
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo nodeid in map.Values)
{
if (PUSICANControl.IsBusy(nodeid.NodeId))
{
PUSICANControl.StopMove(nodeid.NodeId);
Thread.Sleep(PUSICANControl.SleepMS);
}
}
}
}
}
private static void CheckWorkWait()
{
try
{
TimeSpan span = DateTime.Now - Work.LastSetpTime;
List<WaitResultInfo> list = Work.waitList;
string waitMsg = "";
bool isOk = WaitResultInfo.GetWaitResult(list, span, false, out waitMsg);
if (isOk)
{
Work.EndWait();
}
if (Work.IsWaitMove)
{
if (span.TotalSeconds > 30)
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.WaitTimeOutMsg, "组装中,等待【{0}】超时 已等待[{1}]秒", waitMsg, Math.Round(span.TotalSeconds, 0));
LogUtil.error(WarnMsg);
}
}
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
}
//public static double X_Min = (double)ConfigAppSettings.GetNumValue(Setting_Init.XAxis_MinValue);
//public static double X_Max = (double)ConfigAppSettings.GetNumValue(Setting_Init.XAxis_MaxValue);
//public static double Y_Min = (double)ConfigAppSettings.GetNumValue(Setting_Init.YAxis_MinValue);
//public static double Y_Max = (double)ConfigAppSettings.GetNumValue(Setting_Init.YAxis_MaxValue);
public static double X_Min = 1;
public static double X_Max = 1920;
public static double Y_Min = 1;
public static double Y_Max = 1080;
public static double X_ChangeValue = 1;
public static double Y_ChangeValue = 1;
/// <summary>
/// 判断是否是有效的地址
/// </summary>
public static bool IsValidPosition(double x, double y)
{
if (X_Min <= x && x <= X_Max && Y_Min <= y && y <= Y_Max)
{
return true;
}
return false;
}
public static string GetShowMsg()
{
string ShowMsg = "";
if (TSAVBean.IsInSuddenDown)
{
ShowMsg = ResourceControl.GetString(ResourceControl.DeviceInSuddenStop, "设备急停中");
}else if (TSAVBean.NoAirAlarm)
{
ShowMsg = ResourceControl.GetString(ResourceControl.NoAirAlarm, "未检测到气压信号");
}
else if (TSAVBean.Status.Equals(TSAVStatus.Wait))
{
ShowMsg = ResourceControl.GetString(ResourceControl.DeviceNotStart, "设备未启动")+" "+startRunMsg;
}
else if (TSAVBean.Status.Equals(TSAVStatus.Reset))
{
ShowMsg = ResourceControl.GetString(ResourceControl.DeviceInGohome, "设备正在原点返回中");
}
else if (TSAVBean.Status.Equals(TSAVStatus.Runing))
{
string msg = ResourceControl.GetString(ResourceControl.DeviceInWork, "设备工作中");
string lineMsg = ResourceControl.GetString(ResourceControl.LineTurn, "流水线转动中");
if (TSAVBean.Work.IsWorking)
{
TimeSpan span = DateTime.Now - TSAVBean.Work.beginWorkTime;
int count = TSAVBean.Work.BoardCount;
string time = span.Hours.ToString().PadLeft(2, '0') + ":" + span.Minutes.ToString().PadLeft(2, '0') + ":" + span.Seconds.ToString().PadLeft(2, '0');
ShowMsg = ResourceControl.GetString(ResourceControl.WorkInfoMsg, "已工作{0},{1}块电路板", time, count) + "\r\n" + TSAVBean.WarnMsg;
}
else if (TSAVBean.LineStep.moveType.Equals(1))
{
ShowMsg = lineMsg + "\r\n" + TSAVBean.WarnMsg;
}
else
{
ShowMsg = msg + "\r\n" + TSAVBean.WarnMsg;
}
}
return ShowMsg;
}
}
public class NodeInfo
{
public NodeInfo(uint nodeId, string name, string str)
{
this.NodeId = nodeId;
this.NodeName = name;
this.NodeStr = str;
}
public uint NodeId { get; set; }
public string NodeName { get; set; }
public string NodeStr { get; set; }
}
}