LEDExcute.cs
6.81 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
using LEDhelp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LedHelper
{
public class LEDExcute
{
LEDHelper ProduceLED;
LEDHelper BatteriesLED;
LEDHelper PartsStation1LED;
LEDHelper PartsStation2LED;
public Queue<string> ProduceQueue { get; set; } = new Queue<string>();
public Queue<string> BatteriesQueue { get; set; } = new Queue<string>();
public Queue<string> PartsStation1Queue { get; set; } = new Queue<string>();
public Queue<string> PartsStation2Queue { get; set; } = new Queue<string>();
public LEDExcute()
{
string produceLedIP = ConfigurationManager.AppSettings["ProductLedIP"];
string batteriesLedIP = ConfigurationManager.AppSettings["BatteriesLedIP"];
string partsStation1LedIP = ConfigurationManager.AppSettings["PartsStation1LedIP"];
string partsStation2LedIP = ConfigurationManager.AppSettings["PartsStation2LedIP"];
int ledPort = Convert.ToInt32(ConfigurationManager.AppSettings["ledPort"]);
ProduceLED = new LEDhelp.LEDHelper(produceLedIP, (uint)ledPort, 1);
BatteriesLED = new LEDhelp.LEDHelper(batteriesLedIP, (uint)ledPort, 1);
PartsStation1LED = new LEDhelp.LEDHelper(partsStation1LedIP, (uint)ledPort, 1);
PartsStation2LED = new LEDhelp.LEDHelper(partsStation2LedIP, (uint)ledPort, 1);
}
public void BeginSendInfo()
{
Task.Run(async () =>
{
while (true)
{
await Task.Delay(2000);
if (ProduceLED != null && ProduceQueue != null && ProduceQueue.Count > 0)
{
SCREEN_ForceOnOff(LEDhelp.LEDHelper.Produce, LEDhelp.LEDHelper.OPEN);
SCREEN_DelDynamicArea(LEDhelp.LEDHelper.Produce, 0);
sendLedInfo(LEDhelp.LEDHelper.Produce, LEDhelp.LEDHelper.GREEN, ProduceQueue.Dequeue());
setBrightness(LEDhelp.LEDHelper.Produce, 5);
}
if (BatteriesLED != null && BatteriesQueue != null && BatteriesQueue.Count > 0)
{
SCREEN_ForceOnOff(LEDhelp.LEDHelper.Batteries, LEDhelp.LEDHelper.OPEN);
SCREEN_DelDynamicArea(LEDhelp.LEDHelper.Batteries, 0);
sendLedInfo(LEDhelp.LEDHelper.Batteries, LEDhelp.LEDHelper.RED, BatteriesQueue.Dequeue());
setBrightness(LEDhelp.LEDHelper.Batteries, 5);
}
if (PartsStation1LED != null && PartsStation1Queue != null && PartsStation1Queue.Count > 0)
{
SCREEN_ForceOnOff(LEDhelp.LEDHelper.PartsStation1, LEDhelp.LEDHelper.OPEN);
SCREEN_DelDynamicArea(LEDhelp.LEDHelper.PartsStation1, 0);
sendLedInfo(LEDhelp.LEDHelper.PartsStation1, LEDhelp.LEDHelper.RED, PartsStation1Queue.Dequeue());
setBrightness(LEDhelp.LEDHelper.PartsStation1, 5);
}
if (PartsStation2LED != null && PartsStation2Queue != null && PartsStation2Queue.Count > 0)
{
SCREEN_ForceOnOff(LEDhelp.LEDHelper.PartsStation2, LEDhelp.LEDHelper.OPEN);
SCREEN_DelDynamicArea(LEDhelp.LEDHelper.PartsStation2, 0);
sendLedInfo(LEDhelp.LEDHelper.PartsStation2, LEDhelp.LEDHelper.RED, PartsStation2Queue.Dequeue());
setBrightness(LEDhelp.LEDHelper.PartsStation2, 5);
}
}
});
}
private void sendLedInfo(int direction, int color, String sendText)
{
if (color == LEDhelp.LEDHelper.GREEN)
{
sendText = "\\C2" + sendText;
}
else if (color == LEDhelp.LEDHelper.YELLOW)
{
sendText = "\\C3" + sendText;
}
else
{
sendText = "\\C1" + sendText;
}
if (direction == LEDhelp.LEDHelper.Produce)
{
ProduceLED.SendLedInfo(sendText);
}
if(direction == LEDhelp.LEDHelper.Batteries)
{
BatteriesLED.SendLedInfo(sendText);
}
if (direction == LEDhelp.LEDHelper.PartsStation1)
{
PartsStation1LED.SendLedInfo(sendText);
}
if (direction == LEDhelp.LEDHelper.PartsStation2)
{
PartsStation2LED.SendLedInfo(sendText);
}
}
private void SCREEN_ForceOnOff(int direction, byte status)
{
if (direction == LEDhelp.LEDHelper.Produce)
{
ProduceLED.SCREEN_ForceOnOff(status);
}
if (direction == LEDhelp.LEDHelper.Batteries)
{
BatteriesLED.SCREEN_ForceOnOff(status);
}
if (direction == LEDhelp.LEDHelper.PartsStation1)
{
PartsStation1LED.SCREEN_ForceOnOff(status);
}
if (direction == LEDhelp.LEDHelper.PartsStation2)
{
PartsStation2LED.SCREEN_ForceOnOff(status);
}
}
// value 0-15 值越大亮度越大
public void setBrightness(int direction, byte value)
{
if (direction == LEDhelp.LEDHelper.Produce)
{
ProduceLED.setBrightness(1, value, null);
}
if (direction == LEDhelp.LEDHelper.Batteries)
{
BatteriesLED.setBrightness(1, value, null);
}
if (direction == LEDhelp.LEDHelper.PartsStation1)
{
PartsStation1LED.setBrightness(1, value, null);
}
if (direction == LEDhelp.LEDHelper.PartsStation2)
{
PartsStation2LED.setBrightness(1, value, null);
}
}
public void SCREEN_DelDynamicArea(int direction, byte DeleteAreaId)
{
if (direction == LEDhelp.LEDHelper.Produce)
{
ProduceLED.SCREEN_DelDynamicArea(DeleteAreaId);
}
if (direction == LEDhelp.LEDHelper.Batteries)
{
BatteriesLED.SCREEN_DelDynamicArea(DeleteAreaId);
}
if (direction == LEDhelp.LEDHelper.PartsStation1)
{
PartsStation1LED.SCREEN_DelDynamicArea(DeleteAreaId);
}
if (direction == LEDhelp.LEDHelper.PartsStation2)
{
PartsStation2LED.SCREEN_DelDynamicArea(DeleteAreaId);
}
}
}
}