/// <summary> /// 查询烟感 /// </summary> /// <param name="strAddr"></param> /// <returns></returns> public ProbeState AskFire(string strAddr) { ProbeState probe = ProbeState.正常; string strFireSend = "IN4"; strAddr = strAddr.PadLeft(2, '0'); strFireSend += strAddr;//地址 strFireSend += "003R000\r\n"; string strRet = serial.SendReceStr(strFireSend, 8, IsWait.CanStop); //txt 发送 接受 //strRet = strFireSend.Substring(0, strFireSend.Length - 1); if (!String.IsNullOrEmpty(strRet) && strRet.Length >= 12) { int index = strRet.IndexOf("IN"); if (strRet.Length - index >= 12) { strRet = strRet.Substring(index, 12); txtLog.TxtWriteStr("Sensor.txt", "Yw Send", strFireSend, false); if (strRet.Length > 0) { txtLog.TxtWriteStr("Sensor.txt", "Yw Rece", strRet, true); } if (strRet.Length >= 12) { string strRetHand = strRet.Substring(0, 3); //IN3 IN301003R000 string strRetAddr = strRet.Substring(3, 2); //01 string strRetOther = strRet.Substring(5, 5); //003R0 if (strRetHand == "IN4" && strRetAddr == strAddr && strRetOther == "003R0" && strRet[11] == '0') { if (strRet[10] == '0') { probe = ProbeState.正常; } else if (strRet[10] == '1') { probe = ProbeState.报警; } } else { probe = ProbeState.通信错误; } } else { probe = ProbeState.通讯; } } } return(probe); }
/// <summary> /// 查询烟感 /// </summary> /// <param name="strAddr"></param> /// <returns></returns> public ProbeState AskFire(string strAddr) { ProbeState probe = ProbeState.正常; string strFireSend = "IN4"; strFireSend += strAddr;//地址 strFireSend += "003R000\r\n"; //txt 发送 string strTxt = strFireSend.Substring(0, strFireSend.Length - 1); txtLog.WriteTxt("Yw.txt", "Send", strTxt, false); string strRet = mainSerial.SendReceStr(strFireSend, 500); //txt 接受 if (strRet.Length > 0) { txtLog.WriteTxt("Yw.txt", "Rece", strRet, false); } if (strRet.Length >= 12) { string strRetHand = strRet.Substring(0, 3); //IN3 IN301003R000 string strRetAddr = strRet.Substring(3, 2); //01 string strRetOther = strRet.Substring(5, 5); //003R0 if (strRetHand == "IN4" && strRetAddr == strAddr && strRetOther == "003R0" && strRet[11] == '0') { if (strRet[10] == '0') { probe = ProbeState.正常; } else if (strRet[10] == '1') { probe = ProbeState.报警; } } else { probe = ProbeState.通信错误; } } else { probe = ProbeState.通讯; } return(probe); }
protected Probe() { _enabled = false; _state = ProbeState.Stopped; _storeData = true; _startStopTimes = new List <Tuple <bool, DateTime> >(); _successfulHealthTestTimes = new List <DateTime>(); _maxChartDataCount = 10; _chartData = new List <ChartDataPoint>(_maxChartDataCount + 1); _powerConnectionChanged = async(sender, connected) => { if (connected) { // ask the probe to start processing its data try { SensusServiceHelper.Get().Logger.Log("AC power connected. Initiating data processing within probe.", LoggingLevel.Normal, GetType()); _processDataCanceller = new CancellationTokenSource(); await ProcessDataAsync(_processDataCanceller.Token); SensusServiceHelper.Get().Logger.Log("Probe data processing complete.", LoggingLevel.Normal, GetType()); } catch (OperationCanceledException) { // don't report task cancellation exceptions. these are expected whenever the user unplugs the device while processing data. SensusServiceHelper.Get().Logger.Log("Data processing task was cancelled.", LoggingLevel.Normal, GetType()); } catch (Exception ex) { // the data processing actually failed prior to cancellation. this should not happen, so report it. SensusException.Report("Non-cancellation exception while processing probe data: " + ex.Message, ex); } } else { // cancel any previous attempt to process data _processDataCanceller?.Cancel(); } }; }
public async Task StopAsync() { lock (_stateLocker) { if (_state == ProbeState.Stopped || _state == ProbeState.Stopping) { SensusServiceHelper.Get().Logger.Log("Attempted to stop probe, but it was already in state " + _state + ".", LoggingLevel.Normal, GetType()); return; } else { _state = ProbeState.Stopping; } } try { await ProtectedStopAsync(); } finally { lock (_startStopTimes) { _startStopTimes.Add(new Tuple <bool, DateTime>(false, DateTime.Now)); _startStopTimes.RemoveAll(t => t.Item2 < Protocol.ParticipationHorizon); } // unhook from the AC charge event signal -- remove handler to AC broadcast receiver SensusContext.Current.PowerConnectionChangeListener.PowerConnectionChanged -= _powerConnectionChanged; lock (_stateLocker) { _state = ProbeState.Stopped; } } }
public async Task StartAsync() { lock (_stateLocker) { // don't attempt to start the probe if it is not enabled. this can happen, e.g., when remote protocol // updates disable the probe and the probe is subsequently restarted to take on the update values. if (Enabled && _state == ProbeState.Stopped) { _state = ProbeState.Initializing; } else { SensusServiceHelper.Get().Logger.Log("Attempted to start probe, but it was already in state " + _state + " with " + nameof(Enabled) + "=" + Enabled + ".", LoggingLevel.Normal, GetType()); return; } } try { await InitializeAsync(); lock (_stateLocker) { _state = ProbeState.Starting; } // start data rate calculators _rawRateCalculator.Start(); _storageRateCalculator.Start(); _uiUpdateRateCalculator.Start(); await ProtectedStartAsync(); lock (_stateLocker) { _state = ProbeState.Running; } lock (_startStopTimes) { _startStopTimes.Add(new Tuple <bool, DateTime>(true, DateTime.Now)); _startStopTimes.RemoveAll(t => t.Item2 < Protocol.ParticipationHorizon); } } catch (Exception startException) { if (startException is NotSupportedException) { Enabled = false; } // stop probe to clean up any inconsistent state information try { await StopAsync(); } catch (Exception stopException) { SensusServiceHelper.Get().Logger.Log("Failed to stop probe after failing to start it: " + stopException.Message, LoggingLevel.Normal, GetType()); } string message = "Sensus failed to start probe \"" + GetType().Name + "\": " + startException.Message; SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType()); await SensusServiceHelper.Get().FlashNotificationAsync(message); throw startException; } }