From ff58f159796469f2ad7e6922fa5698654bc98c23 Mon Sep 17 00:00:00 2001
From: wells.liu <wells.liu@broconcentric.com>
Date: 星期六, 04 七月 2020 13:51:39 +0800
Subject: [PATCH] 板卡运动配置
---
src/Bro.Device.GTSCard/GTSCardDriver.cs | 53 ++++++++++++++++----------
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs | 48 +++++++++++++++++------
2 files changed, 67 insertions(+), 34 deletions(-)
diff --git a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
index e42e318..117a980 100644
--- a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
+++ b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
@@ -138,7 +138,7 @@
[Category("鏉垮崱鎿嶄綔")]
[Description("鏉垮崱鎿嶄綔閰嶇疆鍩虹被闆嗗悎锛屼緷娆℃墽琛�")]
[TypeConverter(typeof(CollectionCountConvert))]
- [Editor(typeof(ComplexCollectionEditor<MotionCardOperationConfigBase>), typeof(UITypeEditor))]
+ [Editor(typeof(ComplexCollectionEditor<MotionCardOperationSet>), typeof(UITypeEditor))]
public List<MotionCardOperationSet> OperationCollection { get; set; } = new List<MotionCardOperationSet>();
public string GetDisplayText()
@@ -147,7 +147,8 @@
}
}
- public class MotionCardOperationSet : IComplexDisplay
+ [Device("MotionOperationSet", "杩愬姩鎿嶄綔閰嶇疆鍩虹被", EnumHelper.DeviceAttributeType.OperationConfig)]
+ public class MotionCardOperationSet : IComplexDisplay
{
[Category("IO鎿嶄綔閰嶇疆")]
[DisplayName("IO棰勬鏌ュ畾涔夐泦鍚�")]
@@ -176,12 +177,18 @@
[DisplayName("IO纭瓒呮椂")]
public int IOConfirmTimeout { get; set; } = 0;
+ //[Category("鏉垮崱杩愬姩閰嶇疆")]
+ //[DisplayName("杩愬姩閰嶇疆闆嗗悎")]
+ //[Description("MovingOps锛氳繍鍔ㄩ厤缃泦鍚�")]
+ //[TypeConverter(typeof(CollectionCountConvert))]
+ //[Editor(typeof(ComplexCollectionEditor<MovingOption>), typeof(UITypeEditor))]
+ //public List<MovingOption> MovingOps { get; set; } = new List<MovingOption>();
[Category("鏉垮崱杩愬姩閰嶇疆")]
[DisplayName("杩愬姩閰嶇疆闆嗗悎")]
[Description("MovingOps锛氳繍鍔ㄩ厤缃泦鍚�")]
- [TypeConverter(typeof(CollectionCountConvert))]
- [Editor(typeof(ComplexCollectionEditor<MovingOption>), typeof(UITypeEditor))]
- public List<MovingOption> MovingOps { get; set; } = new List<MovingOption>();
+ [TypeConverter(typeof(ComplexObjectConvert))]
+ [Editor(typeof(PropertyObjectEditor),typeof(UITypeEditor))]
+ public MotionOperationCollection MotionOperationCollection { get; set; } = new MotionOperationCollection();
public string GetDisplayText()
@@ -216,19 +223,34 @@
}
string moving = "";
- MovingOps.ForEach(i =>
- {
- moving += i.GetDisplayText() + " ";
- });
- if (moving != "")
- {
- moving = " 杩愬姩锛�" + moving;
- }
+ //MovingOps.ForEach(i =>
+ //{
+ // moving += i.GetDisplayText() + " ";
+ //});
+ //if (moving != "")
+ //{
+ // moving = " 杩愬姩锛�" + moving;
+ //}
return (preCheck + output + confirm + moving).Trim();
}
}
+ public class MotionOperationCollection : OperationConfigBase, IComplexDisplay
+ {
+ [Category("杩愬姩閰嶇疆")]
+ [DisplayName("杩愬姩閰嶇疆闆嗗悎")]
+ [Description("MovingOps锛氳繍鍔ㄩ厤缃泦鍚�")]
+ [TypeConverter(typeof(CollectionCountConvert))]
+ [Editor(typeof(ComplexCollectionEditor<MovingOption>), typeof(UITypeEditor))]
+ public List<MovingOption> MovingOps { get; set; } = new List<MovingOption>();
+
+ public string GetDisplayText()
+ {
+ return $"{string.Join(" ", MovingOps.Select(u => u.GetDisplayText()))}";
+ }
+ }
+
//[Device("MotionCardOperationConfigCollection", "鏉垮崱鎿嶄綔閰嶇疆鍩虹被闆嗗悎", EnumHelper.DeviceAttributeType.OperationConfig)]
//public class MotionCardOperationConfigCollection : OperationConfigBase
//{
diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index 3368e83..f2c0343 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -76,27 +76,44 @@
}
/// <summary>
- /// 璁惧 杩愯
+ /// 璁惧 杩愯锛堟墽琛� 鏉垮崱绯诲垪鐨勬搷浣滅殑 闆嗗悎锛�
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public override ResponseMessage Run(IOperationConfig config)
{
ResponseMessage responseMessage = new ResponseMessage();
- var opConfig = config as GTSCardOperationConfig;
+ var motionCardOperationConfig = config as MotionCardOperationConfigBase;
+ foreach (var operationSet in motionCardOperationConfig.OperationCollection)
+ {
+ responseMessage = RunOperationSet(operationSet);
+ if (!responseMessage.Result)
+ {
+ return responseMessage;
+ }
+ }
+ return responseMessage;
+ }
+
+ /// <summary>
+ /// 鎵ц 涓�涓郴鍒楃殑鎿嶄綔
+ /// </summary>
+ private ResponseMessage RunOperationSet(MotionCardOperationSet operationSet)
+ {
+ ResponseMessage responseMessage = new ResponseMessage();
// 1.棰勬鏌�
if (CurrentState == DeviceState.DSOpen)
{
- foreach (var preCheck in opConfig.PreCheckIOCollection)
+ foreach (var preCheck in operationSet.PreCheckIOCollection)
{
- int timeout = opConfig.PreCheckIOTimeout;
- int? ioData = null;
+ int timeout = operationSet.PreCheckIOTimeout;
+ IOValue? ioData = null;
while (CurrentState == DeviceState.DSOpen)
{
Thread.Sleep(10);
ioData = MonitorValues.FirstOrDefault(u => u.IONum == preCheck.IOItem.IONum && u.IOType == preCheck.IOItem.IOType)?.Value;//IO 鏄紑銆佸叧 浠嶮onitorValues 鑾峰彇
timeout -= 10;
- if (preCheck.CheckValue == ioData || (opConfig.PreCheckIOTimeout > 0 && timeout < 0))
+ if (preCheck.CheckValue == ioData || (operationSet.PreCheckIOTimeout > 0 && timeout < 0))
{
break;
}
@@ -114,8 +131,7 @@
// 2.鏉垮崱杩愬姩
if (CurrentState == DeviceState.DSOpen)
{
- responseMessage = MoveToPoint(opConfig);
-
+ responseMessage = MoveToPoint(operationSet.MotionOperationCollection);
if (!responseMessage.Result)
{
return responseMessage;
@@ -126,7 +142,7 @@
// 3.IO杈撳嚭 涓嶉渶瑕佽秴鏃�
if (CurrentState == DeviceState.DSOpen)
{
- foreach (var ioOutput in opConfig.IOOutputCollection)
+ foreach (var ioOutput in operationSet.IOOutputCollection)
{
var ioData = MonitorValues.FirstOrDefault(u => u.IONum == ioOutput.IOItem.IONum && u.IOType == ioOutput.IOItem.IOType)?.Value;//IO 鏄紑銆佸叧 浠嶮onitorValues 鑾峰彇
if (ioOutput.CheckValue != ioData)
@@ -141,16 +157,16 @@
// 4.IO纭
if (CurrentState == DeviceState.DSOpen)
{
- foreach (var ioConfirm in opConfig.IOConfirmCollection)
+ foreach (var ioConfirm in operationSet.IOConfirmCollection)
{
- int timeout = opConfig.IOConfirmTimeout;
- int? ioData = null;
+ int timeout = operationSet.IOConfirmTimeout;
+ IOValue? ioData = null;
while (CurrentState == DeviceState.DSOpen)
{
Thread.Sleep(10);
ioData = MonitorValues.FirstOrDefault(u => u.IONum == ioConfirm.IOItem.IONum && u.IOType == ioConfirm.IOItem.IOType)?.Value;//IO 鏄紑銆佸叧 浠嶮onitorValues 鑾峰彇
timeout -= 10;
- if (ioConfirm.CheckValue == ioData || (opConfig.IOConfirmTimeout > 0 && timeout < 0))
+ if (ioConfirm.CheckValue == ioData || (operationSet.IOConfirmTimeout > 0 && timeout < 0))
{
break;
}
@@ -250,19 +266,14 @@
public override ResponseMessage MoveToPoint(IOperationConfig opConfig)
{
ResponseMessage responseMessage = new ResponseMessage();
- var gtsOperationConfig = opConfig as GTSCardOperationConfig;
+ var gtsOperationCollection = opConfig as MotionOperationCollection;
List<Task<bool>> taskList = new List<Task<bool>>();
- //TaskFactory factory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);
- // 濡傛灉鏄涓酱鐨勮繍鍔� 绛夋瘡涓酱杩愬姩缁撴潫
- foreach (var movingOp in gtsOperationConfig.MovingOps)
+ foreach (var movingOp in gtsOperationCollection.MovingOps)
{
- //var task = factory.StartNew<bool>((op) =>
- //{
- // return SingleAxisMoving(op as MovingOption);
- //}, movingOp);
var task = SingleAxisMoving(movingOp);
taskList.Add(task);
}
+
Task.WaitAll(taskList.ToArray());
responseMessage.Result = taskList.All(u => u.GetAwaiter().GetResult());
if (!responseMessage.Result)
--
Gitblit v1.8.0