123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- namespace Aitex.Core.RT.IOCore
- {
- public delegate void SetValue<T>(int index, T Value);
- public delegate T GetValue<T>(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<T>
- {
- protected string name;
- protected string addr;
- protected int index;
- protected T[] values;
- protected SetValue<T> setter = null;
- protected GetValue<T> 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<bool>
- {
- private IOAccessor<bool> rawAccessor;
- public bool RawData
- {
- get
- {
- return rawAccessor.Value;
- }
- /// <summary>
- /// 修改数字量输入值
- ///
- /// 注意:
- /// 1. 此处修改的数字量输入值在调用IOManager.Update_Input方法后将被覆写
- /// 2. 只能修改索引号为500之后定义的软件DI信号点(规定0~499为硬件输入信号点区间)
- /// </summary>
- /// <param name="index">DI索引号</param>
- /// <param name="value"></param>
- set
- {
- rawAccessor.Value = value;
- }
- }
- public DIAccessor(string name, int index, bool[] values, bool[] raws)
- :base(name, index, values)
- {
- rawAccessor = new IOAccessor<bool>(name, index, raws);
- }
- }
- public class DOAccessor : IOAccessor<bool>
- {
- 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<float>
- {
- public AIAccessor(string name, int index, float[] values)
- :base(name,index, values)
- {
- }
- }
- public class AOAccessor : IOAccessor<float>
- {
- public AOAccessor(string name, int index, float[] values)
- :base(name,index, values)
- {
- }
- }
-
- }
|