using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DoAn.PLC { public class Host { Dictionary _lstTagServer; public Host() { this._lstTagServer = new Dictionary(); } /// /// 创建一个PLC服务 /// /// /// public TagServer CreateTagServer(string hostIp) { if (GetTagServerByIp(hostIp) != null) return null; // 用带IP地址创建对象 TagServer tagServer = new TagServer(hostIp); AddTagServer(hostIp, tagServer); return tagServer; } private void AddTagServer(string hostIp,TagServer tagServer) { this._lstTagServer.Add(hostIp, tagServer); } /// /// 根据IP返回一个PLC服务 /// /// /// public TagServer GetTagServerByIp(string hostIp) { return this._lstTagServer.ContainsKey(hostIp) ? this._lstTagServer[hostIp] : null; } /// /// 关闭所有 /// public void CloseConnect() { foreach (KeyValuePair item in this._lstTagServer) { item.Value.DisconnectPLC(); } } } }