MainMachine _LedProcess.cs
4.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
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
partial class MainMachine
{
Led AlarmLed;
Led StandbyLed;
Led RunningLed;
Led RightLed;
Led LeftLed;
System.Threading.Timer ledtimer;
void LedProcessInit()
{
ledtimer = new System.Threading.Timer(new TimerCallback(LedProcess), null, 0, 1000);
GC.KeepAlive(ledtimer);
}
void LedProcess(object o)
{
StandbyLed.LedState = LedState.off;
AlarmLed.LedState = LedState.off;
RunningLed.LedState = LedState.off;
RightLed.LedState = LedState.off;
LeftLed.LedState = LedState.off;
//无法运行,量报警灯
if (!canRunning)
{
AlarmLed.LedState = LedState.on;
}
//所有过程都在运动,闪烁运行中灯
//if (!RightMoveInfo.IsStep(MoveStep.Wait)
// || !LeftMoveInfo.IsStep(MoveStep.Wait)
// || !MiddleMoveInfo.IsStep(MoveStep.M_Standby)
// || LabelMoveInfo.IsStep(MoveStep.Lbl_WaitPrint))
//{
// RunningLed.LedState = LedState.on;
//}
if (alarmType != AlarmType.None)
{
AlarmLed.LedState = LedState.on;
AlarmBuzzer.ON();
}
else {
AlarmBuzzer.OFF();
}
if (runStatus == RunStatus.HomeReset)
{
StandbyLed.LedState = LedState.blink;
}
if (runStatus == RunStatus.Running)
{
RunningLed.LedState = LedState.on;
//右侧料串已空
if (RightMoveInfo.IsStep(MoveStep.Wait) && IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH) && RightShelfNoTray)
{
//Msg.add("右侧料串已空,等待取走料串",MsgLevel.warning);
if (IOValue(IO_Type.RightCar_Check).Equals(IO_VALUE.HIGH))
RightLed.LedState = LedState.on;
else
RightLed.LedState = LedState.blink;
}
//左侧料串已满
if (LeftMoveInfo.IsStep(MoveStep.Wait) && IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH) && LeftShelfNoTray)
{
//Msg.add("作侧料串已满,等待取走料串", MsgLevel.warning);
if (IOValue(IO_Type.LeftCar_Check).Equals(IO_VALUE.HIGH))
LeftLed.LedState = LedState.blink;
else
LeftLed.LedState = LedState.blink;
}
}
Led.LedGroup.ForEach((x) => { x.run(); });
}
}
public class Led {
public static List<Led> LedGroup = new List<Led>();
public LedState LedState = LedState.off;
ushort ledio;
public Led(ushort io) {
ledio = io;
LedGroup.Add(this);
}
IO_VALUE iovalue;
IO_VALUE lastiovalue;
public void run() {
if (this.LedState == LedState.on) {
iovalue = IO_VALUE.HIGH;
}
if (this.LedState == LedState.off)
{
iovalue = IO_VALUE.LOW;
}
if (this.LedState == LedState.blink)
{
if (iovalue == IO_VALUE.LOW)
{
iovalue = IO_VALUE.HIGH;
}
else {
iovalue = IO_VALUE.LOW;
}
}
if (iovalue != lastiovalue) {
lastiovalue = iovalue;
IOManager.WriteSingleDO("", 0x00, ledio, iovalue);
}
}
}
public enum LedState {
off,
on,
blink
}
}