/// <summary>
 /// 载入一个设备
 /// </summary>
 /// <param name="interrupt_id">设备中断号</param>
 /// <param name="device">设备实例</param>
 public override void LoadDevice(int interrupt_id, IOBase device)
 {
     if (null == device)
     {
         if (InterruptTables.TryGetValue(interrupt_id, out string label))
         {
             if (DeviceTables.TryGetValue(label, out DeviceTable table))
             {
                 table.RunState = true;
             }
             else
             {
                 ControlInterrupt.Interrupt(DeviceException_Type.Not_Exist, -1, null);
             }
         }
         else
         {
             ControlInterrupt.Interrupt(DeviceException_Type.Not_Exist, -1, null);
         }
     }
     else
     {
         AddDevice(interrupt_id, device);
     }
 }
 /// <summary>
 /// 设置新的设备中断号
 /// </summary>
 /// <param name="device_id">设备号</param>
 /// <param name="new_interrupt">中断号</param>
 public override void SetInterrupt(int device_id, int new_interrupt)
 {
     if (DeviceIDTables.TryGetValue(device_id, out string label))
     {
         if (DeviceTables.TryGetValue(label, out DeviceTable device))
         {
             InterruptTables.Remove(device.InterruptID);
             FreeInterruptID((ushort)device.InterruptID);
             if (SetInterruptID((ushort)new_interrupt))
             {
                 device.InterruptID = new_interrupt;
             }
             else
             {
                 ControlInterrupt.Interrupt(DeviceException_Type.Interrupt_Error, device_id, device.DevicePointer);
             }
         }
         else
         {
             ControlInterrupt.Interrupt(DeviceException_Type.Interrupt_Error, device_id, null);
         }
     }
     else
     {
         ControlInterrupt.Interrupt(DeviceException_Type.Interrupt_Error, device_id, null);
     }
 }
        /// <summary>
        /// 添加一个设备
        /// </summary>
        /// <param name="interrupt_id">设备中断号</param>
        /// <param name="device">设备实例</param>
        public override void AddDevice(int interrupt_id, IOBase device)
        {
            if (!DeviceTables.ContainsKey(device.Property.DeviceID))
            {
                int interrupt = -1 == interrupt_id?GetInterruptID() : interrupt_id;

                InterruptTables.Add(interrupt, device.Property.DeviceID);
                DeviceTables.Add(device.Property.DeviceID, new DeviceTable(DeviceIDTables.Count, interrupt, new List <string>(), device));
                DeviceIDTables.Add(DeviceIDTables.Count, device.Property.DeviceID);
            }
            else
            {
                //无设备ID则用-1
                ControlInterrupt.Interrupt(DeviceException_Type.Add_Failed, -1, device);
            }
        }
 /// <summary>
 /// 激活设备
 /// </summary>
 /// <param name="interrupt_id">设备中断号</param>
 public override void DeviceActive(int interrupt_id)
 {
     if (InterruptTables.TryGetValue(interrupt_id, out string label))
     {
         if (DeviceTables.TryGetValue(label, out DeviceTable table))
         {
             if (table.RunState)
             {
                 table.DevicePointer.Run();
             }
             else
             {
                 ControlInterrupt.Interrupt(DeviceException_Type.Not_Exist, table.Device_ID, table.DevicePointer);
             }
         }
     }
 }
 /// <summary>
 /// 读设备
 /// </summary>
 /// <param name="interrupt_id">设备中断号</param>
 /// <returns>返回数据</returns>
 public override byte[] DeviceRead(int interrupt_id)
 {
     if (InterruptTables.TryGetValue(interrupt_id, out string label))
     {
         if (DeviceTables.TryGetValue(label, out DeviceTable table))
         {
             if (table.RunState)
             {
                 return(table.DevicePointer.Get());
             }
             else
             {
                 ControlInterrupt.Interrupt(DeviceException_Type.Not_Exist, table.Device_ID, table.DevicePointer);
             }
         }
     }
     return(null);
 }