AutomaticBaiting_Partial.cs
13.2 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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class AutomaticBaiting
{
private static int StartMovePosition = 0;
private static int EndMovePosition = 0;
public static int AutoAxisIsMove = 0;
private static void ACAxisSpeedMove(ConfigMoveAxis moveAxis, int targetSpeed)
{
AutoAxisIsMove = 1;
StartMovePosition = ACServerManager.GetActualtPosition(moveAxis.DeviceName,moveAxis.GetAxisValue());
EndMovePosition = StartMovePosition;
StoreMove.WaitList.Add(WaitResultInfo.WaitAutoAxisStop(moveAxis));
ACServerManager.SpeedMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetSpeed);
}
private static void ACAxisRelMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
private static void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.debug(Name + moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
private static 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)
{
////判断是否需要重新运动
//if (StoreMove.CanWhileCount > 0)
//{
// LogUtil.error(Name+ moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + StoreMove.CanWhileCount + "]次");
// ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
// StoreMove.CanWhileCount--;
//}
//else
//{
msg = Name + " storeMoveStep=" + StoreMove.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error( msg);
return false;
//}
}
return true;
}
return false;
}
private static void CheckWait()
{
List<WaitResultInfo> list = StoreMove.WaitList;
if (list.Count <= 0)
{
StoreMove.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - StoreMove.LastSetpTime;
string NotOkMsg = "";
bool isOk = !StoreMove.OneWaitCanEndStep;
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType == 1)
{
wait.IsEnd = AxisMoveISEnd(wait);
}
else if (wait.WaitType == 2)
{
wait.IsEnd = KND.IOValue(wait.IoType).Equals(wait.IoValue);
int timeOutMs = StoreManager.Config.IOSingle_TimerOut;
if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
{
ConfigIO io = StoreManager.Config.getWaitIO(wait.IoType);
WarnMsg = Name + " 等待信号" + io.DisplayStr + "=" + wait.IoValue + "超时!";
StoreManager.Store.Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, StoreMove.MoveType);
LogUtil.error(WarnMsg);
isOk = false;
break;
}
}
else if (wait.WaitType == 3)
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType == 5)
{
}
else if (wait.WaitType == 6)
{
IO_VALUE value = (IO_VALUE)ACServerManager.GetHomeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
wait.IsEnd = wait.IoValue.Equals(value);
}
else if (wait.WaitType == 7)
{
}
else if (wait.WaitType == 8)
{
IO_VALUE value = (IO_VALUE)ACServerManager.GetLimitNegativeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
wait.IsEnd = wait.IoValue.Equals(value);
}
else if (wait.WaitType == 9)
{
IO_VALUE value = (IO_VALUE)ACServerManager.GetLimitPositiveSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
wait.IsEnd = wait.IoValue.Equals(value);
}
else if (wait.WaitType == 10)
{
wait.IsEnd = AutoAxisIsEnd(wait);
}
else if (wait.WaitType == 11)
{
wait.IsEnd = !String.IsNullOrEmpty(LastCode);
}
if (wait.IsEnd)
{
if (StoreMove.OneWaitCanEndStep)
{
isOk = true;
break;
}
}
else
{
if (!StoreMove.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
if (isOk)
{
StoreMove.EndStepWait();
}
else if (span.TotalSeconds > StoreMove.TimeOutSeconds)
{
if (NotOkMsg.Equals(""))
{
WarnMsg = Name + "等待超时【" + StoreMove.MoveType + "】【" + StoreMove.MoveStep + "】已等待【" + Math.Round(span.TotalSeconds) + "】秒";
foreach (WaitResultInfo wait in list)
{
WarnMsg = WarnMsg + "\r\n" + wait.ToStr();
}
LogUtil.error(WarnMsg);
}
else
{
WarnMsg = Name + "【" + StoreMove.MoveType + "】【" + StoreMove.MoveStep + "】等待超时 [" + NotOkMsg
+ "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg);
}
StoreManager.Store.Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnMsg, StoreMove.MoveType);
}
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
private static bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
bool isOk = ACServerManager.GetBusyStatus(moveAxis.DeviceName, moveAxis.GetAxisValue()).Equals(0);
if (isOk)
{
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount - targetPosition);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (StoreMove.CanWhileCount > 0)
{
LogUtil.error(Name + moveAxis.DisplayStr + "目标[" + targetPosition + "]当前[" + outCount +
"],误差过大,重新运动,剩余[" + StoreMove.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
StoreMove.CanWhileCount--;
}
else
{
msg = Name + moveAxis.DisplayStr + "目标[" + targetPosition + "]当前[" + outCount + "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
private static bool AxisMoveISEnd(WaitResultInfo wait)
{
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 (!wait.IsEnd)
{
IO_VALUE value = (IO_VALUE)ACServerManager.GetHomeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
if (value.Equals(IO_VALUE.HIGH))
{
ACServerManager.SuddenStop(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
LogUtil.error(Name + wait.ToStr() + "原点返回过程中到达 负限位,直接停止运动");
StoreManager.Store.Alarm(StoreAlarmType.AxisMoveError, StoreManager.Store.GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, StoreMove.MoveType);
}
}
if (!msg.Equals(""))
{
WarnMsg = msg;
StoreManager.Store.Alarm(StoreAlarmType.AxisMoveError, StoreManager.Store.GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, StoreMove.MoveType);
}
return wait.IsEnd;
}
private static bool AutoAxisIsEnd(WaitResultInfo wait)
{
bool result = false;
if (KND.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.HIGH))
{
result = true;
}
else
{
IO_VALUE LimitN = (IO_VALUE)ACServerManager.GetLimitNegativeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
if (LimitN.Equals(IO_VALUE.HIGH))
{
result = true;
}
}
if (result)
{
AutoAxisIsMove = 0;
ACServerManager.SuddenStop(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
}
return result;
}
public static int GetSize()
{
if (KND.IOValue(IO_Type.WidthCheck1).Equals(IO_VALUE.HIGH))
{
if (KND.IOValue(IO_Type.WidthCheck2).Equals(IO_VALUE.HIGH))
{
return 13;
}
else
{
return 7;
}
}
return 0;
}
#region Halcon扫码枪代码
public bool IsTestCamera = false;
private static string spiltStr = "##";
public static void GetCameraCode()
{
Task.Factory.StartNew(delegate ()
{
KND.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string message = "";
List<string> codeList = CodeManager.CameraScan();
if (codeList.Count <= 0)
{
codeList = CodeManager.CameraScan();
}
foreach (string str in codeList)
{
message = message + "=1+0x0-" + LastSize + "x" + LastHeight + " =" + str + spiltStr;
}
LastCode = message;
if (LastCode.Equals(""))
{
LogUtil.error("未扫到二维码,请拿走料盘");
WarnMsg = "未扫到二维码,请拿走料盘";
}
KND.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
StoreManager.Store.onCodeReceived(message);
});
}
#endregion
private static void CylinderMove(string highType, string lowType, bool isWait)
{
if (isWait)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(lowType, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(highType, IO_VALUE.HIGH));
}
KND.IOMove(lowType, IO_VALUE.LOW);
KND.IOMove(highType, IO_VALUE.HIGH);
}
}
}