From 1e12238d9d6ea02f89aa7150f8507c9d8368a429 Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期四, 09 七月 2020 14:29:15 +0800
Subject: [PATCH] 板卡操作配置编辑时传递轴号和轴名称
---
src/Bro.Device.GTSCard/GTSCardDriver.cs | 11
src/Bro.Common.Device/DeviceBase/MotionCardBase.cs | 137 ++++++++++++++--
src/Bro.M071.Process/M071Process.cs | 2
src/Bro.Common.Model/Forms/FrmDeviceOpConfigEditor.cs | 1
src/Bro.Common.Model/Model/MotionCardRelated.cs | 314 +++++++++++++++++++++++---------------
5 files changed, 314 insertions(+), 151 deletions(-)
diff --git a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
index a6d2849..1ff6cd5 100644
--- a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
+++ b/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);
+ //}
+ }
+
}
diff --git a/src/Bro.Common.Model/Forms/FrmDeviceOpConfigEditor.cs b/src/Bro.Common.Model/Forms/FrmDeviceOpConfigEditor.cs
index bb4b9a7..d17062c 100644
--- a/src/Bro.Common.Model/Forms/FrmDeviceOpConfigEditor.cs
+++ b/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;
}
diff --git a/src/Bro.Common.Model/Model/MotionCardRelated.cs b/src/Bro.Common.Model/Model/MotionCardRelated.cs
index 6342b0a..7083a14 100644
--- a/src/Bro.Common.Model/Model/MotionCardRelated.cs
+++ b/src/Bro.Common.Model/Model/MotionCardRelated.cs
@@ -1,9 +1,11 @@
锘縰sing 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.杞村啿绐佹潯浠�")]
diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs
index 240c375..5b3eb7f 100644
--- a/src/Bro.Device.GTSCard/GTSCardDriver.cs
+++ b/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)
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 0b2ad8b..1d8c532 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/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);
--
Gitblit v1.8.0