领胜LDS 键盘AOI检测项目
wells.liu
2020-07-04 ff58f159796469f2ad7e6922fa5698654bc98c23
板卡运动配置
2个文件已修改
101 ■■■■■ 已修改文件
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.GTSCard/GTSCardDriver.cs 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
    //{
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 是开、关 从MonitorValues 获取
                        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 是开、关 从MonitorValues 获取
                    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 是开、关 从MonitorValues 获取
                        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)