using System; using System.Collections.Generic; using System.ComponentModel; using TeamAAS.Global.Devices; using Newtonsoft.Json; namespace TeamAAS.Motion.Models { /// 单台运动/IO 设备的配置(持久化为 Config\MotionDevices.json)。 [Serializable] public class MotionDeviceConfig { /// 设备名称(唯一,状态栏/绑定树显示用)。 [DisplayName("设备名称")] [Description("设备唯一名称")] public string Name { get; set; } = "运动卡1"; /// 设备适配器唯一标识(如 "Simulated(仿真)", "Leadshine", "Googol")决定实例化哪个品牌适配器 [DisplayName("设备类型")] [Description("填写适配器注册的唯一字符串键值")] public string AdapterKey { get; set; } = "Simulated"; // 默认仿真 /// 板卡号/设备号(品牌适配器解释,如卡号 0)。 [DisplayName("板卡号")] [Description("品牌适配器的板卡/设备索引")] public int BoardIndex { get; set; } = 0; /// 轴数量(有 Axes 时等于配置条数)。不要在 setter 里生成默认轴,反序列化会先写 AxisCount 再追加 Axes,造成列表重复。 [DisplayName("轴数量")] public int AxisCount { get => Axes != null && Axes.Count > 0 ? Axes.Count : _axisCount; set => _axisCount = Math.Max(1, value); } private int _axisCount = 4; /// 逻辑轴列表(实轴 / 虚轴 / 组合轴)。为空时按 AxisCount 生成默认 X/Y/Z/R。 [Browsable(false)] [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)] public List Axes { get; set; } = new List(); /// 本地端子板 DI 点数。 [DisplayName("本地 DI 点数")] public int LocalInputCount { get; set; } = 16; /// 本地端子板 DO 点数。 [DisplayName("本地 DO 点数")] public int LocalOutputCount { get; set; } = 16; /// EtherCAT 扩展 DI 点数(无硬件信息时用)。 [DisplayName("EtherCAT DI 点数")] public int InputCount { get; set; } = 16; /// EtherCAT 扩展 DO 点数(无硬件信息时用)。 [DisplayName("EtherCAT DO 点数")] public int OutputCount { get; set; } = 16; /// 连接参数。汇川卡填设备配置 XML 路径,可用 | 或 ; 分隔系统配置,例如:ENI.xml|System.xml [DisplayName("连接参数")] [Description("IP / 串口 / EtherCAT 配置等,由品牌适配器解释")] public string ConnectionString { get; set; } = ""; /// 总急停输入点,-1 表示不启用。 [Browsable(false)] public int EstopDiIndex { get; set; } = -1; [Browsable(false)] public MotionIoBank EstopDiBank { get; set; } = MotionIoBank.Local; /// true=DI 为 1 时急停有效(常开);false=DI 为 0 时有效(常闭)。 [Browsable(false)] public bool EstopActiveHigh { get; set; } = true; /// 总停止输入点,-1 表示不启用。 [Browsable(false)] public int StopDiIndex { get; set; } = -1; [Browsable(false)] public MotionIoBank StopDiBank { get; set; } = MotionIoBank.Local; /// true=DI 为 1 时停止有效。 [Browsable(false)] public bool StopActiveHigh { get; set; } = true; } }