BoxBean.cs
15.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
using Asa;
using DeviceLib;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class BoxBean : EquipBase
{
private bool IsIntSlvBlock = false;
public AutoInoutInfo AutoInout = new AutoInoutInfo();
public string CID = "";
public BOX_Config Config;
public string lastPosId = "";
public StoreStatus lastPosIdStatus = StoreStatus.StoreOnline;
public List<ConfigMoveAxis> moveAxisList = new List<ConfigMoveAxis>();
public List<string> PositionNumList = new List<string>();
public HumitureBean humBean = null;
public AxisBean UpdownAxis = null;
public AxisBean MiddleAxis = null;
public AxisBean ComAxis = null;
public AxisBean InoutAxis = null;
/// <summary>
/// 出料口最后一盘料信息,0=暂无,1=单盘出库料亮绿灯,2=入库NG料亮红灯
/// </summary>
public int OutDoorReelType = 0;
public BoxBean(BOX_Config config)
{
Init();
baseConfig = config;
CID = config.CID;
IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
serverConTimer.Elapsed += server_connect_timer_Tick;
logType = 1000 * config.Id;
//添加调试
IsDebug = config.IsInDebug.Equals(1);
Name = (" BOX_" + config.Id + " ").ToUpper();
MoveInfo = new StoreMoveInfo(ID, Name);
this.ID = config.Id; ;
this.Config = config;
//温湿度
humBean = new HumitureBean(config.Humiture_Port, Name);
MoveAxisConfig();
List<ACBoxPosition> positionList = CSVPositionReader<ACBoxPosition>.getPositionList();
PositionNumList = new List<string>();
foreach (ACBoxPosition position in positionList)
{
if (position.StoreId.Equals(ID) && ACBoxPosition.CheckPosition(position, Config))
{
PositionNumList.Add(position.PositionNum);
}
}
InoutAxis = new AxisBean(config.InOut_Axis, Name);
MiddleAxis = new AxisBean(config.Middle_Axis, Name);
UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
ComAxis = new AxisBean(config.Comp_Axis, Name);
mainTimer.Enabled = false;
}
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//判断急停
if (runStatus >= StoreRunStatus.HomeMoving)
{
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
if (isInSuddenDown.Equals(false))
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,报警急停");
WarnMsg = Name + "收到急停信号,报警急停";
//报警时会关闭所有轴
Alarm(AlarmType.SuddenStop, "1", WarnMsg, MoveType.None);
}
}
}
}
public void MoveAxisConfig()
{
Config.UpDown_Axis.BreakOnDO = IO_Type.UpdownAxis_Break;
moveAxisList = new List<ConfigMoveAxis>();
moveAxisList.Add(Config.Middle_Axis);
moveAxisList.Add(Config.UpDown_Axis);
moveAxisList.Add(Config.InOut_Axis);
moveAxisList.Add(Config.Comp_Axis);
}
public override bool StartRun(bool isDebug = false)
{
if (!StoreManager.Store.canStart)
{
WarnMsg = "启动失败:设备未初始化完成";
LogUtil.error(Name + "启动失败:设备未初始化完成");
return false;
}
LogInfo("开始启动,启动时间:" + StartTime.ToString());
AutoInout.StopAuto();
mainTimer.Enabled = false;
alarmType = AlarmType.None;
//急停按钮和气压检测需要一起判断
IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check);
if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)))
{
//lastAirValue = airCheck;
lastAirCloseTime = DateTime.Now;
if (!OpenAllAxis(true))
{
return false;
}
//TODO 启动时先所有轴远点返回,测试暂时关闭
runStatus = StoreRunStatus.HomeMoving;
storeStatus = StoreStatus.ResetMove;
//启动温湿度服务器
HumitureController.Init(Config.Humiture_Port);
ReturnHome();
StartTime = DateTime.Now;
mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
serverConTimer.Enabled = true;
return true;
}
else
{
if (suddenBtn.Equals(IO_VALUE.LOW))
{
WarnMsg = "启动失败:急停没开";
LogUtil.error(" (" + Name + ")启动失败:急停没开!");
}
else
{
WarnMsg = "启动失败:没有气压信号";
LogUtil.error(" (" + Name + ")启动失败:没有气压信号!");
}
return false;
}
}
#region 原点返回和复位处理
private void ReturnHome()
{
lastPosId = "";
lastPosIdStatus = StoreStatus.ResetMove;
AutoInout.ClearCount();
runStatus = StoreRunStatus.HomeMoving;
MoveInfo.NewMove(MoveType.ReturnHome);
InoutStartReset();
}
public override void Reset(bool isNeedClearAuto = true)
{
AutoInout.ClearCount();
//复位之前先停止运行
if (isNeedClearAuto)
{
AutoInout.StopAuto();
}
runStatus = StoreRunStatus.Reset;
storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(MoveType.Reset);
if (!OpenAllAxis(true))
{
LogInfo("复位时打开轴失败,需要再次复位,直接报警停止复位");
return;
}
InoutStartReset();
isInPro = false;
}
private void InoutStartReset()
{
//清理报警
WarnMsg = "";
isInSuddenDown = false;
isNoAirCheck = false;
alarmType = AlarmType.None;
//开始复位动作
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H01_InOutBack);
LogInfo(MoveInfo.MoveType + ": 进出轴回原点 ");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
InoutAxis.HomeMove(MoveInfo);
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
switch (MoveInfo.MoveStep)
{
case StoreMoveStep.BOX_H01_InOutBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H02_InoutToP1);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
LogInfo(MoveInfo.MoveType + ": 进出轴到待机点P1,关闭仓门");
InoutAxis.AbsMove(MoveInfo, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down);
break;
case StoreMoveStep.BOX_H02_InoutToP1:
//如果此时轴三还在报警,需要提示错误并等待
if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{
LogUtil.error(Name + MoveInfo.MoveType + "复位失败: " + Config.InOut_Axis.Explain + "报警");
WarnMsg = Name + "复位失败: " + Config.InOut_Axis.Explain + "报警";
Alarm(AlarmType.AxisAlarm );
return;
}
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_OtherAxisHome);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
LogInfo(MoveInfo.MoveType + ": 压紧轴,旋转轴,上下轴开始 原点返回,关闭NG门");
CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down);
ComAxis.HomeMove(MoveInfo);
MiddleAxis.HomeMove(MoveInfo);
UpdownAxis.HomeMove(MoveInfo);
break;
case StoreMoveStep.BOX_H03_OtherAxisHome:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H04_OtherAxisBack);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
LogInfo(MoveInfo.MoveType + ": 旋转轴运动到P1,上下轴走到P1,压紧轴到P1, ");
MiddleAxis.AbsMove(MoveInfo, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxis_P1, Config.UpDownAxis_P1_Speed);
ComAxis.AbsMove(MoveInfo, Config.CompAxis_P1, Config.CompAxis_P1_Speed);
break;
case StoreMoveStep.BOX_H04_OtherAxisBack:
LogInfo(MoveInfo.MoveType + ": 完成");
MoveEndP();
break;
default: break;
}
}
#endregion
public override void StopRun()
{
lastPosId = "";
lastPosIdStatus = StoreStatus.StoreOnline;
WarnMsg = "";
AutoInout.StopAuto();
IoCheckTimer.Enabled = false;
serverConTimer.Enabled = false;
StopMove();
runStatus = StoreRunStatus.Wait;
mainTimer.Enabled = false;
TimeSpan span = DateTime.Now - StartTime;
LogInfo(",停止运行,总运行时间:" + span.ToString());
}
public override void Alarm(AlarmType alarmType, string alarmDetial = "", string alarmMsg = "", MoveType storeMoveType = MoveType.None)
{
base.Alarm(alarmType, alarmDetial, alarmMsg, storeMoveType);
AutoInout.StopAuto();
}
internal override void TimerProcess()
{
try
{
DateTime time = DateTime.Now;
if (MoveInfo.MoveType != MoveType.None)
{
BusyMoveProcess();
ShowTimeLog("BusyMoveProcess");
}
else if (runStatus.Equals(StoreRunStatus.Runing))
{
ShowTimeLog("判断是否需要出入库");
AutoResetProcess();
ShowTimeLog("AutoResetProcess");
IOTimeOutProcess();
ShowTimeLog("IOTimeOutProcess");
} //检查运动轴报警
if (runStatus > StoreRunStatus.Wait && (!isInSuddenDown) && (!isNoAirCheck))
{
ShowTimeLog("开始检测轴报警");
CheckAxisAlarm(new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });
ShowTimeLog("轴报警检测完成");
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错" + ex.ToString());
}
}
private void AutoResetProcess()
{
try
{
bool noInStore = MoveInfo.MoveType.Equals(MoveType.None) && alarmType.Equals(AlarmType.None);
if (AutoInout.CurrInOutACount >= StoreManager.Config.Box_ResetACount && noInStore)
{
if (runStatus < StoreRunStatus.Runing || MoveInfo.MoveType == MoveType.InStore || MoveInfo.MoveType == MoveType.OutStore)
{
// LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,当时当前正在忙碌中暂不复位");
}
else
{
LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,需要复位一下");
Reset();
}
return;
}
else if (waitInStoreParam != null && noInStore && IsDebug.Equals(false))
{
if (!StartInStoreMove(waitInStoreParam))
{
LogInfo("执行排队的入库【" + waitInStoreParam.ToStr() + "】失败");
}
else
{
LogInfo("执行排队的入库【" + waitInStoreParam.ToStr() + "】成功,清理缓存");
waitInStoreParam = null;
}
}
else if (waitOutStoreList.Count > 0 && noInStore && IsDebug.Equals(false))
{
InOutParam param = null;
bool result = waitOutStoreList.TryDequeue(out param);
if (result && param != null)
{
LogInfo("执行排队的出库【" + param.ToStr() + "】");
StartExecuctOut(param);
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "处理出入库排队列表出错:" + ex.ToString());
}
}
public override void StopMove()
{
MoveInfo.EndMove();
IOMove(IO_Type.UpdownAxis_Break, IO_VALUE.LOW);
//运动版停止
MiddleAxis.SuddenStop(true);
UpdownAxis.SuddenStop(true);
InoutAxis.SuddenStop(true);
ComAxis.SuddenStop(true);
CloseAllAxis();
LogInfo("StopMove");
isInPro = false;
}
public bool OpenAllAxis(bool isCheck)
{
return RunMultiAxis(true, IO_Type.Axis_Run, IO_Type.UpdownAxis_Break, new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });
}
public void CloseAllAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
CloseMultiAxis(IO_Type.Axis_Run, IO_Type.UpdownAxis_Break, new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });
}
}
}