using System; using System.Collections.Generic; using System.Diagnostics; namespace Aitex.Core.RT.IOCore { public delegate void SetValue(int index, T Value); public delegate T GetValue(int index); public enum IOType { DI, DO, AI, AO, } public class CustomIOName { public const string Shutter = "CustomIO_Shutter"; public const string Spindle = "CustomIO_Spindle"; public const string Bath1 = "CustomIO_Bath1"; public const string Bath2 = "CustomIO_Bath2"; public const string Bath3 = "CustomIO_Bath3"; public const string Bath4 = "CustomIO_Bath4"; public const string LineHeaterCh1 = "CustomIO_LineHeaterCh1"; public const string LineHeaterCh2 = "CustomIO_LineHeaterCh2"; public const string LineHeaterCh3 = "CustomIO_LineHeaterCh3"; public const string LineHeaterCh4 = "CustomIO_LineHeaterCh4"; public const string LineHeaterCh5 = "CustomIO_LineHeaterCh5"; public const string LineHeaterCh6 = "CustomIO_LineHeaterCh6"; public const string LineHeaterCh7 = "CustomIO_LineHeaterCh7"; public const string LineHeaterCh8 = "CustomIO_LineHeaterCh8"; public const string RobotX = "CustomIO_RobotX"; public const string RobotZ = "CustomIO_RobotZ"; public const string PLCStatus = "CustomIO_PLCStatus"; public const string Tv = "CustomIO_TV"; } public class IOAccessor { protected string name; protected string addr; protected int index; protected T[] values; protected SetValue setter = null; protected GetValue getter = null; public T Value { get { return getter(index); } set { setter(index, value); } } public string Name { get { return name; } } public int Index { get { return index; } } public string Addr { get { return addr; } } public string StringIndex { get { return name.Substring(0, 2) + "-" + index.ToString(); } } public int IoTableIndex { get; set; } public IOAccessor(string name, int index, T[] values) { this.name = name; this.index = index; this.values = values; getter = GetValue; setter = SetValue; } private T GetValue(int index) { Debug.Assert(values!= null && index >= 0 && index < values.Length); return values[index]; } private void SetValue(int index, T value) { Debug.Assert(values != null && index >= 0 && index < values.Length); values[index] = value; } } public class DIAccessor : IOAccessor { private IOAccessor rawAccessor; public bool RawData { get { return rawAccessor.Value; } /// /// 修改数字量输入值 /// /// 注意: /// 1. 此处修改的数字量输入值在调用IOManager.Update_Input方法后将被覆写 /// 2. 只能修改索引号为500之后定义的软件DI信号点(规定0~499为硬件输入信号点区间) /// /// DI索引号 /// set { rawAccessor.Value = value; } } public DIAccessor(string name, int index, bool[] values, bool[] raws) :base(name, index, values) { rawAccessor = new IOAccessor(name, index, raws); } } public class DOAccessor : IOAccessor { public DOAccessor(string name, int index, bool[] values) :base(name,index, values) { setter = SetValueSafe; } public bool SetValue(bool value, out string reason) { if (IO.CanSetDO(name, value, out reason)) { values[index] = value; return true; } return false; } public bool Check(bool value, out string reason) { return IO.CanSetDO(name, value, out reason); } private void SetValueSafe(int index, bool value) { string reason; if (IO.CanSetDO(name, value, out reason)) { values[index] = value; } } } public class AIAccessor : IOAccessor { public AIAccessor(string name, int index, float[] values) :base(name,index, values) { } } public class AOAccessor : IOAccessor { public AOAccessor(string name, int index, float[] values) :base(name,index, values) { } } }