FilterMachine.cs
8.5 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
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;
namespace DeviceLibrary
{
public partial class FilterMachine : MachineBase, IRobot
{
private Config_Filter _config;
public new Config_Filter Config
{
get => _config;
set
{
base.Config = value;
_config = value;
}
}
public override string DeviceName { get; set; } = "分盘线";
public bool canRunning { get; set; }
public bool isBusy { get; set; }
public bool isAlarm { get; set; }
//public RunStatus runStatus { get; set; }
//public bool UserPause { get; set; }
public bool IgnoreSafecheck { get; set; }
public bool IgnoreGratingSignal { get; set; }
public int NGBox_Count { get => nGBox_Count; set { nGBox_Count = value; Properties.Settings1.Default.NGBox_Count = value; Properties.Settings1.Default.Save(); } }
public int MSDBox_Count { get => mSDBox_Count; set { mSDBox_Count = value; Properties.Settings1.Default.MSDBox_Count = value; Properties.Settings1.Default.Save(); } }
public int PaperBox_Count { get => paperBox_Count; set { mSDBox_Count = value; Properties.Settings1.Default.PaperBox_Count = value; Properties.Settings1.Default.Save(); } }
private int nGBox_Count = 0;
private int mSDBox_Count = 0;
private int paperBox_Count = 0;
public bool Init(out string msg)
{
msg = "";
try
{
string configFile = "config\\FilterConfig.csv";
Config = new Config_Filter(0, "", configFile);
Config = (Config_Filter)CSVConfigReader.LoadConfig<IO_Filter_Type>(Config);
MoveInfo = new MoveInfo(DeviceName);
ResetMoveInfo = MoveInfo;
NGBox_Count = Properties.Settings1.Default.NGBox_Count;
MSDBox_Count = Properties.Settings1.Default.MSDBox_Count;
PaperBox_Count = Properties.Settings1.Default.PaperBox_Count;
}
catch (Exception e)
{
msg = e.Message;
return false;
}
return true;
}
protected override void LoopProcess()
{
mstart = true;
while (mstart)
{
try
{
//HomeReset();
canRunning = DeviceCheck();
if (canRunning)
{
//BtnProcess();
canRunning = SafeCheck();
}
Thread.Sleep(stepDelaytime);
if (!canRunning || !mstart)
continue;
if (runStatus == RunStatus.Running)
{
WorkProcess();
}
else if (runStatus == RunStatus.HomeReset)
{
HomeReset();
}
}
catch (Exception ex)
{
Msg.add(ex.Message, MsgLevel.warning);
LogUtil.error(DeviceName + " " + ex.ToString());
}
finally
{
ProcessMsgEventFire(Msg);
//ProcessMoveinfoEventFire(MoveInfo.List);
Msg.Clear();
}
}
LogUtil.info($"{DeviceName} 主线程已退出.");
}
public bool DeviceCheck()
{
bool ok = true;
if (alarmType == AlarmType.SuddenStop)
{
Msg.add("系统需要重置", MsgLevel.warning);
ok = false;
}
if (NGBox_Count >= Config.NG_BOX_MAXCOUNT) {
Msg.add("NG箱已满", MsgLevel.warning);
ok = false;
}
if (MSDBox_Count >= Config.MSD_BOX_MAXCOUNT)
{
Msg.add("MSD箱已满", MsgLevel.warning);
ok = false;
}
if (PaperBox_Count >= Config.PAPER_BOX_MAXCOUNT)
{
Msg.add("Paper箱已满", MsgLevel.warning);
ok = false;
}
if (alarmType != AlarmType.SuddenStop)
{
TimeSpan span = DateTime.Now - checkAlarmTime;
//在回原点,复位,出入库时,检测报警间隔减小
if ((!runStatus.Equals(RunStatus.Stop) && span.TotalSeconds > 3) || span.TotalSeconds > 1)
{
foreach (ConfigMoveAxis configMoveAxis in Config.moveAxisList)
{
if (AxisManager.GetAlarmStatus(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue()) == 1)
{
Msg.add($"{configMoveAxis.DeviceName}:运动报警", MsgLevel.warning);
ok = false;
}
}
}
}
return ok;
}
public void BeginHomeReset(bool firstRun = false)
{
if (!firstRun)
{
StopMove();
Thread.Sleep(500);
}
OpenAllServo();
alarmType = AlarmType.None;
runStatus = RunStatus.HomeReset;
ResetMoveInfo.NewMove(MoveStep.H01_HomeReset);
ResetMoveInfo.log("开始回原");
ResetMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
private void HomeReset()
{
if (CheckWait(ResetMoveInfo))
return;
switch (ResetMoveInfo.MoveStep)
{
case MoveStep.H01_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
ResetMoveInfo.log("正在回原, 所有阻挡上升");
CylinderMove(ResetMoveInfo, IO_Filter_Type.NG_TaryStop_Down, IO_Filter_Type.NG_TaryStop_Up, IO_VALUE.HIGH);
CylinderMove(ResetMoveInfo, IO_Filter_Type.Paper_TaryStop_Down, IO_Filter_Type.Paper_TaryStop_Up, IO_VALUE.HIGH);
CylinderMove(ResetMoveInfo, IO_Filter_Type.MSD_TaryStop_Down, IO_Filter_Type.MSD_TaryStop_Up, IO_VALUE.HIGH);
break;
case MoveStep.H02_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
ResetMoveInfo.log("正在回原");
IOMove(IO_Filter_Type.Line3_Run, IO_VALUE.HIGH);
break;
case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H04_HomeReset);
ResetMoveInfo.log("正在回原");
CylinderMove(ResetMoveInfo, IO_Filter_Type.NG_GetOut_Bck, IO_Filter_Type.NG_GetOut_Fwd, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_Filter_Type.Paper_GetOut_Bck, IO_Filter_Type.Paper_GetOut_Fwd, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_Filter_Type.MSD_GetOut_Bck, IO_Filter_Type.MSD_GetOut_Fwd, IO_VALUE.LOW);
break;
case MoveStep.H04_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
break;
case MoveStep.H05_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("正在回原, 所有阻挡下升");
CylinderMove(ResetMoveInfo, IO_Filter_Type.NG_TaryStop_Down, IO_Filter_Type.NG_TaryStop_Up, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_Filter_Type.Paper_TaryStop_Down, IO_Filter_Type.Paper_TaryStop_Up, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_Filter_Type.MSD_TaryStop_Down, IO_Filter_Type.MSD_TaryStop_Up, IO_VALUE.LOW);
IOMove(IO_Filter_Type.Line3_Run, IO_VALUE.LOW);
break;
case MoveStep.HEND_HomeReset:
ResetMoveInfo.log("回源完成");
ResetMoveInfo.EndMove();
MoveInfo.NewMove(MoveStep.Filter_01_WaitReel);
runStatus = RunStatus.Running;
break;
}
}
}
}