MoveInfo.cs
12.5 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
400
401
402
403
404
405
406
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class MoveInfo
{
public static List<MoveInfo> List = new List<MoveInfo>();
public int TimeOutSeconds = 60;
public MoveInfo(string name, bool addtolist=true)
{
MoveParam = new ReelParam();
this.moveStep = MoveStep.Wait;
IsInWait = false;
this.Name = name;
if(addtolist)
List.Add(this);
}
public MoveInfo(object p, string v)
{
this.p = p;
this.v = v;
}
public string Name { get; set; }
public DateTime LastSetpTime { get; set; }
public bool OneWaitCanEndStep = false;
public ReelParam MoveParam { get; set; }
public bool IsInWait { get; set; }
MoveStep moveStep;
public int CanWhileCount = 0;
delegate string StateDelegate();
StateDelegate stateDelegate;
public void SetStateDelegate(Func<string> target) {
stateDelegate = new StateDelegate(target);
}
public String GetStateStr() {
if (stateDelegate != null)
return stateDelegate.Invoke();
return "";
}
public MoveStep MoveStep
{
get { return moveStep; }
}
public void NewMove(MoveStep step)
{
this.MoveParam = new ReelParam();
NextMoveStep(step);
}
public void NextMoveStep(MoveStep step)
{
// PreMoveStep = moveStep;
moveStep = step;
LastSetpTime = DateTime.Now;
IsInWait = true;
WaitList = new List<WaitResultInfo>();
OneWaitCanEndStep = false;
CanWhileCount = 5;
}
/// <summary>
/// 当前步骤执行完成
/// </summary>
public void EndStepWait()
{
IsInWait = false;
WaitList = new List<WaitResultInfo>();
}
public void EndMove()
{
this.MoveParam = new ReelParam();
moveStep = MoveStep.Wait;
LastSetpTime = DateTime.Now;
IsInWait = false;
WaitList = new List<WaitResultInfo>();
CanWhileCount = 0;
}
public List<WaitResultInfo> WaitList = new List<WaitResultInfo>();
public bool IsStep(MoveStep step)
{
return moveStep.Equals(step);
}
public bool IsTimeOut(int timeOutSeconds = 60)
{
TimeSpan span = DateTime.Now - LastSetpTime;
if (span.TotalSeconds > timeOutSeconds)
{
return true;
}
return false;
}
public TimeSpan StepSpan()
{
TimeSpan span = DateTime.Now - LastSetpTime;
return span;
}
string lastmsg = "";
public void log(string msg) {
msg = $"[{Name}][{moveStep}][{MoveParam.PosID}-{MoveParam.WareCode}]{msg}";
if (String.Compare(lastmsg,msg, StringComparison.Ordinal)!=0)
{
lastmsg = msg;
LogUtil.info(msg);
}
}
string lasterrmsg = "";
private object p;
private string v;
public void errlog(string msg)
{
msg = $"[{Name}][{moveStep}][{MoveParam.WareCode}]{msg}";
if (String.Compare(lasterrmsg, msg, StringComparison.Ordinal) != 0)
{
lasterrmsg = msg;
LogUtil.error(msg);
}
}
public void Msg(string msg, MsgLevel msgLevel)
{
WaitList.Add(WaitResultInfo.WaitMsg(msg, msgLevel));
}
}
public class WaitResultInfo
{
private WaitResultInfo()
{
IsEnd = false;
CanWhileMoveCount = 0;
}
public static WaitResultInfo WaitIO(string ioType, IO_VALUE ioValue)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W002_IOValue;
wait.IoType = ioType;
wait.IoValue = ioValue;
return wait;
}
public static WaitResultInfo WaitAxis(ConfigMoveAxis axis, int targetPosition, int targetSpeed)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W001_AxisMove;
wait.AxisInfo = axis;
wait.IsHomeMove = false;
wait.TargetPosition = targetPosition;
wait.TargetSpeed = targetSpeed;
return wait;
}
public static WaitResultInfo WaitAxis(ConfigMoveAxis axis, bool isHomeMove)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W001_AxisMove;
wait.AxisInfo = axis;
wait.IsHomeMove = true;
return wait;
}
public static WaitResultInfo WaitTime(int MScends)
{
WaitResultInfo wait = new WaitResultInfo();
wait.CanWhileMoveCount = 0;
wait.WaitType = WaitEnum.W003_Time;
wait.TimeMSeconds = MScends;
wait.IsEnd = false;
return wait;
}
public static WaitResultInfo WaitAxisOrg(ConfigMoveAxis axis, IO_VALUE value)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W006_AxisOrg;
wait.AxisInfo = axis;
wait.IsHomeMove = true;
wait.IoValue = value;
wait.IsEnd = false;
return wait;
}
public static WaitResultInfo WaitBatchAxisMove(ConfigMoveAxis axis, int targetPosition, int targetSpeed)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W008_BatchAxis;
wait.AxisInfo = axis;
wait.IsHomeMove = false;
wait.TargetPosition = targetPosition;
wait.TargetSpeed = targetSpeed;
return wait;
}
internal static WaitResultInfo WaitScanCode()
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W009_ScanCode;
wait.IsHomeMove = false;
return wait;
}
public static WaitResultInfo WaitAction(Func<WaitResultInfo, bool> a,string msg)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W013_Action;
wait.Action = a;
wait.ActionMsg = msg;
return wait;
}
public static WaitResultInfo WaitMsg(string msg, MsgLevel msgLevel)
{
WaitResultInfo wait = new WaitResultInfo();
wait.WaitType = WaitEnum.W014_Msg;
wait.ActionMsg = msg;
wait.IsEnd = true;
wait.Data = msgLevel;
return wait;
}
public string ToStr()
{
if (WaitType.Equals(WaitEnum.W001_AxisMove))
{
if (IsHomeMove)
{
return crc.GetString("Res0074.60c85b4b","轴") + "【" + AxisInfo.DisplayStr + "】" + crc.GetString("AxisMoveControl_groupAxis_panel1_btnAxisReturnHome_Text","原点返回");
}
else
{
return crc.GetString("Res0074.60c85b4b","轴") + "【" + AxisInfo.DisplayStr + "】" + crc.GetString("Res0075.0c33436f","绝对运动,目标位置") + "【" + TargetPosition + "】";
}
}
else if (WaitType.Equals(WaitEnum.W002_IOValue))
{
return crc.GetString("Res0076.87979227","等待") + "【" + IoType + "】=【" + IoValue + "】";
}
else if (WaitType.Equals(WaitEnum.W003_Time))
{
return crc.GetString("Res0077.d7647f48","时间等待") + ":【" + TimeMSeconds + "】" + crc.GetString("Res0078.21157cbf","毫秒");
}
else if (WaitType.Equals(WaitEnum.W006_AxisOrg))
{
return crc.GetString("Res0074.60c85b4b","轴") + "【" + AxisInfo.DisplayStr + "】" + crc.GetString("Res0079.3802ba42","ORG信号") + ":【" + IoValue + "】";
}
else if (WaitType.Equals(WaitEnum.W007_ReelHeight))
{
return crc.GetString("Res0080.f4a8d691","料盘高度") + "【" + TargetPosition + "】";
}
else if (WaitType.Equals(WaitEnum.W008_BatchAxis))
{
return crc.GetString("Res0081.84e7c741","批量轴上升到上料点");
}
else if (WaitType.Equals(WaitEnum.W009_ScanCode))
{
return crc.GetString("Res0082.ed4de1c6","扫码完成");
}
else if (WaitType.Equals(WaitEnum.W013_Action))
{
return ActionMsg;
}
else
{
return "WaitType=【" + WaitType + "】";
}
}
/// <summary>
/// 当未结束时可以重复运动的次数
/// </summary>
public int CanWhileMoveCount { get; set; }
/// <summary>
/// 等待结果,1=轴运动,2=IO运动,3=时间,4=电钢,5=硕科电机,6=等待轴原点信号,8=等待压紧轴压紧到位
/// </summary>
public int WaitType { get; set; }
/// <summary>
/// 轴运动时表示轴信息
/// </summary>
public ConfigMoveAxis AxisInfo { get; set; }
/// <summary>
/// IO类型
/// </summary>
public String IoType { get; set; }
/// <summary>
/// IO值
/// </summary>
public IO_VALUE IoValue { get; set; }
/// <summary>
/// 等待的毫秒
/// </summary>
public int TimeMSeconds { get; set; }
/// <summary>
/// 是否是原点返回
/// </summary>
public bool IsHomeMove = false;
/// <summary>
/// 轴目标位置
/// </summary>
public int TargetPosition { get; set; }
/// <summary>
/// 轴目标速度
/// </summary>
public int TargetSpeed { get; set; }
/// <summary>
/// 是否已经结束
/// </summary>
public bool IsEnd { get; set; }
/// <summary>
/// 等待事件代理
/// </summary>
public Func<WaitResultInfo, bool> Action { get; set; }
public string ActionMsg { get; set; }
public dynamic Data { get; set; }
}
internal class WaitEnum
{
/// <summary>
/// 伺服运动
/// </summary>
internal static int W001_AxisMove = 1;
/// <summary>
/// 信号到达
/// </summary>
internal static int W002_IOValue = 2;
/// <summary>
/// 时间等待
/// </summary>
internal static int W003_Time = 3;
/// <summary>
/// 硕科电机
/// </summary>
internal static int W005_ShuoKe = 5;
/// <summary>
/// 轴原点信号
/// </summary>
internal static int W006_AxisOrg = 6;
/// <summary>
/// 料盘高度
/// </summary>
internal static int W007_ReelHeight = 7;
/// <summary>
/// 批量轴上升到上料点
/// </summary>
internal static int W008_BatchAxis = 8;
/// <summary>
/// 扫码完成
/// </summary>
internal static int W009_ScanCode = 9;
/// <summary>
/// 通用代理等待方法
/// </summary>
internal static int W013_Action = 13;
/// <summary>
/// 等待时反馈消息
/// </summary>
internal static int W014_Msg = 14;
}
public enum StoreMoveType
{
/// <summary>
/// 没有任何操作
/// </summary>
None = 0,
/// <summary>
/// 入库
/// </summary>
InStore = 1,
/// <summary>
/// 出库
/// </summary>
OutStore = 2,
/// <summary>
/// 原点返回
/// </summary>
ReturnHome = 3,
/// <summary>
/// 重置
/// </summary>
StoreReset = 4,
///// <summary>
///// 移栽装置的停止,需要先远点返回,然后停止
///// </summary>
//StopMove=5,
///// <summary>
///// 移栽检测托盘
///// </summary>
//CheckFixture=6,
}
}