/// <summary> /// 查询状态 /// </summary> /// <param name="Ip"></param> /// <param name="Port"></param> /// <param name="SN"></param> /// <returns></returns> private void DoorSatus(string InSN, string OutSN) { EventHandler <DoorStateEventArgs> newState = NewState; if (newState != null) { try { wgMjControllerRunInformation conRunInfo = null; int InStatus = wgWatching.CheckControllerCommStatus(Int32.Parse(InSN), ref conRunInfo); newState(this, new DoorStateEventArgs(InStatus, Int32.Parse(InSN))); int OutStatus = wgWatching.CheckControllerCommStatus(Int32.Parse(OutSN), ref conRunInfo); newState(this, new DoorStateEventArgs(OutStatus, Int32.Parse(OutSN))); } catch (Exception ex) { _Log.logError.Error("Query Door State Error", ex); } } }
/// <summary> /// 定时读取 门禁控制器状态 /// </summary> private void updateControllerStatus() { try { if (watching != null) { int iCount = listWg.Count; for (int iIndex = 0; iIndex < iCount; iIndex++) { if (listWg[iIndex] != null) { // 门的类型 大门 或 工具柜门 WgDoorType doorOrBox = listWg[iIndex].DoorOrBoxDoor; #region 网络通信 状态 及校时 //网络连接错误 30S 后继续连接 bool blAgain = false; if (listWg[iIndex].StateOfNet == CommuniState.未连接) { TimeSpan span = DateTime.Now - listWg[iIndex].TimeErrNet; if (span.TotalSeconds > 30) { blAgain = true; lock (listWg) { listWg[iIndex].TimeErrNet = DateTime.Now; } } } if (listWg[iIndex].StateOfNet == CommuniState.已连接 || blAgain) { wgMjControllerRunInformation conRunInfo = null; int commStatus; int iSn = (int)listWg[iIndex].IntSn; commStatus = watching.CheckControllerCommStatus(iSn, ref conRunInfo); if (commStatus == -1) { if (listWg[iIndex].StateOfNet != CommuniState.未连接) { lock (listWg) { listWg[iIndex].StateOfNet = CommuniState.未连接; listWg[iIndex].TimeErrNet = DateTime.Now; } //通信 异常信息 及记录 NetErrInfoAndRecord(doorOrBox, iIndex, ErrorContent.通信异常.ToString()); #region //string strErrType = DoorOrBoxDoor.ToString(); //string strWgName = "";//微耕控制器名称 //if (DoorOrBoxDoor == EventType.工具柜) //{ // strWgName = listWg[iIndex].StrNameOfWg; //} //string strContent = ErrorContent.通信异常.ToString(); ////异常记录 //commonCls.NewErrRecord(strErrType, strWgName, strContent, ""); //if (NewAlarmShowEvent != null) //{ // NewAlarmShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strWgName, strContent, "", "", DateTime.Now)); //} #endregion } } else if (commStatus == 1) { if (listWg[iIndex].StateOfNet != CommuniState.已连接) { lock (listWg) { listWg[iIndex].StateOfNet = CommuniState.已连接; } //通信恢复 正常 记录及主界面显示 NetErrInfoAndRecord(doorOrBox, iIndex, ErrorContent.通信恢复正常.ToString()); #region 通信恢复 正常 记录及主界面显示 //string strErrType = DoorOrBoxDoor.ToString(); //string strWgName = "";//微耕控制器名称 //if (DoorOrBoxDoor == EventType.工具柜) //{ // strWgName = listWg[iIndex].StrNameOfWg; //} //string strContent = ErrorContent.通信恢复正常.ToString(); //commonCls.NewErrRecord(strErrType, strWgName, strContent, ""); //if (NewAlarmShowEvent != null) //{ // NewAlarmShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strWgName, strContent, "", "", DateTime.Now)); //} #endregion #region 校时 DateTime time = conRunInfo.dtNow; TimeSpan ts = DateTime.Now - time;//记录历史温湿度数据间隔 if (ts.TotalSeconds >= 59 || ts.TotalSeconds <= -59) { wgController.AdjustTimeIP(DateTime.Now); } #endregion } } } #endregion #region 门状态 if (listWg[iIndex].StateOfNet == CommuniState.已连接) { if (listWg[iIndex].listDoor != null) { string strArea = listWg[iIndex].StrArea; int iCountDoor = listWg[iIndex].listDoor.Count; for (int iIndexDoor = 0; iIndexDoor < iCountDoor; iIndexDoor++) { //门名称 string strDoorName = ""; if (listWg[iIndex].listDoor[iIndexDoor].StrDoorName != null) { strDoorName = listWg[iIndex].listDoor[iIndexDoor].StrDoorName; } int iDoorIndex = listWg[iIndex].listDoor[iIndexDoor].IntDoorIndex; DoorsState getDoorState = listWg[iIndex].GetDoorState(iDoorIndex); if (listWg[iIndex].listDoor[iIndexDoor].StateOfDoor != getDoorState) { lock (listWg) { listWg[iIndex].listDoor[iIndexDoor].StateOfDoor = getDoorState; } if (getDoorState == DoorsState.开门) { lock (listWg) { listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor = DateTime.Now; } if (listWg[iIndex].listDoor[iIndexDoor].IsOfRfid == DeviceUsing.启用) { clsRfidRead.strOpenUser = listWg[iIndex].listDoor[iIndexDoor].StrUser; } //开门 string strOpenType = listWg[iIndex].listDoor[iIndexDoor].StrOpenType; string strGroup = listWg[iIndex].listDoor[iIndexDoor].StrGroup; string strUser = listWg[iIndex].listDoor[iIndexDoor].StrUser; OnOffDoorInfoRecord(doorOrBox, strDoorName, DoorsState.开门, strOpenType, strGroup, strUser, DateTime.Now, strArea); #region //string strOpenType = listWg[iIndex].listDoor[iIndexDoor].StrOpenType; //string strGroup = listWg[iIndex].listDoor[iIndexDoor].StrGroup; //string strUser = listWg[iIndex].listDoor[iIndexDoor].StrUser; //if (DoorOrBoxDoor == EventType.门禁) //{ // commonCls.NewDoorInOut(DoorsState.开门, strOpenType, strDoorName, strGroup, strUser, ""); //} //else if (DoorOrBoxDoor == EventType.工具柜) //{ //} //if (NewEventShowEvent != null) //{ // NewEventShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strDoorName, DoorsState.开门.ToString(), strUser, strOpenType, DateTime.Now)); //} #endregion } else if (getDoorState == DoorsState.关门) { lock (listWg) { listWg[iIndex].listDoor[iIndexDoor].ClearOpenInfo(); } if (listWg[iIndex].listDoor[iIndexDoor].IsOfRfid == DeviceUsing.启用) { clsRfidRead.strOpenUser = ""; } //关门 DateTime timeOpen = listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor; OnOffDoorInfoRecord(doorOrBox, strDoorName, DoorsState.关门, "", "", "", timeOpen, strArea); #region //TimeSpan timeSpan = DateTime.Now - listWg[iIndex].listDoor[iIndexDoor].TimeOpenDoor; //string strSpan = clsCommon.CalculateTime(timeSpan); //if (DoorOrBoxDoor == EventType.门禁) //{ // commonCls.NewDoorInOut(DoorsState.关门, "", "", "", "", strSpan); //} //else if (DoorOrBoxDoor == EventType.工具柜) //{ //} //if (NewEventShowEvent != null) //{ // NewEventShowEvent(new NewEventEventArgs(DoorOrBoxDoor, strDoorName, DoorsState.开门.ToString(), "", "", DateTime.Now)); //} #endregion } } } } } #endregion } } } } catch (Exception ex) { if (frmMain.blDebug) { MessageUtil.ShowTips(ex.Message); } } }
/// <summary> /// 更新 门禁控制器状态 /// </summary> public void updateControllerStatus() { if (watching != null) { int iCount = listWg.Count; for (int iIndex = 0; iIndex < iCount; iIndex++) { if (listWg[iIndex] != null) { #region 门禁控制器 实时状态 bool blAskWgState = false; if (listWg[iIndex].DoorNet == CommuniState.已连接) { blAskWgState = true; } else if (listWg[iIndex].DoorNet == CommuniState.已断开) { TimeSpan ts = DateTime.Now - listWg[iIndex].TimeLastAsk; if (ts.TotalSeconds >= 10) { blAskWgState = true; listWg[iIndex].TimeLastAsk = DateTime.Now; } } if (blAskWgState) { wgMjControllerRunInformation conRunInfo = null; int commStatus; int iSn = (int)listWg[iIndex].IntSn; commStatus = watching.CheckControllerCommStatus(iSn, ref conRunInfo); if (commStatus == -1) { listWg[iIndex].IntNetError++; ////实时监控 3次 仍未通信上, 则提示未连接 if (listWg[iIndex].DoorNet != CommuniState.已断开) { if (listWg[iIndex].IntNetError >= 3) { listWg[iIndex].IntNetError = 0; lock (listWg) { listWg[iIndex].DoorNet = CommuniState.已断开; } NewAlarmEvent(AlarmContent.通信异常.ToString(), false, ""); } } } else if (commStatus == 1) { listWg[iIndex].IntNetError = 0; if (listWg[iIndex].DoorNet == CommuniState.已断开) { lock (listWg) { listWg[iIndex].DoorNet = CommuniState.已连接; } NewAlarmEvent(AlarmContent.通信恢复正常.ToString(), false, ""); } if (listWg[iIndex].DoorNet != CommuniState.已连接) { lock (listWg) { listWg[iIndex].DoorNet = CommuniState.已连接; } } //校时 DateTime time = conRunInfo.dtNow; TimeSpan ts = DateTime.Now - time;//记录历史温湿度数据间隔 if (ts.TotalSeconds >= 59 || ts.TotalSeconds <= -59) { wgController.AdjustTimeIP(DateTime.Now); } } } #endregion #region 门状态 开 关 if (listWg[iIndex].DoorNet == CommuniState.已连接) { BigDoorStateRecord(iIndex, DoorNo.门1); if (listWg[iIndex].WgDoorCount == DoorCount.双门) { BigDoorStateRecord(iIndex, DoorNo.门2); } } #endregion } } } //try //{ //} //catch (Exception ex) //{ // if (frmMain.blDebug) // MessageUtil.ShowTips(ex.Message); //} }