领胜LDS 键盘AOI检测项目
xcd
2020-07-09 1e12238d9d6ea02f89aa7150f8507c9d8368a429
板卡操作配置编辑时传递轴号和轴名称
5个文件已修改
465 ■■■■■ 已修改文件
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs 137 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Common.Model/Forms/FrmDeviceOpConfigEditor.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Common.Model/Model/MotionCardRelated.cs 314 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Device.GTSCard/GTSCardDriver.cs 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M071.Process/M071Process.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
@@ -190,13 +190,48 @@
        [Category("板卡操作")]
        [Description("板卡操作配置基类集合,依次执行")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<MotionCardOperationSet>), typeof(UITypeEditor))]
        [Editor(typeof(MotionCardOperationSetEditor), typeof(UITypeEditor))]
        public List<MotionCardOperationSet> OperationCollection { get; set; } = new List<MotionCardOperationSet>();
        public string GetDisplayText()
        {
            //OperationCollection.ForEach(o =>
            //{
            //    o.MotionCardId = DeviceId;
            //});
            return string.Join(" ", OperationCollection.Select(u => u.GetDisplayText()));
        }
    }
    public class MotionCardOperationSetEditor : ComplexCollectionEditor<MotionCardOperationSet>
    {
        public MotionCardOperationSetEditor(Type type) : base(type) { }
        IOperationConfig opConfig = null;
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context.Instance is IOperationConfig config && value is List<MotionCardOperationSet> setList)
            {
                opConfig = config;
                setList.ForEach(set => set.MotionCardId = opConfig.DeviceId);
            }
            return base.EditValue(context, provider, value);
        }
        protected override object CreateInstance(Type itemType)
        {
            object obj = base.CreateInstance(itemType);
            if (obj is MotionCardOperationSet set)
            {
                set.MotionCardId = opConfig?.DeviceId;
            }
            return obj;
        }
    }
    [Device("MotionOperationSet", "运动操作配置基类", EnumHelper.DeviceAttributeType.OperationConfig)]
@@ -230,18 +265,21 @@
        [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(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public MotionOperationCollection MotionOperationCollection { get; set; } = new MotionOperationCollection();
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(MovingOpsCollectionEditor), typeof(UITypeEditor))]
        public List<MovingOption> MovingOps { get; set; } = new List<MovingOption>();
        public string MotionCardId = "";
        //[Category("板卡运动配置")]
        //[DisplayName("运动配置集合")]
        //[Description("MovingOps:运动配置集合")]
        //[TypeConverter(typeof(ComplexObjectConvert))]
        //[Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        //public MotionOperationCollection MotionOperationCollection { get; set; } = new MotionOperationCollection();
        public string GetDisplayText()
@@ -276,14 +314,15 @@
            }
            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();
        }
@@ -444,4 +483,66 @@
        //}
    }
    public class MovingOpsCollectionEditor : ComplexCollectionEditor<MovingOption>
    {
        public MovingOpsCollectionEditor(Type type) : base(type)
        {
        }
        MotionCardBase motionCard = null;
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context.Instance is MotionCardOperationSet set)
            {
                if (!string.IsNullOrWhiteSpace(set.MotionCardId))
                {
                    using (var scope = GlobalVar.Container.BeginLifetimeScope())
                    {
                        var deviceList = scope.Resolve<List<IDevice>>();
                        if (deviceList != null)
                        {
                            motionCard = deviceList.FirstOrDefault(u => u.Id == set.MotionCardId) as MotionCardBase;
                        }
                    }
                }
                if (motionCard != null && value is List<MovingOption> ops)
                {
                    ops.ForEach(o => o.SetAxisSetting(motionCard.IConfig.AxisSettings));
                }
            }
            return base.EditValue(context, provider, value);
        }
        protected override object SetItems(object editValue, object[] value)
        {
            Array.ForEach(value, v =>
             {
                 if (v is MovingOption op && motionCard != null)
                 {
                     op.SetAxisSetting(motionCard.IConfig.AxisSettings);
                 }
             });
            return base.SetItems(editValue, value);
        }
        ///// <summary>
        ///// 限制一次选一个实例
        ///// </summary>
        ///// <returns></returns>
        //protected override bool CanSelectMultipleInstances()
        //{
        //    return false;
        //}
        ///// <summary>
        ///// 指定创建的对象类型
        ///// </summary>
        ///// <returns></returns>
        //protected override Type CreateCollectionItemType()
        //{
        //    return typeof(MovingOption);
        //}
    }
}
src/Bro.Common.Model/Forms/FrmDeviceOpConfigEditor.cs
@@ -120,6 +120,7 @@
        {
            Bind.Device = cboDevice.SelectedValue.ToString();
            Bind.OpConfig = propGrid.SelectedObject as IOperationConfig;
            Bind.OpConfig.DeviceId = Bind.Device;
            this.DialogResult = DialogResult.OK;
        }
