/**计时器触发响应函数 * 轮询操作 * 定时器自动重启 * **/ private void ReceiveTimerEventHandler(object sender, ElapsedEventArgs e) { if (PortBll == null || Port == null) { return; } if (CommunicateFlage == PortCommunicationState.OutOfCommunicate) { CommunicateFlage = PortCommunicationState.InCommunicate; } else { return; } mrEvent.Reset(); //端口连接 PortConnect(); //判断端口状态是否改变,并在改变时抛出告警,改变标志位。 CheckPortStateChang(); //如果端口是连接的,就去轮询设备 if (PortBll.ThisConnect) { for (short ListID = 0; ListID < DeviceList.Count; ListID++) { if (DeviceList[ListID].Device.RecoverState)//当前设备状态为--连接许可,执行以下代码 { try { COMMUNICATERESULT ret = GetOneDeviceData(ListID); //读取一个设备的数据,并返回读取结果 CheckOneDeviceStateChange(ListID, ret); //判断该设备是否 通讯成功 } catch (Exception ee) { string jj = ee.ToString(); } } else { CountAdd_SetRecoverState(ListID); } } } else { SetAllDeviceToCommFail(); } mrEvent.Set(); CommunicateFlage = PortCommunicationState.OutOfCommunicate; }
//强制终止 读取数据 函数 时候,需要恢复 通讯标志位 public void ReCommunication() { CommunicateFlage = PortCommunicationState.OutOfCommunicate; }