KTK_Store.cs
28.8 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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 康泰克单台自动料仓
/// </summary>
public abstract class KTK_Store : KTK_DeviceBase
{
public KTK_Store()
{
}
/// <summary>
/// 开始运行的时间
/// </summary>
public DateTime StartTime { get; set; }
public DateTime statusTime = DateTime.Now;
/// <summary>
/// 伺服运行时间列表,key=轴,key=开始时间,value=结束时间
/// </summary>
public Dictionary<int, Dictionary<DateTime, DateTime>> AxisRunTimeMap = new Dictionary<int, Dictionary<DateTime, DateTime>>();
public Dictionary<int, DateTime> AxisLastStartTime = new Dictionary<int, DateTime>();
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
public DateTime lastAirCloseTime = DateTime.Now;
/// <summary>
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
/// <summary>
/// 是否没有检测到气压
/// </summary>
public bool isNoAirCheck = false;
/// <summary>
/// 是否再报警中
/// </summary>
public StoreAlarmType alarmType = StoreAlarmType.None;
public AlarmInfo alarmInfo = new AlarmInfo();
/// <summary>
/// 记录上一次的部分IO状态,主要是急停,气压检测信号,复位信号,用来判断是否io发生改变
/// </summary>
public Dictionary<string, IO_VALUE> DILastValueMap = new Dictionary<string, IO_VALUE>();
public object lastDiListLock = "";
public void addLastDI(string type, IO_VALUE value)
{
try
{
lock (lastDiListLock)
{
if (DILastValueMap.ContainsKey(type))
{
DILastValueMap.Remove(type);
}
DILastValueMap.Add(type, value);
}
}
catch (Exception ex)
{
LOGGER.Error(ex.ToString());
}
}
/// <summary>
/// 获取料仓运行的时间
/// </summary>
/// <returns></returns>
public TimeSpan GetStoreRunTime()
{
if (StartTime != null)
{
return DateTime.Now - StartTime;
}
else
{
return new TimeSpan(0);
}
}
/// <summary>
/// 获取轴已运行时间
/// </summary>
/// <returns></returns>
public TimeSpan GetAxisRunTime(int axisNo)
{
TimeSpan span = new TimeSpan(0);
try
{
if (AxisRunTimeMap.ContainsKey(axisNo))
{
Dictionary<DateTime, DateTime> moveMap = AxisRunTimeMap[axisNo];
if (moveMap != null && moveMap.Count > 0)
{
foreach (DateTime key in moveMap.Keys)
{
span += moveMap[key] - key;
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.ToString());
}
return span;
}
protected void AddAxisMoveTime(ConfigMoveAxis axis)
{
int axisNo = axis.GetAxisValue();
if (AxisLastStartTime.ContainsKey(axisNo))
{
AxisLastStartTime.Remove(axisNo);
}
AxisLastStartTime.Add(axisNo, DateTime.Now);
}
#region 轴运动
/// <summary>
/// 轴运动结束的时间记录
/// </summary>
protected void MoveEndPro(short AxisNo)
{
if (AxisLastStartTime.ContainsKey(AxisNo))
{
DateTime startTIme = AxisLastStartTime[AxisNo];
Dictionary<DateTime, DateTime> moveTimeMap = null;
if (AxisRunTimeMap.ContainsKey(AxisNo))
{
moveTimeMap = AxisRunTimeMap[AxisNo];
}
else
{
moveTimeMap = new Dictionary<DateTime, DateTime>();
AxisRunTimeMap.Add(AxisNo, moveTimeMap);
}
if (!moveTimeMap.ContainsKey(startTIme))
{
moveTimeMap.Add(startTIme, DateTime.Now);
// LogUtil.info(LOGGER, StoreName + ",伺服运动结束,开始时间" + startTIme.ToString() + ",结束时间" + DateTime.Now.ToString());
AxisLastStartTime.Remove(AxisNo);
}
AxisRunTimeMap.Remove(AxisNo);
AxisRunTimeMap.Add(AxisNo, moveTimeMap);
}
}
/// <summary>
/// 轴运动 .会自动加入等待列表中
/// </summary>
/// <param name="moveAxis">需要运动的轴</param>
/// <param name="targetPosition">目标位置</param>
/// <param name="speed">速度</param>
protected void AxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, int startSpeed)
{
moveAxis.TargetPosition = targetPosition;
AddAxisMoveTime(moveAxis);
KTKSMCManager.ABSMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), targetPosition, targetSpeed, moveAxis.AccelTime, moveAxis.DecelTime,moveAxis.ResolveSpeed);
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition,targetSpeed));
}
/// <summary>
/// 判断轴是否运动完成
/// </summary>
protected bool AxisMoveIsEnd(ConfigMoveAxis moveAxis,int targetPosition,int targetSpeed,out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
if (DeviceControl.isNoDeviceDebug)
{
return true;
}
bool isend = KTKSMCManager.IsMoveEnd(deviceName, axisNo);
int outCount = KTKSMCManager.WGetCountPulse(deviceName, axisNo);
int errorCount=Math.Abs(outCount-targetPosition);
if (isend)
{
if (errorCount > moveAxis.CanErrorCountMax)
{
//判断是否需要重新运动
if (StoreMove.CanWhileCount > 0)
{
LogUtil.error(LOGGER, StoreName + " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",targetSpeed=" + targetSpeed + ",当前outCount=" + outCount +
",误差值大于最大误差【" + moveAxis.CanErrorCountMax + "】,但是轴已经停止运动,还有【" + StoreMove.CanWhileCount + "】次可以重复运动的次数");
LogUtil.error(LOGGER,StoreName + " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + "开始重新运动");
KTKSMCManager.ABSMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), targetPosition, targetSpeed, moveAxis.AccelTime, moveAxis.DecelTime,moveAxis.ResolveSpeed);
StoreMove.CanWhileCount--;
}
else
{
msg = StoreName + " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",targetSpeed=" + targetSpeed + ",当前outCount=" + outCount +",误差值大于最大误差【" + moveAxis.CanErrorCountMax + "】,但是轴已经停止运动,需要报警";
LogUtil.error(LOGGER, msg);
return false;
}
}
else
{
//信号显示轴已经运行结束,验证脉冲数
MoveEndPro(moveAxis.GetAxisValue());
return true;
}
}
else if (errorCount < moveAxis.CanErrorCountMin)
{
LogUtil.info(LOGGER, " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",当前outCount=" + outCount +
",误差值小于最小误差【" + moveAxis.CanErrorCountMin + "】,默认轴已经停止运动");
//信号显示轴已经运行结束,验证脉冲数
MoveEndPro(moveAxis.GetAxisValue());
return true;
}
return false;
}
protected bool HomeMoveIsEnd(ConfigMoveAxis moveAxis){
if (KTKSMCManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()) || DeviceControl.isNoDeviceDebug)
{
MoveEndPro(moveAxis.GetAxisValue());
return true;
}
return false;
}
/// <summary>
/// 轴原点返回运动,等待收到反馈后才会返回
/// </summary>
/// <param name="moveAxis">需要运动的轴</param>
/// <param name="speed">速度</param>
protected void AxisHomeMove(ConfigMoveAxis moveAxis)
{
if (!DBStoreManager.isUseMiddleAxis)
{
return;
}
moveAxis.TargetPosition = 0;
LogUtil.debug(LOGGER, "DeviceName=" + moveAxis.DeviceName + ",AxisNo=" + moveAxis.GetAxisValue() + ",speed=" + moveAxis.TargetSpeed + "开始原点返回");
AddAxisMoveTime(moveAxis);
if (SAStoreManager.store != null)
{
if (moveAxis.GetAxisValue().Equals(2)) {
KTKSMCManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.StartSpeed,
moveAxis.TargetSpeed, moveAxis.AccelTime, moveAxis.DecelTime, moveAxis.ResolveSpeed, (short)CSmcConst.CSMC_CW);
}
else
{
KTKSMCManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.StartSpeed,
moveAxis.TargetSpeed, moveAxis.AccelTime, moveAxis.DecelTime, moveAxis.ResolveSpeed, (short)CSmcConst.CSMC_CCW);
}
}
else
{
KTKSMCManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.StartSpeed, moveAxis.TargetSpeed, moveAxis.AccelTime, moveAxis.DecelTime, moveAxis.ResolveSpeed);
}
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
}
protected void AxisHomeMove_Middle(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.debug(LOGGER, "DeviceName=" + moveAxis.DeviceName + ",AxisNo=" + moveAxis.GetAxisValue() + ",speed=" + moveAxis.TargetSpeed + "开始原点返回");
AddAxisMoveTime(moveAxis);
KTKSMCManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.StartSpeed, moveAxis.TargetSpeed, moveAxis.AccelTime, moveAxis.DecelTime, moveAxis.ResolveSpeed, true);
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
}
/// <summary>
/// 将轴位置重置
/// </summary>
/// <param name="moveAxis"></param>
protected void AxisCountClear(ConfigMoveAxis moveAxis)
{
if (!DBStoreManager.isUseMiddleAxis)
{
return;
}
LogUtil.debug(LOGGER, "重置轴deviceName=[" + moveAxis.DeviceName + "],AxisNo=[" + moveAxis.GetAxisValue() + "]的位置");
KTKSMCManager.WSetOutPulse(moveAxis.DeviceName, moveAxis.GetAxisValue(), 0);
KTKSMCManager.WSetCountPulse(moveAxis.DeviceName, moveAxis.GetAxisValue(), 0);
}
#endregion
#region 电钢运动
/// <summary>
/// 电钢运动 会自动加入等待列表中
/// </summary>
public void StellMove(int slvAddr, int targetPosition, int speed)
{
//ModbusBean.instance.MoveAbsolute((byte)slvAddr, targetPosition, speed, 1000, 1000);
//StoreMove.WaitList.Add(WaitResultInfo.WaitStell((byte)slvAddr, targetPosition, speed));
}
/// <summary>
/// 电钢运动 原点返回
/// </summary>
public void StellHomeMove(int slvAddr, int targetPosition, int speed)
{
//try
//{
// ModbusBean.instance.Home((byte)slvAddr);
// StoreMove.WaitList.Add(WaitResultInfo.WaitStellHome((byte)slvAddr, targetPosition, speed));
//}
//catch (Exception ex)
//{
// LogUtil.error(LOGGER, "StellHomeMove报错:" + ex.ToString());
//}
}
protected bool StellHomeMoveIsEnd(byte slvAddr,int targetPosition, int speed)
{
//try
//{
// if (ModbusBean.instance.IsPortOpen())
// {
// int? actualposition, commandposition;
// // 读取电机的实际位置,并将读取结果的判断值(例:错误代码)赋给变量resultap
// ErrorCode resultap = ModbusBean.instance.ReadActualPosition(slvAddr, out actualposition);
// // 读取指令位置,并将读取结果的判断值(例:错误代码)赋给变量resultcp
// ErrorCode resultcp = ModbusBean.instance.ReadCommandPosition(slvAddr, out commandposition);
// if (actualposition == null)
// {
// LogUtil.debug(LOGGER, "判断电钢是否原点返回错误:获取到的actualposition是空");
// actualposition = 9999999;
// }
// if (commandposition == null)
// {
// LogUtil.debug(LOGGER, "判断电钢是否原点返回错误:获取到的commandposition是空");
// commandposition = 9999999;
// }
// int cha = Math.Abs(targetPosition - (int)actualposition);
// int cha2 = (Math.Abs(targetPosition - (int)commandposition));
// if (cha <= 10 && cha2 <= 10)
// {
// return true;
// }
// else
// {
// //重新运动一次
// if (StoreMove.CanWhileCount > 0)
// {
// StellHomeMove(slvAddr, targetPosition, speed);
// StoreMove.CanWhileCount--;
// }
// }
// }
//}
//catch (Exception ex)
//{
// LogUtil.error(LOGGER, "判断电钢是否原点返回报错:" + ex.ToString());
//}
return false;
}
/// <summary>
/// 将电钢位置重置
/// </summary>
protected void StellCountClear(int slvAddr)
{
}
/// <summary>
/// 判断电钢是否运动完成
/// </summary>
protected bool StellMoveIsEnd(byte slvAddr, int targetPosition, int speed, out string msg)
{
msg = "";
//try
//{
// if (ModbusBean.instance.IsPortOpen())
// {
// int? actualposition, commandposition;
// // 读取电机的实际位置,并将读取结果的判断值(例:错误代码)赋给变量resultap
// ErrorCode resultap = ModbusBean.instance.ReadActualPosition(slvAddr, out actualposition);
// // 读取指令位置,并将读取结果的判断值(例:错误代码)赋给变量resultcp
// ErrorCode resultcp = ModbusBean.instance.ReadCommandPosition(slvAddr, out commandposition);
// if (actualposition==null)
// {
// LogUtil.debug(LOGGER, "判断电钢是否运动到位错误:获取到的actualposition是空");
// actualposition = 9999999;
// }
// if (commandposition == null)
// {
// LogUtil.debug(LOGGER, "判断电钢是否运动到位错误:获取到的commandposition是空");
// commandposition = 9999999;
// }
// int cha = Math.Abs(targetPosition - (int)actualposition);
// int cha2 = (Math.Abs(targetPosition - (int)commandposition));
// if (cha <= 10 && cha2 <= 10)
// {
// return true;
// }
// else
// {
// //重新运动一次
// if (StoreMove.CanWhileCount > 0)
// {
// StellMove(slvAddr, targetPosition, speed);
// StoreMove.CanWhileCount--;
// }
// }
// }
//}
//catch (Exception ex)
//{
// LogUtil.error(LOGGER, "判断电钢是否运动到位报错:" + ex.ToString());
//}
return false;
}
#endregion
#region 扫码枪代码
/// <summary>
/// 扫码枪链接
/// </summary>
protected TcpClient scannerSocket;
/// <summary>
/// 扫描枪 是否开始运行
/// </summary>
public bool isScannerRun = false;
/// <summary>
/// 开启扫码枪
/// </summary>
public bool StartScanner(string serverIp, int port)
{
return StartScanner(serverIp, port, false);
}
/// <summary>
/// 停止扫码枪
/// </summary>
public void StopScanner()
{
try
{
scannerSocket.close();
isScannerRun = false;
}
catch (Exception ex)
{
LogUtil.error(LOGGER,"出错:"+ ex);
}
}
/// <summary>
/// 发送扫码命令开始扫码
/// </summary>
public void BeginScannering()
{
string str = ConfigAppSettings.GetValue(Setting_Init.scanner_start_command);
scannerSocket.send(str);
//onCodeReceived("AAAA");
}
/// <summary>
/// 开启扫码枪
/// </summary>
public bool StartScanner(string serverIp, int port, bool isMustCon)
{
bool result = true;
try
{
if (!isScannerRun || isMustCon)
{
if (scannerSocket == null)
{
scannerSocket = new TcpClient();
}
result = scannerSocket.connect(serverIp, port, new TcpClient.HandleMessage(onCodeReceived));
if (result)
{
isScannerRun = true;
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex);
}
return result;
}
/// <summary>
/// 扫码枪数据接收
/// </summary>
/// <param name="message"></param>
protected virtual void onCodeReceived(string message)
{
try
{
message = message.Replace("\r", "");
message = message.Replace("\n", "");
char a = (char)02;
message = message.Replace(a.ToString(), "");
message = message.Trim();
if (!string.IsNullOrEmpty(message))
{
LogUtil.info(LOGGER, "收到扫码器数据<< \n" + message);
}
else
{
LogUtil.error(LOGGER, "没有收到二维码信息,请重新放入料盘");
return;
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.StackTrace);
}
}
#endregion
/// <summary>
/// 运动处理
/// </summary>
protected bool isInPro = false;
protected virtual void BusyMoveProcess()
{
if (isInPro)
{
return;
}
isInPro = true;
if (DeviceControl.isNoDeviceDebug)
{
StoreMove.EndStepWait();
}
switch (StoreMove.MoveType)
{
case StoreMoveType.InStore:
InStoreProcess();
isInPro = false;
break;
case StoreMoveType.OutStore:
OutStoreProcess();
isInPro = false;
break;
case StoreMoveType.ReturnHome:
ReturnHomeProcess();
isInPro = false;
break;
case StoreMoveType.StoreReset:
ResetProcess();
isInPro = false;
break;
default: break;
}
isInPro = false;
}
protected void SaveAlarmInfo(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType)
{
alarmMsg = alarmMsg.Replace(StoreName, "");
int inoutStatus = 0;
if (storeMoveType.Equals(StoreMoveType.InStore))
{
inoutStatus = 1;
}
else if (storeMoveType.Equals(StoreMoveType.InStore))
{
inoutStatus = 2;
}
int aType = 0;
switch (alarmType)
{
case StoreAlarmType.AxisMoveError:
aType = 2;
break;
case StoreAlarmType.AxisAlarm:
aType = 2;
break;
case StoreAlarmType.SuddenStop:
aType = 1;
alarmDetial = "1";
break;
case StoreAlarmType.NoAirCheck:
aType = 1;
alarmDetial = "2";
break;
case StoreAlarmType.IoSingleTimeOut:
aType = 3;
break;
case StoreAlarmType.StellAlarm:
aType = 2;
alarmDetial = "5";
break;
default: break;
}
alarmInfo = new AlarmInfo(StoreID, aType, alarmDetial, alarmMsg, inoutStatus);
}
/// <summary>
/// 开始运行
/// </summary>
public abstract bool StartRun();
/// <summary>
/// 停止运行
/// </summary>
public abstract void StopRun();
/// <summary>
/// 报警
/// </summary>
/// <param name="alarmType"></param>
public abstract void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType);
/// <summary>
/// 重置(夹料装置状态不变)
/// </summary>
public abstract void Reset();
/// <summary>
/// 停止所有运动
/// </summary>
public abstract void StopMove();
/// <summary>
/// 重置处理
/// </summary>
protected abstract void ResetProcess();
/// <summary>
/// 原点返回处理
/// </summary>
protected abstract void ReturnHomeProcess();
/// <summary>
/// 松下伺服轴原点返回运动,等待收到反馈后才会返回
/// </summary>
protected void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.debug(LOGGER, "DeviceName=" + moveAxis.DeviceName + ",AxisNo=" + moveAxis.GetAxisValue() + ",speed=" + moveAxis.TargetSpeed + "开始原点返回");
AddAxisMoveTime(moveAxis);
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.TargetSpeed);
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
protected void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, int startSpeed)
{
moveAxis.TargetPosition = targetPosition;
AddAxisMoveTime(moveAxis);
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition,targetSpeed);
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, 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 isend =ACServerManager.IsHomeMoveEnd(deviceName, axisNo);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isend)
{
if (errorCount > moveAxis.CanErrorCountMax)
{
//判断是否需要重新运动
if (StoreMove.CanWhileCount > 0)
{
LogUtil.error(LOGGER, StoreName + " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",targetSpeed=" + targetSpeed + ",当前outCount=" + outCount +
",误差值大于最大误差【" + moveAxis.CanErrorCountMax + "】,但是轴已经停止运动,还有【" + StoreMove.CanWhileCount + "】次可以重复运动的次数");
LogUtil.error(LOGGER, StoreName + " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + "开始重新运动");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition,targetSpeed);
StoreMove.CanWhileCount--;
}
else
{
msg = StoreName + " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",targetSpeed=" + targetSpeed + ",当前outCount=" + outCount + ",误差值大于最大误差【" + moveAxis.CanErrorCountMax + "】,但是轴已经停止运动,需要报警";
LogUtil.error(LOGGER, msg);
return false;
}
}
else
{
//信号显示轴已经运行结束,验证脉冲数
MoveEndPro(moveAxis.GetAxisValue());
return true;
}
}
else if (errorCount < moveAxis.CanErrorCountMin)
{
LogUtil.info(LOGGER, " storeMoveStep=" + StoreMove.MoveStep + ", DeviceName=" + deviceName + ",AxisNo=" + axisNo + ",targetPosition=" + targetPosition + ",当前outCount=" + outCount +
",误差值小于最小误差【" + moveAxis.CanErrorCountMin + "】,默认轴已经停止运动");
//信号显示轴已经运行结束,验证脉冲数
MoveEndPro(moveAxis.GetAxisValue());
return true;
}
return false;
}
protected bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis)
{
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()) )
{
MoveEndPro(moveAxis.GetAxisValue());
return true;
}
return false;
}
}
}