MainMachine _LedRGBProcess.cs
5.1 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
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using static System.Windows.Forms.AxHost;
namespace DeviceLibrary
{
partial class MainMachine
{
private Flyelectronic_485_RGB_Controller rGB_Controller = null;
private bool rgbLedInitOk = false;
public string lastColor = "";
System.Threading.Timer ledRgbTimer;
public bool CloseRgbLed()
{
if(rgbLedInitOk)
{
rGB_Controller.Dispose();
}
return true;
}
public bool InitRgbLed(out string msg)
{
msg = "";
string port = Setting_Init.Device_LedLight_PortName;
if (port == "")
{
LogUtil.info( "未配置LED灯端口号");
return false;
}
rGB_Controller = new Flyelectronic_485_RGB_Controller("LED");
bool result = rGB_Controller.OpenPort(port, out msg);
if (result)
{
LogUtil.error("LED灯初始化成功");
rgbLedInitOk = true;
ledRgbTimer = new System.Threading.Timer(new TimerCallback(RgbLedProcess), null, 0, 1000);
GC.KeepAlive(ledtimer);
msg = "";
return true;
}
else
{
LogUtil.error("LED灯初始化失败:" + msg);
}
return false;
}
public void CloseColor()
{
rGB_Controller.CloseLed();
lastColor = "";
}
public void ShowColor(Color color)
{
if (lastColor!=""&& lastColor.Equals(color.Name.ToString()))
{
return;
}
//rGB_Controller.CloseLed();
rGB_Controller.ShowColor(color);
lastColor = color.Name.ToString();
}
public void ShowYellowLight()
{
lastColor = "yellowL";
//rGB_Controller.CloseLed();
rGB_Controller.ShowYellowLight();
}
public void ShowGreenLight()
{
lastColor = "greenL";
//rGB_Controller.CloseLed();
rGB_Controller.ShowGreenLight();
}
private void RgbLedProcess(object o)
{
if (rGB_Controller == null || (!rgbLedInitOk))
{
return;
}
// 红色: 急停,
//紫色: 异常,
//蓝绿: 待机
//流动绿: 入库
//流动黄: 出库,
//白色: 等待用户响应(等待取走盘等),
//蓝色: 扫码检测
if (runStatus == RunStatus.Stop)
{
//未启动 黑色
ShowColor(Color.Black);
}
else if (isInSuddenDown)
{
//红色: 急停,
ShowColor(Color.Red);
}
else if (hasAlarm)
{
//紫色: 异常,
ShowColor(Color.Purple);
} //温度超限
else if (IsTHoutRange())
{
//紫色: 异常,
ShowColor(Color.Purple);
}
//温度超限30分钟
else if (IsTHoutRangeOver30m())
{
//紫色: 异常,
ShowColor(Color.Purple);
}
else if (runStatus == RunStatus.Running)
{
var h = NGDoor_Tray_Test_Reel;
if (h != null && h.Value)
{
//等待料盘拿走
//白色: 等待用户响应(等待取走盘等),
//蓝色: 扫码检测
ShowColor(Color.White);
}
else if (ClampMoveInfo.IsStep(MoveStep.ReelClamp_10) && (!RobotManage.InoutDebugMode) && (!ClampMoveInfo.MoveParam.IsNg))
{
//蓝色: 扫码检测
ShowColor(Color.Blue);
}
//出入库 绿闪 黄闪
else if (StoreMoveInfo.MoveStep >= MoveStep.StoreOut10)
{
////流动黄: 出库,
//if (lastColor.Equals("yellowRun"))
//{
// return;
//}
ShowYellowLight();
}
else if (StoreMoveInfo.MoveStep >= MoveStep.StoreIn01)
{
////流动绿: 入库
//if (lastColor.Equals("yellowRun"))
//{
// return;
//}
ShowGreenLight();
}
}
else
{
//待机 蓝绿
ShowColor(Color.FromArgb(0, 128, 128));
}
}
}
}