Ejemplo n.º 1
0
        private void LogShow_Load(object sender, EventArgs e)
        {
            Data2File.CheckDirs();

            string[] filenames = Directory.GetFiles(Data2File.GetOperFolder());
            foreach (string filename in filenames)
            {
                LstLogs.Items.Add(Name2Time(Path.GetFileNameWithoutExtension(filename)));
            }
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        private void BntRunAuto_Click(object sender, EventArgs e)
        {
            // runOrStop, true for run, false for stop
            if (runOrStop)
            {
                // Change the button to Stop function
                this.BntRunAuto.Text = "终止";

                // Disable manual menu to avoid
                this.MenuManual.Enabled  = false;
                this.MenuParaSet.Enabled = false;
                this.MenuComSet.Enabled  = false;

                // Init auto control
                float initTemp     = float.Parse(TxtInitTemp.Text);
                float intervalTemp = float.Parse(TxtIntervalTemp.Text);
                autoStep = new StepControl(initTemp, intervalTemp, intervalTemp > 0);

                // Record the start time
                GlbVars.ctrlStartTime = DateTime.Now;
                // Run
                blinkTimer.Enabled = true;
                autoStep.ThisTurn();
                GlbVars.tempReadTimer.Enabled = true;
            }
            else
            {
                // Change the button to Stop function
                this.BntRunAuto.Text = "运行";

                // Enable all menus
                this.MenuManual.Enabled  = true;
                this.MenuParaSet.Enabled = true;
                this.MenuComSet.Enabled  = true;

                // Stop timer
                GlbVars.tempReadTimer.Enabled = false;
                blinkTimer.Enabled            = false;

                // Fix flucShow to read and show
                PicFlucShow.BackColor = Color.Red;
                PicFlucShow.Visible   = true;

                // Finish the temperature data file
                Data2File.FinishTempFile();
            }

            runOrStop = !runOrStop;
        }
Ejemplo n.º 4
0
        private void LstLogs_DoubleClick(object sender, EventArgs e)
        {
            string selected = LstLogs.SelectedItem as string;

            if (selected == null || selected == "")
            {
                return;
            }

            using (StreamReader sr = new StreamReader
                                         (Data2File.GetOperFolder() + "\\" + Time2Name(selected) + ".log"))
            {
                TxtLog.Text = sr.ReadToEnd();
            }
        }
Ejemplo n.º 5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Check and create folders for data saving
            Data2File.CheckDirs();

            #region Load configuration .ini file
            // If there is no config file, create one and write default value to it
            if (!File.Exists(configFilePath))
            {
                IniReadWrite.INIWriteValue(configFilePath, configSec, "COM", "COM1");
                IniReadWrite.INIWriteValue(configFilePath, configSec, "TempThr", "0.01");
                IniReadWrite.INIWriteValue(configFilePath, configSec, "FlucThr", "0.01");
                IniReadWrite.INIWriteValue(configFilePath, configSec, "ReadInterval", "1000");
            }

            // Get COM port and set it
            GlbVars.uartCom =
                new UartProtocol(IniReadWrite.INIGetStringValue(configFilePath, configSec, "COM", "COM1"));
            this.StaCom.Text = GlbVars.portName;

            // Get temperature and fluctuation threshold
            GlbVars.paraValues[(int)GlbVars.Paras_t.TempThr] =
                float.Parse(IniReadWrite.INIGetStringValue(configFilePath, configSec, "TempThr", "0.01"));

            GlbVars.paraValues[(int)GlbVars.Paras_t.FlucThr] =
                float.Parse(IniReadWrite.INIGetStringValue(configFilePath, configSec, "FlucThr", "0.01"));

            // Get read timer.interval
            GlbVars.readTempInterval =
                int.Parse(IniReadWrite.INIGetStringValue(configFilePath, configSec, "ReadInterval", "1000"));
            #endregion

            // Init check timer, use readTempTimer to replace
            GlbVars.tempReadTimer.Interval = GlbVars.readTempInterval;
            GlbVars.tempReadTimer.Elapsed += CheckTimer_Tick;

            // Init blink timer
            blinkTimer.Interval = 1000;
            blinkTimer.Elapsed += BlinkTimer_Elapsed;
        }
Ejemplo n.º 6
0
        private void BntRun_Click(object sender, EventArgs e)
        {
            // runOrStop, true for run, false for stop
            if (runOrStop)
            {
                // Change the button to Stop function
                this.BntRun.Text = "终止";

                // Init auto control
                float initTemp     = float.Parse(TxtInitTemp.Text);
                float intervalTemp = float.Parse(TxtIntervalTemp.Text);
                autoStep = new StepControl(initTemp, intervalTemp, intervalTemp > 0);

                // Record the start time
                GlbVars.ctrlStartTime = DateTime.Now;
                // Run
                blinkTimer.Enabled = true;
                autoStep.ThisTurn();
                GlbVars.tempReadTimer.Enabled = true;
            }
            else
            {
                // Change the button to Stop function
                this.BntRun.Text = "运行";

                // Stop timer
                GlbVars.tempReadTimer.Enabled = false;
                blinkTimer.Enabled            = false;

                // Fix Blink to visible
                BlinkBlink.Visible = true;

                // Finish the temperature data file
                Data2File.FinishTempFile();
            }

            runOrStop = !runOrStop;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Timer to check if this turn of run is over
        /// </summary>
        private void CheckTimer_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            float temperature = 0;
            bool  steady      = autoStep.CheckFluc(out temperature);

            // Update UI
            this.Invoke(new EventHandler(delegate
            {
                // Update temperature show
                this.LblTempShowAuto.Text = temperature.ToString("0.000 ℃");
                // Save temperature data
                Data2File.Temp2File(temperature);

                // Update fluc flag
                if (steady)
                {
                    this.PicFlucShow.BackColor = Color.Green;
                }
                else
                {
                    this.PicFlucShow.BackColor = Color.Red;
                }
            }));

            // If steady, inform conductivity measurement equipment
            if (steady)
            {
                // Create a critical region
                GlbVars.tempReadTimer.Enabled = false;
                autoStep.InformCondMeas();
                GlbVars.tempReadTimer.Enabled = true;

                int remainTimes = int.Parse(TxtTimes.Text);

                // Remain times dcrease 1
                remainTimes--;
                this.Invoke(new EventHandler(delegate
                {
                    this.TxtTimes.Text = remainTimes.ToString();
                }));

                // If there no remain times, finish all test
                if (remainTimes == 0)
                {
                    // Game over
                    GlbVars.tempReadTimer.Enabled = false;
                    MessageBox.Show("所有测试结束");

                    // Finish the temperature data file
                    Data2File.FinishTempFile();

                    // Click Run button to change the status to STOP status
                    this.Invoke(new EventHandler(delegate
                    {
                        this.BntRunAuto.PerformClick();
                    }));
                }
                // If there is, start next turn of run
                else
                {
                    autoStep.NextTurn();
                }
            }
        }