using Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Configuration; using System.Drawing.Design; using System.Linq; using System.Threading; using static Bro.Common.Helper.EnumHelper; namespace Bro.Device.GTSCard { [Device("GTSCard", "固高板卡", EnumHelper.DeviceAttributeType.OperationConfig)] public class GTSCardOperationConfig : MotionCardOperationConfigBase { //[Category("板卡运动配置")] //[DisplayName("运动配置集合")] //[Description("MovingOps:运动配置集合")] //[TypeConverter(typeof(CollectionCountConvert))] //[Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] //public ObservableCollection MovingOps { get; set; } = new ObservableCollection(); //public string GetDisplayText() //{ // return MovingOps.Count() == 0 ? "--" : string.Join(";", MovingOps.Select(m => m.GetDisplayText())); //} } [Device("GTSCard", "固高板卡", EnumHelper.DeviceAttributeType.InitialConfig)] public class GTSCardInitialConfig : MotionCardInitialConfigBase { //[Category("板卡配置")] //[DisplayName("卡号")] //[Description("CardNum:卡号")] //public int CardNum { get; set; } //[Category("板卡配置")] //[DisplayName("初始配置文件路径")] //[Description("InitialConfigFilePath:初始配置文件路径")] //[Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] //public string InitialConfigFilePath { get; set; } //[Category("轴配置")] //[DisplayName("轴数量")] //[Description("AxisNum:轴数量")] //public int AxisNum { get; set; } = 2; //[Category("轴配置")] //[DisplayName("轴配置信息集合")] //[Description("AxisSettings:轴配置信息集合")] //[TypeConverter(typeof(CollectionCountConvert))] //[Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] //public List AxisSettings { get; set; } = new List(); //[Category("轴配置")] //[DisplayName("轴速度比率")] //[Description("AxisVelocityRatio:轴速度比率")] //public double AxisVelocityRatio { get; set; } = 1; //[Category("延时配置")] //[DisplayName("动作完成后延迟")] //[Description("ActionAfterDelay:动作完成后延迟")] //public int ActionAfterDelay { get; set; } = 100; //[Category("警报配置")] //[Description("WarningSetCollection:警报配置列表")] //[DisplayName("警报配置")] //[TypeConverter(typeof(CollectionCountConvert))] //[Editor(typeof(WarningSetsEditor), typeof(UITypeEditor))] //public List WarningSetCollection { get; set; } = new List(); //#region IMonitorConfig //[Category("监听设置")] //[Description("MonitorSetCollection:监听操作配置集合")] //[DisplayName("监听配置")] //[TypeConverter(typeof(CollectionCountConvert))] //[Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] //public List MonitorSetCollection { get; set; } = new List(); //[Category("监听设置")] //[Description("true:启动监听 false:关闭监听")] //[DisplayName("监听启用")] //public bool IsEnableMonitor { get; set; } = true; //[Category("监听设置")] //[Description("扫描间隔时间,单位:ms")] //[DisplayName("扫描间隔")] //public int MonitorInterval { get; set; } = 10; //[Category("监听设置")] //[Description("超时设置,单位:ms")] //[DisplayName("监听超时")] //public int MonitorTimeout { get; set; } = 500; //[Category("事件地址设置")] //[Description("事件开始地址,PLC的实际寄存器地址。十进制,不包含功能码。")] //[DisplayName("监听开始地址")] //public int EventStartAddress { get; set; } = 8000; ////[Category("事件地址设置")] ////[Description("事件地址长度,最大长度128")] ////[DisplayName("监听长度")] ////public int EventLength { get; set; } = 120; //public List GetAllMonitorSet() //{ // WarningSetCollection.ForEach(m => m.Source = this.Name); // MonitorSetCollection.ForEach(m => m.SourceDevice = this.Id); // return MonitorSetCollection; //} //#endregion //#region IMotion Related //[Category("运动配置")] //[Description("运动轴状态集合")] //[DisplayName("运动轴状态集合")] //[TypeConverter(typeof(CollectionCountConvert))] //[Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] //public List MotionStateCollection { get; set; } = new List(); //#endregion } ///// ///// 轴配置 ///// //public class AxisSetting : IComplexDisplay //{ // [Category("轴配置")] // [DisplayName("轴号索引")] // [Description("AxisIndex:轴号索引")] // public int AxisIndex { get; set; } // [Category("轴配置")] // [DisplayName("轴名称")] // [Description("AxisName:轴名称")] // public string AxisName { get; set; } // [Category("轴配置")] // [DisplayName("轴是否启用")] // [Description("IsAxisEnabled:轴是否启用")] // public bool IsAxisEnabled { get; set; } = false; // [Category("换算配置")] // [DisplayName("脉冲数换算比例")] // [Description("脉冲数和其他计量单位的换算比例,例如设置为1000,表示1000个脉冲等于1uint")] // public int PulseRatio { get; set; } = 1; // [Category("速度配置")] // [DisplayName("默认速度参数")] // [Description("VelocityPara:默认速度参数")] // [TypeConverter(typeof(ComplexObjectConvert))] // [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] // public VelocityPara VelocityPara { get; set; } = new VelocityPara(); // [Category("回原点设置")] // [DisplayName("回原点模式")] // [Description("HomeMode:回原点模式。0:一般模式 1:极限限位模式 2:外部触发模式")] // public int HomeMode { get; set; } = 0; // [Category("回原点设置")] // [DisplayName("回原点方向")] // [Description("IsHomePositive:回原点方向。 true:正方向开始 false:负方向开始")] // public bool IsHomePositive { get; set; } = true; // [Category("回原点设置")] // [DisplayName("是否自动回原点")] // [Description("IsAutoGoHome:是否自动回原点。 true:是 false:否")] // public bool IsAutoGoHome { get; set; } = false; // [Category("超时设置")] // [DisplayName("回原点超时")] // [Description("TimeOutHome:回原点超时,单位毫秒")] // public int TimeOutHome { get; set; } = 30000; // [Category("超时设置")] // [DisplayName("运动超时")] // [Description("TimeOutMove:运动超时,单位毫秒")] // public int TimeOutMove { get; set; } = 10000; // [Category("开闭环设置")] // [DisplayName("是否使用Cmmd回馈")] // [Description("IsUseCmmdPosition:是否使用Cmmd回馈")] // public bool IsUseCmmdPosition { get; set; } = false; // [Category("开闭环设置")] // [DisplayName("是否使用板卡反馈停止信号")] // [Description("IsUseMDNStopSignal:是否使用板卡反馈停止信号")] // public bool IsUseMDNStopSignal { get; set; } = false; // [Category("开闭环设置")] // [DisplayName("是否启用报警")] // [Description("IsUseWarning:是否启用报警")] // public bool IsUseWarning { get; set; } = false; // [Category("暂停配置")] // [DisplayName("是否启用立即暂停")] // [Description("IsImmediatePause:是否启用立即暂停")] // public bool IsImmediatePause { get; set; } = false; // [Category("暂停配置")] // [DisplayName("轴位置处于区间内时适用的暂停操作")] // [Description("ImmediatePauseSections:当轴位置处于区间内时适用的暂停操作")] // [TypeConverter(typeof(CollectionCountConvert))] // [Editor(typeof(ComplexCollectionEditor
), typeof(UITypeEditor))] // public List
ImmediatePauseSections { get; set; } = new List
(); // public string GetDisplayText() // { // return AxisIndex + "-" + AxisName + "-" + (IsAxisEnabled ? "启用" : "禁用"); // } //} ///// ///// 位置对象 ///// //public class Section : IComplexDisplay //{ // [Category("暂停区间")] // [DisplayName("起始位置")] // [Description("StartPosition:起始位置")] // public int StartPosition { get; set; } // [Category("暂停区间")] // [DisplayName("结束位置")] // [Description("EndPosition:结束位置")] // public int EndPosition { get; set; } // public string GetDisplayText() // { // return $"{StartPosition}--{EndPosition}"; // } //} ///// ///// 速度参数对象 ///// //public class VelocityPara //{ // [Category("速度配置")] // [DisplayName("速度")] // [Description("Velocity:速度,为0时表示不修改当前设置")] // public double Velocity { get; set; } = 0; // [Category("速度配置")] // [DisplayName("加速度")] // [Description("Acc:加速度,为0时表示不修改当前设置")] // public double Acc { get; set; } = 1; // [Category("速度配置")] // [DisplayName("减速度")] // [Description("减速度,为0时表示不修改当前设置")] // public double Dec { get; set; } = 1; //} ///// ///// 回原点参数对象 ///// //public class GoHomePara //{ // [Category("回原点参数")] // [DisplayName("回原点方式")] // [Description("HomeMode:回原点方式 (HOME_MODE_LIMIT = 10; HOME_MODE_LIMIT_HOME = 11; HOME_MODE_LIMIT_INDEX = 12; HOME_MODE_LIMIT_HOME_INDEX = 13;HOME_MODE_HOME = 20;HOME_MODE_HOME_INDEX = 22;HOME_MODE_INDEX = 30;")] // public short HomeMode { get; set; } = 11; // [Category("回原点参数")] // [DisplayName("回原点方向")] // [Description("HomeDir:1 正向,-1 负向")] // public short HomeDir { get; set; } = 1; // [Category("回原点参数")] // [DisplayName("回原点方向")] // [Description("HomeDir:1 正向,-1 负向")] // public short Edge { get; set; } = 0; // [Category("回原点参数")] // [DisplayName("回原点最低速度")] // [Description("LowVelocity:速度,为0时表示不修改当前设置")] // public double LowVelocity { get; set; } = 50; // [Category("回原点参数")] // [DisplayName("回原点最高速度")] // [Description("HighVelocity:速度,为0时表示不修改当前设置")] // public double HighVelocity { get; set; } = 50; // [Category("回原点参数")] // [DisplayName("搜搜距离")] // [Description("SearchHomeDistance:搜搜距离")] // public int SearchHomeDistance { get; set; } = 9999999; // [Category("回原点参数")] // [DisplayName("偏移距离")] // [Description("HomeOffset:偏移距离")] // public int HomeOffset { get; set; } = 0; // [Category("回原点参数")] // [DisplayName("跳过步长")] // [Description("EscapeStep:跳过步长")] // public int EscapeStep { get; set; } = 1000; //} ///// ///// 运动对象 ///// //public class MovingOption : INotifyPropertyChanged, IComplexDisplay //{ // private int axisIndex = 0; // [Category("运动配置")] // [DisplayName("运动轴索引")] // [Description("AxisIndex:运动轴索引")] // [TypeConverter(typeof(AxisIndexConvert))] // public int AxisIndex // { // get => axisIndex; // set // { // if (axisIndex != value) // { // axisIndex = value; // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AxisIndex")); // } // axisIndex = value; // } // } // private MotorMoveMode moveMode = MotorMoveMode.Normal; // [Category("运动配置")] // [DisplayName("运动模式")] // [Description("MoveMode:运动模式")] // public MotorMoveMode MoveMode // { // get => moveMode; // set // { // if (moveMode != value) // { // moveMode = value; // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MoveMode")); // } // moveMode = value; // } // } // 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")); // } // isAbsolute = value; // } // } // 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")); // } // destination = value; // } // } // 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")); // } // } // 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")); // } // } // internal List _axisSettingList = new List(); // public void SetAxisSetting(List settings) // { // if (settings != null) // _axisSettingList = settings; // } // public string GetDisplayText() // { // string axisName = AxisIndex.ToString(); // var axisSet = _axisSettingList.FirstOrDefault(a => a.AxisIndex == AxisIndex); // if (axisSet != null) // { // axisName += ("-" + axisSet.AxisName); // } // return axisName + "," + MoveMode.ToString() + "," + (IsAbsolute ? "Abs" : "Rel") + "," + Destination; // } // public event PropertyChangedEventHandler PropertyChanged; //} //public class AxisIndexConvert : TypeConverter //{ // Dictionary _indexNameDict = new Dictionary(); // 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.轴冲突条件")] // [Description("轴冲突条件,满足全部条件时轴运动需要检查冲突")] // [TypeConverter(typeof(CollectionCountConvert))] // [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] // public List AxisOptions { get; set; } = new List(); // [Category("1.轴冲突条件")] // [Description("IO冲突条件,满足全部条件时轴运动需要检查冲突")] // [TypeConverter(typeof(CollectionCountConvert))] // [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] // public List IOOptions { get; set; } = new List(); // [Category("2.轴冲突限制")] // [Description("轴冲突限制,轴运动允许区间")] // [TypeConverter(typeof(CollectionCountConvert))] // [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] // public List AxisLimits { get; set; } = new List(); // [Category("2.轴冲突限制")] // [Description("IO允许条件,允许输出的IO")] // [TypeConverter(typeof(CollectionCountConvert))] // [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] // public List IOOutputs { get; set; } = new List(); // [Category("3.轴冲突启用")] // [Description("true:启用轴冲突限制 false:不启用轴冲突限制")] // public bool IsEnabled { get; set; } = true; // public string GetDisplayText() // { // string optionStr = "Options:" + String.Join(";", AxisOptions.Select(a => a.GetDisplayText())); // string limitStr = "Limits:" + String.Join(";", AxisLimits.Select(a => a.GetDisplayText())); // return optionStr + "|" + limitStr; // } //} //public class AxisLimit : IComplexDisplay //{ // [Category("1.轴号")] // [Description("1.轴号")] // public int AxisIndex { get; set; } // [Category("2.轴最小限制")] // [Description("2.轴最小限制")] // public int LimitMin { get; set; } // [Category("3.轴最大限制")] // [Description("3.轴最大限制")] // public int LimitMax { get; set; } // private int currentPosition = 0; // [Browsable(false)] // [JsonIgnore] // public int CurrentPosition // { // get => currentPosition; // set // { // if (currentPosition != value) // { // if (value >= LimitMin && value <= LimitMax) // { // IsInLimit = true; // } // else // { // IsInLimit = false; // } // } // currentPosition = value; // } // } // [Browsable(false)] // [JsonIgnore] // public bool IsInLimit { get; set; } // public string GetDisplayText() // { // return String.Format("Index:{0},{1}->{2}", AxisIndex, LimitMin, LimitMax); // } //} //public class IOLimit : IComplexDisplay //{ // [Category("1.IO限制")] // [Description("IO索引")] // public int IOIndex { get; set; } // [Category("1.IO限制")] // [Description("IO限制值。输入判断时该值作为启用判断值,输出判断时该值作为允许输出值")] // public bool IOSignal { get; set; } // public string GetDisplayText() // { // return IOIndex + "--" + IOSignal.ToString(); // } //} //public class AxisMovingStay //{ // public int Position { get; set; } // public int Velocity { get; set; } // public AutoResetEvent MoveHandle { get; set; } = new AutoResetEvent(false); // public AutoResetEvent MoveSendHandle { get; set; } = new AutoResetEvent(false); //} }