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
| using System;
| using System.Collections.Generic;
| using System.ComponentModel;
| using System.Drawing;
| using System.Linq;
| using System.Reflection;
| using System.Resources;
| using System.Text;
| using System.Threading.Tasks;
| using System.Windows.Media;
|
| namespace Bro.Common.Helper
| {
| public static class EnumHelper
| {
| /// <summary>
| /// 根据枚举的代码名称获取枚举列表信息
| /// </summary>
| /// <param name="enumName"></param>
| /// <returns></returns>
| public static List<dynamic> GetEnumListByName(string enumName, string assemblyName = "Common.Helper.EnumHelper+")
| {
| List<dynamic> list = new List<dynamic>();
|
| string fullName = assemblyName + enumName;
|
| Type t = typeof(EnumHelper).Assembly.GetType(fullName);
|
| t.GetEnumNames().ToList().ForEach(e =>
| {
| int value = Convert.ToInt32(Enum.Parse(t, e));
| string desc = ((Enum)Enum.Parse(t, e)).GetEnumDescription();
| var item = new { Value = value, Desc = desc, Code = e };
| list.Add(item);
| });
|
| return list;
| }
|
| public static List<dynamic> GetEnumListByType(Type enumType)
| {
| List<dynamic> list = new List<dynamic>();
|
| enumType.GetEnumNames().ToList().ForEach(e =>
| {
| int value = Convert.ToInt32(Enum.Parse(enumType, e));
| string desc = ((Enum)Enum.Parse(enumType, e)).GetEnumDescription();
| var item = new { Value = value, Desc = desc, Code = e };
| list.Add(item);
| });
|
| return list;
| }
|
| /// <summary>
| /// 获取具体某一枚举的中文描述
| /// </summary>
| /// <param name="enumObj"></param>
| /// <returns></returns>
| public static string GetEnumDescription(this Enum enumObj)
| {
| Type t = enumObj.GetType();
| FieldInfo f = t.GetField(enumObj.ToString());
|
| DescriptionAttribute attr = f.GetCustomAttribute<DescriptionAttribute>();
| if (attr != null)
| {
| return attr.Description;
| }
| else
| {
| return null;
| }
| }
|
| public static string GetPartSFCName(this PartType partType)
| {
| Type t = partType.GetType();
| FieldInfo f = t.GetField(partType.ToString());
|
| SFCNameAttribute attr = f.GetCustomAttribute<SFCNameAttribute>();
| if (attr != null)
| {
| return attr.SFCAlias;
| }
| else
| {
| return "";
| }
| }
|
| public static System.Windows.Media.Color GetEnumSelectedMediaColor(this Enum enumObj)
| {
| Type t = enumObj.GetType();
| FieldInfo f = t.GetField(enumObj.ToString());
|
| ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
| if (attr != null)
| {
| var prop = typeof(Colors).GetProperties().FirstOrDefault(p => p.Name == attr.SelectedColor);
| if (prop != null)
| {
| return (System.Windows.Media.Color)prop.GetValue(null);
| }
| }
| return Colors.Transparent;
| }
|
| public static System.Drawing.Color GetEnumSelectedColor(this Enum enumObj)
| {
| Type t = enumObj.GetType();
| FieldInfo f = t.GetField(enumObj.ToString());
|
| ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
| if (attr != null)
| {
| return System.Drawing.Color.FromName(attr.SelectedColor);
| }
| else
| {
| return System.Drawing.Color.Transparent;
| }
| }
|
| public static string GetEnumSelectedColorString(this Enum enumObj)
| {
| Type t = enumObj.GetType();
| FieldInfo f = t.GetField(enumObj.ToString());
|
| ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
| if (attr != null)
| {
| return attr.SelectedColor;
| }
| else
| {
| return "Transparent";
| }
| }
|
|
| /// <summary>
| /// 当枚举牵涉到状态变换,检查现状态是否满足待转换的状态的前置状态要求
| /// </summary>
| /// <param name="stateToBe"></param>
| /// <param name="currentState"></param>
| /// <returns></returns>
| public static bool CheckPreStateValid(this Enum stateToBe, int currentState)
| {
| Type t = stateToBe.GetType();
| FieldInfo f = t.GetField(stateToBe.ToString());
|
| PreStateAttribute attr = f.GetCustomAttribute<PreStateAttribute>();
| if (attr == null)
| {
| return true;
| }
| else
| {
| return attr.CheckPreStateValid(currentState);
| }
| }
|
| /// <summary>
| /// 设备状态定义
| /// 未初始化和异常状态无前置状态要求
| /// 初始化操作前置状态必须是未初始化、关闭状态和异常状态
| /// 打开前置必须是初始化和暂停
| /// 关闭前置必须是打开和暂停和异常
| /// 暂停前置必须是打开
| /// </summary>
| public enum DeviceState
| {
| TBD = -1,
|
| [ColorSelect("Gray")]
| [Description("未初始化")]
| DSUninit = 1,
|
| [ColorSelect("Gold")]
| [PreState(1 + 2 + 4 + 8 + 32)]
| [Description("已初始化")]
| DSInit = 2,
|
| [ColorSelect("Lime")]
| [PreState(2 + 4 + 16)]
| [Description("已打开")]
| DSOpen = 4,
|
| [ColorSelect("Gray")]
| [PreState(1 + 4 + 8 + 16 + 32)]
| [Description("已关闭")]
| DSClose = 8,
|
| [ColorSelect("Gold")]
| [PreState(4 + 16)]
| [Description("已暂停")]
| DSPause = 16,
|
| [ColorSelect("Red")]
| [Description("异常状态")]
| DSExcept = 32
| }
|
| /// <summary>
| /// 工序状态
| /// </summary>
| public enum ProcessState
| {
| [Description("空闲")]
| Idel = 1,
| [Description("运行中")]
| Running = 2,
| [Description("完成")]
| Done = 3,
| [Description("异常")]
| Exceptional = 99,
| }
|
| public enum DeviceAttributeType
| {
| [Description("设备驱动")]
| Device = 1,
|
| [Description("初始配置")]
| InitialConfig = 2,
| [Description("操作配置")]
| OperationConfig = 4,
| [Description("设备配置")]
| DeviceConfig = 8,
| [Description("输入配置")]
| InputConfig = 16,
|
| [Description("初始配置控件")]
| InitialConfigCtrl = 32,
| [Description("操作配置控件")]
| OperationConfigCtrl = 64,
| [Description("设备配置控件")]
| DeviceConfigCtrl = 128,
| [Description("输入配置控件")]
| InputConfigCtrl = 256,
|
| [Description("运行控件")]
| RunCtrl = 512,
|
| [Description("操作配置面板")]
| OperationConfigPanel = 1024,
| }
|
| public enum EnableState
| {
| [Description("启用")]
| Enabled = 0,
| [Description("禁用")]
| Disabled = 1,
| }
|
| public enum EnableStateFilter
| {
| [Description("全部")]
| All = -1,
| [Description("启用")]
| Enabled = 0,
| [Description("禁用")]
| Disabled = 1,
| }
|
| public enum OutputResultCommon
| {
| [Description("OK")]
| OK = 1,
| [Description("NG")]
| NG = 2,
| }
|
| /// <summary>
| /// 设备工作后的输出结果
| /// </summary>
| public enum OutputResult
| {
| [Description("分支一")]
| Branch1 = 1,
| [Description("分支二")]
| Branch2 = 2,
| [Description("分支三")]
| Branch3 = 4,
| [Description("分支四")]
| Branch4 = 8,
| [Description("分支五")]
| Branch5 = 16,
| [Description("分支六")]
| Branch6 = 32,
| [Description("分支七")]
| Branch7 = 64,
| [Description("分支八")]
| Branch8 = 128,
| }
|
| /// <summary>
| /// PLC项目的值的类型
| /// </summary>
| public enum PLCItemType
| {
| [Description("布尔类型")]
| Bool = 0,
| [Description("整型")]
| Integer = 1,
| [Description("字符串型")]
| String = 2,
| }
|
| /// <summary>
| /// 对PLC项目的操作类型
| /// </summary>
| public enum PLCOpType
| {
| [Description("读取")]
| Read = 1,
| [Description("写入")]
| Write = 2,
| [Description("监控")]
| Monitor = 4,
|
| /// <summary>
| /// 报警监控 1+8
| /// </summary>
| [Description("报警监控")]
| WarningMonitor = 9,
|
| /// <summary>
| /// CT监控 1+16
| /// </summary>
| [Description("CT监控")]
| CTMonitor = 17,
| }
|
| /// <summary>
| /// PLC的运行模式
| /// </summary>
| public enum PLCRunMode
| {
| [Description("自动模式")]
| Auto = 0,
| [Description("手动模式")]
| Manual = 1
| }
|
| /// <summary>
| /// 相机运行模式
| /// </summary>
| public enum CameraOpMode
| {
| [Description("拍照")]
| Snapshot = 1,
| [Description("扫描")]
| Scan = 2,
| }
|
| /// <summary>
| /// 设备操作类型
| /// </summary>
| public enum DeviceMode
| {
| [Description("编辑时")]
| Edit = 1,
| [Description("运行时")]
| Run = 2,
| }
|
| /// <summary>
| /// 日志类型
| /// </summary>
| public enum LogType
| {
| [Description("警告信息")]
| Exception_Warning = 1,
| [Description("错误信息")]
| Exception_Error = 2,
| [Description("致命信息")]
| Exception_Fatal = 3,
|
| [Description("设备信息")]
| Info_Device = 11,
| [Description("工序信息")]
| Info_Process = 12,
| [Description("操作信息")]
| Info_Operation = 13,
|
| [Description("用户操作信息")]
| User_Operation = 21,
|
| [Description("测量结果")]
| MeasureResult = 31,
| }
|
| /// <summary>
| /// 马达/运动板卡运行模式
| /// </summary>
| public enum MotorMoveMode
| {
| /// <summary>
| /// 普通点位运动
| /// </summary>
| [Description("普通点位运动")]
| Normal = 1,
|
| ///// <summary>
| ///// 高速等距运动
| ///// </summary>
| //[Description("高速等距运动")]
| //HighSpeedStep = 2,
|
| ///// <summary>
| ///// 高速不等距运动
| ///// </summary>
| //[Description("高速不等距运动")]
| //HighSpeed = 3,
|
| /// <summary>
| /// 找正限位运动
| /// </summary>
| [Description("找正限位运动")]
| FindPositive = 4,
|
| /// <summary>
| /// 离开正限位
| /// </summary>
| [Description("离开正限位")]
| LeavePositive = 5,
|
| /// <summary>
| /// 找负限位运动
| /// </summary>
| [Description("找负限位运动")]
| FindNegative = 6,
|
| /// <summary>
| /// 离开负限位
| /// </summary>
| [Description("离开负限位")]
| LeaveNegative = 7,
|
| /// <summary>
| /// 找原点运动
| /// </summary>
| [Description("找原点运动")]
| FindOri = 8,
|
| /// <summary>
| /// Jog模式
| /// </summary>
| [Description("Jog模式")]
| Jog = 9,
|
| /// <summary>
| /// 读数头找原点方式
| /// </summary>
| [Description("读数头找原点方式")]
| FindOriIndex = 10,
|
| /// <summary>
| /// 插补模式
| /// </summary>
| [Description("插补模式")]
| Coordinate = 11,
|
| ///// <summary>
| ///// 刀向更随功能
| ///// </summary>
| //[Description("刀向更随功能")]
| //BufMove = 12,
| }
|
| /// <summary>
| /// 马达IO定义类型
| /// </summary>
| public enum MotorIODefine
| {
| Nothing,
| InputStartLeft,
| InputStartRight,
| InputCurtainLeft,
| InputCurtainRight,
| InputSafeDoor,
| InputEmergency,
| InputReset,
| InputScrew1,
| InputScrew2,
| InputSuckLeft,
| InputSuckRight,
| InputSuckXYZ,
| InputCylinderLeftLimitFront,
| InputCylinderLeftLimitBack,
| InputCylinderRightLimitFront,
| InputCylinderRightLimitBack,
|
|
| OutputYellow,
| OutputGreen,
| OutputRed,
| OutputBeep,
| OutputLight,
| OutputMotorPower,
| OutputInitOK,
| OutputZLock,
| OutputLeftCylinder,
| OutputRightCylinder,
| OutputLeftSuck,
| OutputRightSuck,
| OutputScrewBlow,
| OutputCamera,
| OutputScrewSuck,
| }
|
| /// <summary>
| /// GTS运动板卡控制返回控制码
| /// </summary>
| public enum GTSRetCode
| {
| [Description("指令执行成功")]
| GRCRunOK = 0, // 指令执行成功
| [Description("指令执行错误")]
| GRCRunErr = 1, // 指令执行错误
| [Description("icense不支持")]
| GRCNotSupport = 2, // icense不支持
| [Description("指令参数错误")]
| GRCInvalidParam = 7, // 指令参数错误
| [Description("主机和运动控制器通讯失败")]
| GRCCommErr = -1, // 主机和运动控制器通讯失败
| [Description("打开控制器失败")]
| GRCOpenErr = -6, // 打开控制器失败
| [Description("运动控制器没有响应")]
| GRCNotAck = -7 // 运动控制器没有响应
| }
|
| /// <summary>
| /// 机台工位设置
| /// </summary>
| public enum WorkStation
| {
| [Description("左工位")]
| Left = 1,
| [Description("右工位")]
| Right = 2
| }
|
| /// <summary>
| /// 零件类型
| /// </summary>
| public enum PartType
| {
| [Description("托盘")]
| Tray,
|
| [Description("流程卡")]
| ProcessCard,
|
| [SFCName("ENCL")]
| [Description("外壳")]
| Housing,
|
| [SFCName("LATOR")]
| [Description("绝缘片")]
| Insulator,
|
| [SFCName("TOP")]
| [Description("散热片")]
| TopSpread,
|
| [SFCName("PWRSPLY")]
| [Description("PSU")]
| PSU,
|
| [Description("WIP")]
| WIP,
| }
|
| /// <summary>
| /// 装载结果
| /// </summary>
| public enum MountResult
| {
| [Description("未装载")]
| NULL = -1,
| [Description("开始装载")]
| START = 99,
| [Description("OK")]
| OK = 1,
| [Description("NG")]
| NG = 0,
| [Description("过站OK")]
| PASS = 2
| }
|
| /// <summary>
| /// 订阅发布类型
| /// </summary>
| public enum PubTag
| {
| //[Description("RFID标签上传")]
| //RFIDCodeUpdate,
| [Description("条码上传")]
| BarcodeUpdate,
| [Description("产品条码信息上传")]
| ProductionCodeUpdate,
| [Description("图像上传")]
| ImageUpdate,
| [Description("图像清除")]
| ImageClear,
| [Description("螺丝扭矩上传")]
| ScrewTorqueUpdate,
| [Description("螺丝平面检测上传")]
| ScrewPlaneUpdate,
|
| [Description("异常信息上传")]
| ExceptionUpdate,
| [Description("PLC报警信息上传")]
| PLCWarningUpdate,
|
| [Description("DownTime通知")]
| DownTimeNotice,
|
| [Description("来料剩余通知")]
| TrayRemain,
|
| [Description("CT时间上传")]
| CTUpdate,
|
| [Description("简单信息上传")]
| SimpleInfoUpdate,
|
| [Description("设备状态")]
| DeviceState,
| [Description("设备操作")]
| DeviceOperation,
|
| [Description("特征点数据上传")]
| FeaturePointUpdate,
| [Description("引导值上传")]
| AdjustUpdate,
| [Description("螺丝图像点位数据上传")]
| ScrewImagePositionUpdate,
| [Description("螺丝运动点位数据上传")]
| ScrewPositionUpdate,
|
| [Description("Log信息")]
| LogInfo,
|
| [Description("工站完成信息")]
| StationDone,
|
| #region ByPass
| /// <summary>
| /// ByPass模式下输入条码
| /// </summary>
| [Description("ByPass模式下输入条码")]
| OnByPassInput,
|
| /// <summary>
| /// ByPass模式切换
| /// </summary>
| [Description("ByPass模式切换")]
| ByPassModeChange,
|
| /// <summary>
| /// ByPass模式操作完成
| /// </summary>
| [Description("ByPass模式操作完成")]
| ByPassOpDone,
|
| /// <summary>
| /// ByPass模式过站检查
| /// </summary>
| [Description("ByPass模式过站检查")]
| ByPassPreCheck,
|
| /// <summary>
| /// ByPass模式来料检查
| /// </summary>
| [Description("ByPass模式来料检查")]
| ByPassIncomingCheck,
| #endregion
|
| #region 总线PLC
| [Description("总线PLC数据上传")]
| MainPLCDataUpdate,
| #endregion
|
| #region Calibration
| [Description("单次标定完成")]
| CalibStepDone,
| [Description("全部标定完成")]
| CalibAllDone,
| #endregion
|
| [Description("视觉计算结果")]
| VisionResult,
| }
|
| /// <summary>
| /// 站点操作模式 PLC通信使用
| /// </summary>
| public enum StationMode
| {
| [ColorSelect("Transparent")]
| [Description("无状态")]
| NULL = -1,
| [ColorSelect("Green")]
| [Description("自动模式")]
| AUTO = 1,
| [ColorSelect("Gold")]
| [Description("手动模式")]
| MANUAL = 0,
| }
|
| /// <summary>
| /// 站点状态 PLC通信使用
| /// </summary>
| public enum StationState
| {
| [ColorSelect("Transparent")]
| [Description("无状态")]
| NULL,
| [ColorSelect("Red")]
| [Description("故障状态")]
| ERROR,
| [ColorSelect("Green")]
| [Description("运行状态")]
| RUN,
| [ColorSelect("Gold")]
| [Description("暂停状态")]
| PAUSE,
| }
|
| public enum WarningFromPC
| {
| OK = 0,
|
| SFCPartFail = 1,
| SFCProductionFail = 2,
| SFCNetError = 3,
|
| LocalNetError = 11,
|
| UnknowError = 21,
|
| /// <summary>
| /// 取料持续失败
| /// </summary>
| PickContinuousFailure = 31,
|
| /// <summary>
| /// 持续抛料
| /// </summary>
| ContinuousRejection = 32,
|
| /// <summary>
| /// 俯拍安装持续失败
| /// </summary>
| InstallContinuousFailure = 33,
| }
|
| //public enum CameraDriverType
| //{
| // Halcon,
| // //HalconPlugIn,
| // Hik,
| //}
|
| public enum ImageType
| {
| Bmp,
| Jpeg,
| }
|
| public enum PLCReplyValue
| {
| OK = 1,
| NG = -1,
| IGNORE = -999,
| }
|
| public enum PriorityDirection
| {
| X,
| Y,
| }
|
| public enum ElementState
| {
| New = 1,
| MouseHover = 2,
| MouseInSide = 3,
| Selected = 4,
| Moving = 5,
|
| Normal = 11,
|
| Measuring = 21,
| MeasureDoneOK = 22,
| MeasureDoneNG = 23,
| }
|
| public enum MouseState
| {
| Normal = 1,
| HoverElement = 2,
| InSideElement = 3,
|
| StretchingLeft = 11,
| StretchingRight = 12,
| StretchingUp = 13,
| StretchingDown = 14,
| MoveElement = 15,
|
| New = 21,
| Editing = 22,
| SelectedElement = 23,
|
| MovingAll = 31,
|
| SelectionZone = 41,
| SelectionZoneDoing = 42,
| }
|
| public enum RunMode
| {
| [Description("设置模式")]
| SetMode = 0,
| [Description("运行模式")]
| RunMode = 1,
| }
| }
| }
|
|