XRayMachine.cs
9.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
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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
using crc = OnlineStore.CodeResourceControl;
public partial class XRayMachine : MachineBase, IRobot
{
private Config_XRay _config;
public new Config_XRay Config
{
get => _config;
set
{
base.Config = value;
_config = value;
}
}
public override string DeviceName { get; } = "点料";
public bool canRunning { get; set; }
public bool isBusy { get; set; }
public bool isAlarm { get; set; }
//public RunStatus runStatus { get; set; }
//public override bool UserPause { get; set; }
public bool IgnoreSafecheck { get; set; }
public bool IgnoreGratingSignal { get; set; }
AxisBean Line_Entry_Axis;
AxisBean Line_In_Axis;
public bool Init(out string msg)
{
ConfigHelper.Config.Get("xray_light_delay", 1000);
msg = "";
try
{
string configFile = "config\\XrayConfig.csv";
Config = new Config_XRay(0, "", configFile);
Config = (Config_XRay)CSVConfigReader.LoadConfig<IO_XRay_Type>(Config);
LogUtil.info(DeviceName + " config load finish");
#region 初始化伺服轴
Line_Entry_Axis = new AxisBean(Config.Line_Entry_Axis, DeviceName);
Line_In_Axis = new AxisBean(Config.Line_In_Axis, DeviceName);
#endregion
MoveInfo = new MoveInfo(DeviceName);
ResetMoveInfo = MoveInfo;
LedProcessInit();
Asa.XrayImage.setProcessLevel(4.0);
IOMonitor.RegisterIO(IO_XRay_Type.Exit_Open, Config, IO_VALUE.LOW, delegate () { XRayDoorOpen(); });
IOMonitor.RegisterIO(IO_XRay_Type.Entry_Open, Config, IO_VALUE.LOW, delegate () { XRayDoorOpen(); });
AlarmBuzzer.SetOnOffAction(() => { IOMove(IO_XRay_Type.Alarm_Buzzer, IO_VALUE.HIGH); }, () => { IOMove(IO_XRay_Type.Alarm_Buzzer, IO_VALUE.LOW); });
LogUtil.info(DeviceName + " init end");
}
catch (Exception e){
msg = e.Message;
return false;
}
return true;
}
public override void Run()
{
base.Run();
IOMove(IO_XRay_Type.Camera_Led, IO_VALUE.HIGH);
}
public override void Stop()
{
IOMove(IO_XRay_Type.Camera_Led, IO_VALUE.LOW);
base.Stop();
}
void XRayDoorOpen() {
if (RobotManage.XRay.IsRayOpen)
{
LogUtil.info(DeviceName + " X光机防护门打开");
//RobotManage.XRay.Stop();
//IOMove(IO_XRay_Type.Xray_Lock, IO_VALUE.LOW);
}
else {
LogUtil.info(DeviceName + " X光没有打开");
}
}
protected override void LoopProcess()
{
mstart = true;
while (mstart)
{
try
{
canRunning = DeviceCheck();
if (canRunning)
{
canRunning = SafeCheck();
}
Thread.Sleep(stepDelaytime);
if (!canRunning || !mstart)
continue;
if (runStatus == RunStatus.Running)
{
FeedingProcess();
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} 主线程已退出.");
}
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
DateTime lastAirCloseTime = DateTime.MinValue;
public bool DeviceCheck() {
//return true;
bool ok = true;
if (IOValue(IO_XRay_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
Alarm(AlarmType.SuddenStop);
Msg.add(crc.GetString("emergency_stop", "急停中"), MsgLevel.warning);
Thread.Sleep(1000);
ok = false;
}
else if (alarmType == AlarmType.SuddenStop)
{
Msg.add(crc.GetString("system_need_reset", "系统需要重置"), MsgLevel.info);
Thread.Sleep(1000);
ok = false;
}
if (IOValue(IO_XRay_Type.Airpressure_Check).Equals(IO_VALUE.LOW))
{
if (lastAirCloseTime == DateTime.MinValue)
lastAirCloseTime = DateTime.Now;
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > Config.AirCheckSeconds)
{
ok = false;
Msg.add(crc.GetString("air_pressure_fail", "气压不足"), MsgLevel.warning);
}
}
else
{
lastAirCloseTime = DateTime.MinValue;
}
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(crc.GetString("axis_run_alert", "{0}:运动报警", configMoveAxis.Explain), 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_XRay_Type.Location_Cylinder_Down, IO_XRay_Type.Location_Cylinder_Up,IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open);
break;
case MoveStep.H02_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
Line_Entry_Axis.RelMove(ResetMoveInfo, Config.Line_Entry_Relative*2, Config.Line_Entry_Relative_speed);
Line_In_Axis.RelMove(ResetMoveInfo, Config.Line_In_Relative*2, Config.Line_In_Relative_speed);
ResetMoveInfo.log("正在回原");
break;
case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("正在回原, 门关闭");
CylinderMove(ResetMoveInfo, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open,IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Location_Cylinder_Down, IO_XRay_Type.Location_Cylinder_Up, IO_VALUE.HIGH);
break;
case MoveStep.HEND_HomeReset:
ResetMoveInfo.log("回源完成");
ResetMoveInfo.EndMove();
//MoveInfo.NewMove(MoveStep.Feeding_05_Goto_Xray);
runStatus = RunStatus.Running;
break;
}
}
}
}