EquipBase.cs
14.3 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
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 OnlineStore.DeviceLibrary
{
public abstract class EquipBase : KTK_Store
{
private bool IsIntSlvBlock = false;
public bool IsDebug = false;
public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
public bool UseAxis = false;
#region 上下气缸伺服运动
protected string portName;
protected short slvAddr;
public bool RunAxis(bool isCheck,ConfigMoveAxis axis)
{
if (!UseAxis)
{
return true;
}
IOMove(IO_Type.BatchAxis_ServoOn, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, axis.TargetSpeed, axis.AddSpeed, axis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAxis(axis))
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.BatchAxis_BreakOn, IO_VALUE.HIGH);
return true;
}
protected void IOMove(object batchAxis_ServoOn, IO_VALUE hIGH)
{
throw new NotImplementedException();
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
protected bool OpenAxis(ConfigMoveAxis axis)
{
//判断轴是否正常
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info(Name + "成功打开轴:" + axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info(Name + "第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(portName, slvAddr);
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(portName, slvAddr);
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info(Name + "清理报警后重新打卡轴成功:" + axis.Explain);
}
else
{
ACServerManager.ServoOff(portName, slvAddr);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
LogUtil.info(Name + WarnMsg);
Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
return true;
}
public void CloseAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.BatchAxis_BreakOn, IO_VALUE.LOW);
ACServerManager.ServoOff(portName, slvAddr);
//关闭串口,等下次重新打开
ACServerManager.ColsePort(portName);
Thread.Sleep(100);
IOMove(IO_Type.BatchAxis_ServoOn, IO_VALUE.LOW);
}
protected void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.info(moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
protected void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
protected bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error(moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
protected bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error(moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
#endregion
#region CheckWait处理
/// <summary>
/// 上一个盘号
/// </summary>
public int preTrayNum = 0;
/// <summary>
/// 当前正在通过的托盘号
/// </summary>
protected int currMoveTrayNum = 0;
protected DateTime preRWTime = DateTime.Now;
protected void CheckWait(LineMoveInfo moveInfo)
{
List<WaitResultInfo> list = moveInfo.WaitList;
if (list.Count <= 0)
{
moveInfo.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
string NotOkMsg = "";
bool isOk = true;
if (moveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(1))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(LineAlarmType.AxisMoveError, 5.ToString(), WarnMsg, moveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(2))
{
NotOkMsg = " (" + baseConfig.GetDisplayName(wait.IoType) + "=" + wait.IoValue + ") ";
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
//屏蔽料盘检测信号
if (wait.IoType.Equals(IO_Type.TrayCheck) && wait.IoValue.Equals(IO_VALUE.HIGH) && LineManager.Config.IsUse_Tray_Check.Equals(0))
{
LogUtil.debug(moveInfo.Name + "未检测到:IsUse_Tray_Check= " + wait.IoValue + ",直接跳过检测继续下一步");
}
//夹紧按钮若果超过一秒钟还未收到,默认成功
else if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 4000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过4秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut)
{
ConfigIO io = baseConfig.getWaitIO(wait.IoType);
WarnMsg = Name + "等待" + NotOkMsg + " 超时";
Alarm(LineAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(MoveInfo.Name + WarnMsg, 13);
}
else if (rwSpan.TotalSeconds > 3 && span.TotalSeconds > 3)
{
preRWTime = DateTime.Now;
string msg = moveInfo.Name + " " + NotOkMsg + "已等待 " + Math.Abs(span.TotalSeconds) + "秒,重写DO:";
bool isLog = false;
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2) && baseConfig.DOList.ContainsKey(ww.IoType))
{
isLog = true;
IOMove(ww.IoType, ww.IoValue);
msg += ww.ToStr() + ",";
}
}
if (isLog)
{
LogUtil.error(msg);
}
}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(3))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(8))
{
string posId = moveInfo.MoveParam.PosId;
int id = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.RightInPosId(id, posId);
}
else if (wait.WaitType.Equals(9))
{
int storeId = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.BoxCanReviceTray(storeId);
}
else if (wait.WaitType.Equals(10))
{
wait.IsEnd = LineManager.Line.SideWay34HasTray().Equals(false);
}
if (wait.IsEnd && moveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
else if (!moveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
if (isOk)
{
moveInfo.EndStepWait();
}
else if (span.TotalSeconds > moveInfo.TimeOutSeconds)
{
WarnMsg = moveInfo.Name + "[" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "]等待[" + NotOkMsg
+ "]超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 18);
Alarm(LineAlarmType.IoSingleTimeOut, "", WarnMsg, moveInfo.MoveType);
}
}
#endregion
public override void Alarm(LineAlarmType alarmType, string alarmDetial, string alarmMsg, LineMoveType storeMoveType)
{
if (this.alarmType.Equals(alarmType))
{
return;
}
this.alarmType = alarmType;
}
}
}