MainMachine _Common_.cs
12.6 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
using OnlineStore;
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
{
partial class MainMachine
{
List<LabelParam> runParams = new List<LabelParam>();
object paramLock = new object();
void addParam(LabelParam param)
{
lock(paramLock)
{
runParams.Add(param);
LogUtil.info($"参数新建【{JsonHelper.SerializeObject(param)}】");
}
}
void removeParam(long uid)
{
lock (paramLock)
{
var param = runParams.FirstOrDefault(p => p.UID == uid);
if(param != null)
{
runParams.Remove(param);
LogUtil.info($"参数删除【{JsonHelper.SerializeObject(param)}】");
}
}
}
LabelParam GetLabelParam(long uid)
{
lock (paramLock)
{
var param = runParams.FirstOrDefault(p => p.UID == uid);
return param;
}
}
//void setParamPlwHight(long uid,int PlwHight,int plateH)
//{
// lock (paramLock)
// {
// var param = runParams.FirstOrDefault(p => p.UID == uid);
// if (param != null)
// {
// param.RightPulseHeight = PlwHight;
// param.RightPlateHeight = plateH;
// LogUtil.info($"参数修改:PlwHight={PlwHight},plateH={plateH}【{JsonHelper.SerializeObject(param)}】");
// }
// }
//}
public void StopMove(bool ServoOff = false)
{
runStatus = RunStatus.Stop;
MoveInfo.List.ForEach((m) => { m.EndMove(); });
AxisBean.StopMultiAxis(AxisBean.List);
if (ServoOff)
AxisBean.CloseMultiAxis(AxisBean.List);
}
public void OpenAllServo()
{
AxisBean.RunMultiAxis(true, out _, AxisBean.List);
}
int logType = 1000;
string WarnMsg = "";
bool CheckWait(MoveInfo MoveInfo)
{
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
string NotOkMsg = "";
if (MoveInfo.WaitList.Count <= 0)
{
MoveInfo.EndStepWait();
return false;
}
bool isOk = true;
if (MoveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in MoveInfo.WaitList)
{
if (wait.IsEnd)
{
if (!wait.WaitType.Equals(WaitEnum.W002_IOValue))
{
continue;
}
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(WaitEnum.W001_AxisMove))
{
string msg = "";
if (wait.IsHomeMove)
{
LogUtil.info($"回原记录:{wait.ToStr()}");
wait.IsEnd = AxisBean.HomeMoveIsEnd(MoveInfo, wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = AxisBean.ACAxisMoveIsEnd(MoveInfo, wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(AlarmType.AxisMoveError, WarnMsg);
Msg.add(WarnMsg, MsgLevel.warning);
break;
}
}
else if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
{
ConfigIO io = RobotManage.Config.getWaitIO(wait.IoType);
NotOkMsg = crc.GetString("Res0104", "等待") + "【" + io.DisplayStr + "】=【" + wait.IoValue + "】";
wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
int timeOutMs = RobotManage.Config.IOSingle_TimerOut;
if (span.TotalMilliseconds > timeOutMs && NoAlarm())
{
WarnMsg = Name + "[" + MoveInfo.MoveStep + "] " + crc.GetString("Res0104", "等待") + "(" + io.DisplayStr + "=" + wait.IoValue + ") " + crc.GetString("Res0105", "超时");
Msg.add(WarnMsg, MsgLevel.warning);
if (NoAlarm())
{
Alarm(AlarmType.IoSingleTimeOut, WarnMsg);
LogUtil.error(WarnMsg, logType + 14);
//MoveInfo.errlog(WarnMsg);
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
}
}
else if (wait.WaitType.Equals(WaitEnum.W003_Time))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(WaitEnum.W013_Action))
{
wait.IsEnd = wait.Action.Invoke(wait);
LogUtil.info($"{Name} 自定义等待 IsEnd={wait.IsEnd},Type={wait.Action.GetType()}");
}
else if (wait.WaitType.Equals(WaitEnum.W008_BatchAxis))
{
AxisBean axisBean;
if (wait.AxisInfo.ProName == "Right_Batch_Axis")
axisBean = Right_Batch_Axis;
else
axisBean = Left_Batch_Axis;
//等待信号亮或者走到绝对位置才停止
if (IOValue(axisBean.TargetIoType).Equals(axisBean.TargetIoValue))
{
LogUtil.debug(Name + "CheckWaitResult 检测到" + axisBean.TargetIoType + "=" + axisBean.TargetIoValue + ",停止运行");
axisBean.StopAxisCheckMove();
if (AxisManager.GetBusyStatus(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue()).Equals(1))
{
axisBean.SuddenStop();
}
wait.IsEnd = true;
}
else
{
bool isbusy = AxisManager.GetBusyStatus(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue()).Equals(1);
if (!isbusy)
{
int outCount = AxisManager.GetActualtPosition(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
int errorCount = Math.Abs(outCount - wait.TargetPosition);
if (errorCount <= wait.AxisInfo.CanErrorCountMax)
{
axisBean.StopAxisCheckMove();
wait.IsEnd = true;
}
else
{
axisBean.AbsMove(null, wait.TargetPosition, wait.TargetSpeed);
wait.IsEnd = false;
}
}
}
}
if (wait.IsEnd)
{
if (MoveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
}
else
{
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
if (isOk)
{
MoveInfo.EndStepWait();
return false;
}
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
{
LogUtil.error($"MoveInfo.MoveStep:{span.TotalSeconds}>{MoveInfo.TimeOutSeconds}");
WarnMsg = Name + "[" + MoveInfo.MoveStep + "]" + crc.GetString("Res0104", "等待") + NotOkMsg + crc.GetString("Res0105", "超时") + "[" + Math.Round(span.TotalSeconds, 1) + "]" + crc.GetString("Res0106", "秒");
int second = (int)(MoveInfo.TimeOutSeconds / span.TotalSeconds) * 10;
if (second > 120)
{
second = 120;
}
else if (second < 10)
{
second = 10;
}
LogUtil.error(WarnMsg, logType + 100, second);
//MoveInfo.errlog(WarnMsg);
Alarm(AlarmType.IoSingleTimeOut, WarnMsg);
Msg.add(WarnMsg, MsgLevel.alarm);
}
return true;
}
/// <summary>
/// 是否再报警中
/// </summary>
AlarmType alarmType = AlarmType.None;
DateTime LastAlarmTime = DateTime.Now;
public void Alarm(AlarmType _alarmType, string alarmMsg = "")
{
if (_alarmType.Equals(AlarmType.None).Equals(false))
{
LastAlarmTime = DateTime.Now;
}
//SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
if (this.alarmType.Equals(_alarmType))
{
return;
}
LogUtil.error(Name + " 报警,报警类型:" + _alarmType);
if (this.alarmType == AlarmType.SuddenStop && _alarmType == AlarmType.None)
{
clampTool.Close();
clampTool.Open();
}
this.alarmType = _alarmType;
if (_alarmType.Equals(AlarmType.AxisAlarm) || _alarmType.Equals(AlarmType.AxisMoveError))
{
LogUtil.error(Name + "轴报警, 停止运动, 打开报警灯");
StopMove(true);
}
else if (_alarmType == AlarmType.SuddenStop)
{
//isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,停止运动, 打开报警灯 ");
StopMove(true);
//storeStatus = StoreStatus.SuddenStop;
}
else if (_alarmType.Equals(AlarmType.NoAirCheck))
{
//isNoAirCheck = true;
LogUtil.error(Name + " 未检测到气压信号 ,停止运动, 打开报警灯 ");
StopMove(true);
//storeStatus = StoreStatus.SuddenStop;
}
}
internal bool NoAlarm()
{
if (alarmType.Equals(AlarmType.None))
{
return true;
}
return false;
}
public void CylinderMove(MoveInfo moveInfo, string IoLowType, string IoHighType)
{
IOMove(IoLowType, IO_VALUE.LOW);
IOMove(IoHighType, IO_VALUE.HIGH);
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoLowType, IO_VALUE.LOW));
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoHighType, IO_VALUE.HIGH));
}
}
public IO_VALUE IOValue(string ioType)
{
return IOManager.IOValue(ioType);
}
public void IOMove(string IoType, IO_VALUE value, bool isCheck = false, int msTime = 0)
{
if (msTime <= 0)
{
if (isCheck && (IOValue(IoType).Equals(value)))
{
return;
}
IOManager.IOMove(IoType, value);
}
else
{
Task.Run(() =>
{
IOManager.IOMove(IoType, value);
Thread.Sleep(msTime);
IO_VALUE tValue = value.Equals(IO_VALUE.HIGH) ? IO_VALUE.LOW : IO_VALUE.HIGH;
LogUtil.info(Name + "定时回写IO: [" + IoType + "]=[" + value + "],msTime=" + msTime);
IOManager.IOMove(IoType, tValue);
});
}
}
}
}