src/Bro.Common.Model/Model/MotionCardRelated.cs
@@ -1,9 +1,11 @@
using Bro.Common.Helper;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
@@ -241,115 +243,129 @@
    /// <summary>
    /// 运动对象
    /// </summary>
    public class MovingOption : INotifyPropertyChanged, IComplexDisplay
    public class MovingOption : IComplexDisplay
    {
        private int axisIndex = 0;
        [Category("运动配置")]
        [DisplayName("运动轴索引")]
        [Description("AxisIndex:运动轴索引")]
        [TypeConverter(typeof(AxisIndexConvert))]
        public string AxisIndexStr { get; set; } = "0";
        [Browsable(false)]
        [JsonIgnore]
        public int AxisIndex
        {
            get => axisIndex;
            set
            {
                if (axisIndex != value)
                {
                    axisIndex = value;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AxisIndex"));
                }
                axisIndex = value;
            }
            get => int.Parse(AxisIndexStr);
            set => AxisIndexStr = value.ToString();
        }
        private MotionMode moveMode = MotionMode.Normal;
        //private int axisIndex = 0;
        //[Category("运动配置")]
        //[DisplayName("运动轴索引")]
        //[Description("AxisIndex:运动轴索引")]
        //[TypeConverter(typeof(AxisIndexConvert))]
        //public int AxisIndex { get; set; }
        //{
        //    get => axisIndex;
        //    set
        //    {
        //        if (axisIndex != value)
        //        {
        //            axisIndex = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AxisIndex"));
        //        }
        //        axisIndex = value;
        //    }
        //}
        //private MotionMode moveMode = MotionMode.Normal;
        [Category("运动配置")]
        [DisplayName("运动模式")]
        [Description("MoveMode:运动模式")]
        public MotionMode MoveMode
        {
            get => moveMode;
            set
            {
                if (moveMode != value)
                {
                    moveMode = value;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MoveMode"));
                }
        public MotionMode MoveMode { get; set; } = MotionMode.Normal;
        //{
        //    get => moveMode;
        //    set
        //    {
        //        if (moveMode != value)
        //        {
        //            moveMode = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MoveMode"));
        //        }
                moveMode = value;
            }
        }
        //        moveMode = value;
        //    }
        //}
        private bool isAbsolute = true;
        //private bool isAbsolute = true;
        [Category("运动配置")]
        [DisplayName("是否绝对运动")]
        [Description("IsAbsolute:是否绝对运动")]
        public bool IsAbsolute
        {
            get => isAbsolute;
            set
            {
                if (isAbsolute != value)
                {
                    isAbsolute = value;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsAbsolute"));
                }
        public bool IsAbsolute { get; set; } = true;
        //{
        //    get => isAbsolute;
        //    set
        //    {
        //        if (isAbsolute != value)
        //        {
        //            isAbsolute = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsAbsolute"));
        //        }
                isAbsolute = value;
            }
        }
        //        isAbsolute = value;
        //    }
        //}
        private int destination = 0;
        //private int destination = 0;
        [Category("运动配置")]
        [DisplayName("目的地")]
        [Description("Destination:目的地")]
        public int Destination
        {
            get => destination;
            set
            {
                if (destination != value)
                {
                    destination = value;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Destination"));
                }
        public int Destination { get; set; }
        //{
        //    get => destination;
        //    set
        //    {
        //        if (destination != value)
        //        {
        //            destination = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Destination"));
        //        }
                destination = value;
            }
        }
        //        destination = value;
        //    }
        //}
        private VelocityPara velocityPara = new VelocityPara();
        //private VelocityPara velocityPara = new VelocityPara();
        [Category("运动配置")]
        [DisplayName("速度参数")]
        [Description("VelocityPara:速度参数")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public VelocityPara VelocityPara
        {
            get => velocityPara;
            set
            {
                velocityPara = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("VelocityPara"));
            }
        }
        public VelocityPara VelocityPara { get; set; } = new VelocityPara();
        //{
        //    get => velocityPara;
        //    set
        //    {
        //        velocityPara = value;
        //        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("VelocityPara"));
        //    }
        //}
        private GoHomePara goHomePara = new GoHomePara();
        //private GoHomePara goHomePara = new GoHomePara();
        [Category("运动配置")]
        [DisplayName("回原点参数")]
        [Description("GoHomePara:速度参数")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public GoHomePara GoHomePara
        {
            get => goHomePara;
            set
            {
                goHomePara = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GoHomePara"));
            }
        }
        public GoHomePara GoHomePara { get; set; } = new GoHomePara();
        //{
        //    get => goHomePara;
        //    set
        //    {
        //        goHomePara = value;
        //        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GoHomePara"));
        //    }
        //}
        [Category("板卡运动配置")]
        [Description("超时设置,单位:ms")]
@@ -357,6 +373,7 @@
        public int MovingTimeout { get; set; } = 0;
        internal List<AxisSetting> _axisSettingList = new List<AxisSetting>();
        public void SetAxisSetting(List<AxisSetting> settings)
        {
            if (settings != null)
@@ -365,7 +382,7 @@
        public string GetDisplayText()
        {
            string axisName = AxisIndex.ToString();
            string axisName = AxisIndexStr;
            var axisSet = _axisSettingList.FirstOrDefault(a => a.AxisIndex == AxisIndex);
            if (axisSet != null)
            {
@@ -373,70 +390,113 @@
            }
            return axisName + "," + MoveMode.ToString() + "," + (IsAbsolute ? "Abs" : "Rel") + "," + Destination;
        }
        public event PropertyChangedEventHandler PropertyChanged;
        //public event PropertyChangedEventHandler PropertyChanged;
    }
    public class AxisIndexConvert : TypeConverter
    public class AxisIndexConvert : ComboBoxItemTypeConvert
    {
        Dictionary<int, string> _indexNameDict = new Dictionary<int, string>();
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        public override Hashtable GetConvertHash(ITypeDescriptorContext context)
        {
            return true;
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            MovingOption mo = context.Instance as MovingOption;
            _indexNameDict = mo._axisSettingList.ToDictionary(a => a.AxisIndex, a => a.AxisIndex + "-" + a.AxisName);
            return new StandardValuesCollection(_indexNameDict.Keys);
        }
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == typeof(string))
            Hashtable table = new Hashtable();
            if (context.Instance is MovingOption op)
            {
                return true;
            }
            return base.CanConvertFrom(context, sourceType);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v)
        {
            if (v is string)
            {
                foreach (var indexName in _indexNameDict)
                op._axisSettingList.ForEach(a =>
                {
                    if (indexName.Value == v.ToString())
                    {
                        return indexName.Key;
                    }
                }
                return Convert.ToInt32(v);
                    table[a.AxisIndex.ToString()] = a.AxisName;
                });
            }
            return base.ConvertFrom(context, culture, v);
            return table;
        }
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                if (_indexNameDict.ContainsKey(Convert.ToInt32(v)))
                {
                    return _indexNameDict[Convert.ToInt32(v)];
                }
            }
            return base.ConvertTo(context, culture, v, destinationType);
        }
        //public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        //{
        //    bool flag = base.CanConvertFrom(context, sourceType);
        //    return flag;
        //}
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }
        //public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        //{
        //    return base.CanConvertTo(context, destinationType);
        //}
        //public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object v)
        //{
        //    //if (string.IsNullOrWhiteSpace(v.ToString()))
        //    //{
        //    //    return 0;
        //    //}
        //    return base.ConvertFrom(context, culture, Convert.ToInt32(v));
        //}
        //public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object v, Type destinationType)
        //{
        //    return base.ConvertTo(context, culture, v, destinationType);
        //}
    }
    //public class AxisIndexConvert : TypeConverter
    //{
    //    Dictionary<int, string> _indexNameDict = new Dictionary<int, string>();
    //    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    //    {
    //        return true;
    //    }
    //    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    //    {
    //        MovingOption mo = context.Instance as MovingOption;
    //        _indexNameDict = mo._axisSettingList.ToDictionary(a => a.AxisIndex, a => a.AxisIndex + "-" + a.AxisName);
    //        return new StandardValuesCollection(_indexNameDict.Keys);
    //    }
    //    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    //    {
    //        if (sourceType == typeof(string))
    //        {
    //            return true;
    //        }
    //        return base.CanConvertFrom(context, sourceType);
    //    }
    //    public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v)
    //    {
    //        if (v is string)
    //        {
    //            foreach (var indexName in _indexNameDict)
    //            {
    //                if (indexName.Value == v.ToString())
    //                {
    //                    return indexName.Key;
    //                }
    //            }
    //            return Convert.ToInt32(v);
    //        }
    //        return base.ConvertFrom(context, culture, v);
    //    }
    //    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v, Type destinationType)
    //    {
    //        if (destinationType == typeof(string))
    //        {
    //            if (_indexNameDict.ContainsKey(Convert.ToInt32(v)))
    //            {
    //                return _indexNameDict[Convert.ToInt32(v)];
    //            }
    //        }
    //        return base.ConvertTo(context, culture, v, destinationType);
    //    }
    //    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
    //    {
    //        return false;
    //    }
    //}
    public class AxisConflictSet : IComplexDisplay
    {
        [Category("1.轴冲突条件")]
src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -162,7 +162,7 @@
            // 2.板卡运动
            if (CurrentState == DeviceState.DSOpen)
            {
                responseMessage = MoveToPoint(operationSet.MotionOperationCollection);
                responseMessage = MoveToPoint(new MotionOperationCollection() { MovingOps = operationSet.MovingOps });
                if (!responseMessage.Result)
                {
                    return responseMessage;
@@ -362,14 +362,15 @@
        {
            List<short> resultCode = new List<short>() { 0 };
            GTSCardAPI.TTrapPrm trapprm = new GTSCardAPI.TTrapPrm();
            resultCode.Add(GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)optionPara.AxisIndex));
            resultCode.Add(GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, (short)optionPara.AxisIndex, out trapprm));
            short axisIndex = short.Parse(optionPara.AxisIndexStr);
            resultCode.Add(GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, axisIndex));
            resultCode.Add(GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, axisIndex, out trapprm));
            trapprm.smoothTime = 1;
            trapprm.acc = optionPara.VelocityPara.Acc != 0 ? optionPara.VelocityPara.Acc : 1;
            trapprm.dec = optionPara.VelocityPara.Dec != 0 ? optionPara.VelocityPara.Dec : 1;
            resultCode.Add(GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, (short)optionPara.AxisIndex, ref trapprm));
            resultCode.Add(GTSCardAPI.GT_SetVel((short)IConfig.CardNum, (short)optionPara.AxisIndex, optionPara.VelocityPara.Velocity * IConfig.AxisVelocityRatio));
            resultCode.Add(GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, axisIndex, ref trapprm));
            resultCode.Add(GTSCardAPI.GT_SetVel((short)IConfig.CardNum, axisIndex, optionPara.VelocityPara.Velocity * IConfig.AxisVelocityRatio));
            var resultOK = resultCode.All(u => u == (short)GTSRetCode.GRCRunOK);
            if (!resultOK)
src/Bro.M071.Process/M071Process.cs
@@ -346,7 +346,7 @@
                                IShapeElement indicator = null;
                                pMeasure.ElementList.Add(indicator);
                                //输出图形基元到界面 todo
                                //输出图形基元到界面
                                OnElementUpdated?.BeginInvoke(indicator, null, null);
                                SaveKeyImages(pMeasure.Barcode, m);