Beispiel #1
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();
        }
Beispiel #2
0
        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();
        }