namespace IPLCConnect { public enum PLCProtocol { Modbus, S7, } public sealed class PLCProtocolAttribute:Attribute { public PLCProtocolAttribute(PLCProtocol protocol = PLCProtocol.S7) => Protocol = protocol; public PLCProtocol Protocol { get; } = PLCProtocol.S7; } public interface IPLCConnect:IDisposable { public PLCProtocol Protocol { get; } /// /// 连接状态 /// public bool IsConnected { get; } /// /// IP地址 /// public string IP { get; } /// /// 端口 /// public int Port { get; } /// /// 初始化 /// /// IP地址 /// 端口号 public void Init(string ip, int port); /// /// 读寄存器 /// /// 数据类型 /// 地址 /// public T Read(string addr) where T : unmanaged; /// /// 读取bool /// /// 地址 /// bit序号 /// public bool ReadBit(string addr, byte bitindex); /// /// 写寄存器 /// /// 数据类型 /// 地址 /// 需要写入的值 public void Write(string addr, T value) where T : unmanaged; /// /// 写bool /// /// 地址 /// bit序号 /// 值 public void Writebit(string addr, byte bitindex, bool value); /// /// 连接 /// public void Connect(); /// /// 断开连接 /// public void DisConnect(); /// /// 连接状态改变 /// public event EventHandler StatusChanged; } }