/// <summary> /// Update control time /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CtrlTimer_Tick(object sender, EventArgs e) { if (GlbVars.tempReadTimer.Enabled) { TimeSpan ts = DateTime.Now - GlbVars.ctrlStartTime; this.LblCtrlTimeShow.Invoke(new EventHandler(delegate { LblCtrlTimeShow.Text = String.Format("{0}:{1}:{2}", ts.Hours, ts.Minutes, ts.Seconds); })); } else { this.LblCtrlTimeShow.Invoke(new EventHandler(delegate { LblCtrlTimeShow.Text = "N/A"; })); } float fluc = 0; string flucString = "N/A"; if (GlbVars.GetFluc(GlbVars.tempFlucLen_10min, out fluc)) { flucString = fluc.ToString("0.000"); } else { flucString = "N/A"; } this.LblFlucShow.Invoke(new EventHandler(delegate { LblFlucShow.Text = flucString; })); }
/// <summary> /// Check if the fluctuation is in range /// </summary> /// <param name="count">Count used to calculate fluctuation</param> /// <returns>If in range</returns> public bool CheckFluc(out float temperature) { // Improve: Need remove all uart error judgement? if (GlbVars.uartCom.ReadData(UartProtocol.Commands_t.TempShow, out temperature) != UartProtocol.Errors_t.NoError) { Exception e = new Exception(" Communication command is in error !!!"); throw e; } // Add temperature data into list GlbVars.AddTemperature(temperature); float fluctuation = 0; // If there not enough temperature point to check fluctuation, consider it not in range if (!GlbVars.GetFluc(checkCount, out fluctuation)) { return(false); } // If temperature and fluctuation are both in range, return true if (Math.Abs(temperature - this.tempSetCurrent) < GlbVars.paraValues[(int)GlbVars.Paras_t.TempThr] && fluctuation < GlbVars.paraValues[(int)GlbVars.Paras_t.FlucThr]) { return(true); } return(false); }
private void BntUpdate_Click(object sender, EventArgs e) { // Enter non-timer region to avoid uart conflict GlbVars.EnterNoTimerRegion(); bool noError = true; // Write old parameters to file Data2File.Operation2File(true); // Loop to check and update paramters for (int i = 0; i < GlbVars.paraValues.Length; i++) { float newValue = float.Parse(TxtParas[i].Text); // Update only when current value is different from previous one // Use **abs(x-y) > margin** to compare two inequal float vars if (Math.Abs(newValue - GlbVars.paraValues[i]) > 10e - 5) { // If update fluctuation and temperature threshold, just update the global variables if (i == (int)GlbVars.Paras_t.FlucThr || i == (int)GlbVars.Paras_t.TempThr) { GlbVars.paraValues[i] = newValue; Data2File.AddParaChanged(i); continue; } // For other parameters, send cmd to MCU to update if (GlbVars.uartCom.SendData((UartProtocol.Commands_t)i, newValue) != UartProtocol.Errors_t.NoError) { noError = false; } else { GlbVars.paraValues[i] = newValue; Data2File.AddParaChanged(i); } } } if (noError) { MessageBox.Show("参数更新成功!"); } else { MessageBox.Show("参数更新失败!"); } // Write new paramters to file Data2File.Operation2File(false); // Exit non-timer region GlbVars.ExitNoTimerRegion(); }
private void BntRead_Click(object sender, EventArgs e) { // Enter non-timer region to avoid uart conflict GlbVars.EnterNoTimerRegion(); GlbVars.paraValues = readParas(); for (int i = 0; i < GlbVars.paraValues.Length; i++) { TxtParas[i].Text = GlbVars.paraValues[i].ToString(GlbVars.paraFormat[i]); } // Exit non-timer region GlbVars.ExitNoTimerRegion(); }