IOManage.cs 1.5 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class IOManage : IO_Interface
    {
        IO_Interface iom;
        public IOManage(string ip,string iomodule="") {
            if (string.IsNullOrWhiteSpace(iomodule))
                iom = new KND_IO(ip);
            else
                iom = new NiRenIO(ip);
            iom.DI_Changed_Event += Iom_DI_Changed_Event;
        }

        private void Iom_DI_Changed_Event(Status[] sta)
        {
            DI_Changed_Event?.Invoke(sta);
        }

        /// <summary>
        /// 自动读取DI委托
        /// </summary>
        /// <param name="sta">状态</param>
        public delegate void DI_Changed(Status[] sta);

        public string IP { get=>iom.IP; set=>iom.IP=value; }

        public bool IsConn { get => iom.IsConn;}

        public int Port { get => iom.Port; set => iom.Port = value; }

        public event DI_Changed DI_Changed_Event;

        public void Close()
        {
            iom.Close();
        }

        public bool Connect()
        {
            return iom.Connect();
        }

        public bool ReadDI(Addr add, out Status sta)
        {
            return iom.ReadDI(add, out sta);
        }

        public bool ReadDO(Addr add, out Status sta)
        {
            return iom.ReadDO(add, out sta);
        }

        public bool WriteDO(int add, Status sta)
        {
            return iom.WriteDO(add, sta);
        }
    }
}