| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | | |
| | | namespace Bro.Common.Base |
| | | { |
| | |
| | | public abstract ResponseMessage MoveToPoint(IOperationConfig opConfig); |
| | | public abstract void ResetAlarm(); |
| | | public abstract ResponseMessage Run(IOperationConfig config); |
| | | |
| | | public virtual void ExcuteMonitorInvoke(DateTime dateTime, string invokeDevice, IDevice device, IMonitorSet monitorSet) |
| | | { |
| | | OnMonitorInvoke?.BeginInvoke(dateTime, invokeDevice, device, monitorSet, OnMethodInvoked, null); |
| | | } |
| | | |
| | | public abstract void OnMethodInvoked(IAsyncResult ar); |
| | | |
| | | public virtual void ExcuteMonitorAlarm(DateTime dateTime, IDevice device, IWarningSet warningSet) |
| | | { |
| | | OnMonitorAlarm?.BeginInvoke(dateTime, device, warningSet, null, null); |
| | | } |
| | | |
| | | public virtual MotionCardInitialConfigBase IConfig |
| | | { |
| | | get |
| | | { |
| | | return InitialConfig as MotionCardInitialConfigBase; |
| | | } |
| | | } |
| | | |
| | | public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); |
| | | |
| | | public abstract void WriteOutput(short cardNum, short index, IOValue value); |
| | | } |
| | | |
| | | public class MotionCardInitialConfigBase : InitialConfigBase, IMonitorConfig |
| | |
| | | public List<IMonitorSet> GetAllMonitorSet() |
| | | { |
| | | WarningSetCollection.ForEach(m => m.Source = this.Name); |
| | | |
| | | MonitorSetCollection.ForEach(m => m.SourceDevice = this.Id); |
| | | return MonitorSetCollection; |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | [Device("MotionCardBase", "板卡操作配置基类", EnumHelper.DeviceAttributeType.OperationConfig)] |
| | | public class MotionCardOperationConfigBase : OperationConfigBase, IComplexDisplay |
| | | { |
| | | [Category("板卡操作")] |
| | | [Description("板卡操作配置基类集合,依次执行")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | [Editor(typeof(ComplexCollectionEditor<MotionCardOperationConfigBase>), typeof(UITypeEditor))] |
| | | public List<MotionCardOperationSet> OperationCollection { get; set; } = new List<MotionCardOperationSet>(); |
| | | |
| | | public string GetDisplayText() |
| | | { |
| | | return string.Join(" ", OperationCollection.Select(u => u.GetDisplayText())); |
| | | } |
| | | } |
| | | |
| | | public class MotionCardOperationSet : IComplexDisplay |
| | | { |
| | | [Category("IO操作配置")] |
| | | [DisplayName("IO预检查定义集合")] |
| | | [Description("IO预检查定义集合")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | [Editor(typeof(IORefrenceItemCollectionEditor),typeof(UITypeEditor))] |
| | | [Editor(typeof(IORefrenceItemCollectionEditor), typeof(UITypeEditor))] |
| | | public List<IORefrenceItem> PreCheckIOCollection { get; set; } = new List<IORefrenceItem>(); |
| | | [Category("IO操作配置")] |
| | | [Description("超时设置,单位:ms")] |
| | | [DisplayName("IO预检查超时")] |
| | | public int PreCheckIOTimeout { get; set; } = 0; |
| | | |
| | | [Category("IO操作配置")] |
| | | [DisplayName("IO输出定义集合")] |
| | | [Description("IO输出定义集合")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | public List<IORefrenceItem> IOOutputCollection { get; set; } = new List<IORefrenceItem>(); |
| | | |
| | | [Category("IO操作配置")] |
| | | [DisplayName("IO确认定义集合")] |
| | | [Description("IO确认定义集合")] |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | public List<IORefrenceItem> IOConfirmCollection { get; set; } = new List<IORefrenceItem>(); |
| | | [Category("IO操作配置")] |
| | | [Description("超时设置,单位:ms")] |
| | | [DisplayName("IO确认超时")] |
| | | public int IOConfirmTimeout { get; set; } = 0; |
| | | |
| | | [Category("板卡运动配置")] |
| | | [DisplayName("运动配置集合")] |
| | |
| | | [TypeConverter(typeof(CollectionCountConvert))] |
| | | [Editor(typeof(ComplexCollectionEditor<MovingOption>), typeof(UITypeEditor))] |
| | | public List<MovingOption> MovingOps { get; set; } = new List<MovingOption>(); |
| | | [Category("板卡运动配置")] |
| | | [Description("超时设置,单位:ms")] |
| | | [DisplayName("运动超时")] |
| | | public int MovingTimeout { get; set; } = 0; |
| | | |
| | | public string GetDisplayText() |
| | | { |
| | | throw new NotImplementedException(); |
| | | string preCheck = ""; |
| | | PreCheckIOCollection.ForEach(i => |
| | | { |
| | | preCheck += i.GetDisplayText() + " "; |
| | | }); |
| | | if (preCheck != "") |
| | | { |
| | | preCheck = " 预检:" + preCheck; |
| | | } |
| | | |
| | | string output = ""; |
| | | IOOutputCollection.ForEach(i => |
| | | { |
| | | output += i.GetDisplayText() + " "; |
| | | }); |
| | | if (output != "") |
| | | { |
| | | output = " 输出:" + output; |
| | | } |
| | | string confirm = ""; |
| | | IOConfirmCollection.ForEach(i => |
| | | { |
| | | confirm += i.GetDisplayText() + " "; |
| | | }); |
| | | if (confirm != "") |
| | | { |
| | | confirm = " 确认:" + confirm; |
| | | } |
| | | |
| | | string moving = ""; |
| | | MovingOps.ForEach(i => |
| | | { |
| | | moving += i.GetDisplayText() + " "; |
| | | }); |
| | | if (moving != "") |
| | | { |
| | | moving = " 运动:" + moving; |
| | | } |
| | | |
| | | return (preCheck + output + confirm + moving).Trim(); |
| | | } |
| | | } |
| | | |
| | | //[Device("MotionCardOperationConfigCollection", "板卡操作配置基类集合", EnumHelper.DeviceAttributeType.OperationConfig)] |
| | | //public class MotionCardOperationConfigCollection : OperationConfigBase |
| | | //{ |
| | | // [Category("复位操作")] |
| | | // [Description("板卡操作配置基类集合,依次执行")] |
| | | // [TypeConverter(typeof(CollectionCountConvert))] |
| | | // [Editor(typeof(ComplexCollectionEditor<MotionCardOperationConfigBase>), typeof(UITypeEditor))] |
| | | // public List<MotionCardOperationConfigBase> MotionCardOpsCollection { get; set; } = new List<MotionCardOperationConfigBase>(); |
| | | //} |
| | | |
| | | public class IORefrenceItemCollectionEditor : CollectionEditor |
| | | { |
| | |
| | | return form; |
| | | } |
| | | |
| | | //protected override object CreateInstance(Type itemType) |
| | | //{ |
| | | // return base.CreateInstance(itemType); |
| | | //} |
| | | protected override object CreateInstance(Type itemType) |
| | | { |
| | | if (itemType == typeof(IORefrenceItem)) |
| | | { |
| | | IORefrenceItem item = new IORefrenceItem(); |
| | | if ((this.Context.Instance is IOperationConfig opConfig) && !string.IsNullOrWhiteSpace(opConfig.DeviceId)) |
| | | { |
| | | using (var scope = GlobalVar.Container.BeginLifetimeScope()) |
| | | { |
| | | List<IDevice> deviceList = scope.Resolve<List<IDevice>>(); |
| | | |
| | | var device = deviceList.FirstOrDefault(u => u.Id == opConfig.DeviceId); |
| | | |
| | | if (device != null && (device is MotionCardBase motionCard)) |
| | | { |
| | | item.IOItemSource = (motionCard.InitialConfig as MotionCardInitialConfigBase).IODefinitionCollection; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return item; |
| | | } |
| | | |
| | | return base.CreateInstance(itemType); |
| | | } |
| | | |
| | | //protected override object[] GetItems(object editValue) |
| | | //{ |
| | |
| | | |
| | | if (device is MotionCardBase motionCard) |
| | | { |
| | | if (value is IORefrenceItem item) |
| | | if (value is List<IORefrenceItem> items) |
| | | { |
| | | item.IOItemSource = (motionCard.InitialConfig as MotionCardInitialConfigBase).IODefinitionCollection; |
| | | items.ForEach(item => |
| | | { |
| | | item.IOItemSource = (motionCard.InitialConfig as MotionCardInitialConfigBase).IODefinitionCollection; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | |
| | | // base.DestroyInstance(instance);//重要!自动删除组件的设计时代码! |
| | | //} |
| | | } |
| | | |
| | | |
| | | } |