} = 3; // #region 客户端管理器初始化 public void Initialize() { // 导入client string path = Path.Combine(PathManager.Instance.GetSettingsPath(), ClientConfigFileName); if (File.Exists(path)) { LoadClientFromXmlFile(path); } else { _cmmSvrConfigs = new List <CmmServerConfig>(); } // 循环初始化client foreach (var config in CmmSvrConfigs) { CmmClient client = new CmmClient(config); client.IsActived = true; //client.InitClient(); // // 更新UI界面 ClientUICommon.AddCmmToView(config, client.State); _cmmClients.Add(client); } // 设置心跳信号 PlcClient.Instance.DisconnectEvent += Plc_DisconnectEvent; PlcClient.Instance.ReconnectEvent += Plc_ReconnectEvent; _heartbeatTimer.Start(); }
/// <summary> /// 添加客户端 /// </summary> /// <param name="csConf"></param> /// <returns>返回false表示客户端已存在,返回true添加成功</returns> public bool AddClient(CmmServerConfig csConf) { // 判断机器是否已经存在 if (_cmmSvrConfigs.Where(cl => cl.HostIPAddress.Equals(csConf.HostIPAddress)).Count() == 0 && _cmmSvrConfigs.Where(cl => cl.ServerID == csConf.ServerID).Count() == 0) { _cmmSvrConfigs.Add(csConf); // 添加机器配置信息 CmmClient client = new CmmClient(csConf); client.IsActived = true; //client.InitClient(); // 添加client时不做初始化 _cmmClients.Add(client); // ClientUICommon.AddCmmToView(csConf, client.State); return(true); } return(false); }