コード例 #1
0
ファイル: Form1.cs プロジェクト: Sowhat2112/KreyosFirmware
        private void RunButton_Click(object sender, EventArgs e)
        {
            // validation
            errorProvider1.Clear();

            if (String.IsNullOrEmpty(BoardIdTextBox.Text))
            {
                BoardIdTextBox.Focus();
                errorProvider1.SetError(BoardIdTextBox, "没有批号");
                return;
            }

            if (string.IsNullOrEmpty(MacAddrTextBox.Text))
            {
                MacAddrTextBox.Focus();
                errorProvider1.SetError(MacAddrTextBox, "没有MAC地址");
                return;
            }

            // check mac address in format
            string mac = MacAddrTextBox.Text;

            byte[] addr = new byte[6];

            if (!TryParseMac(mac, addr))
            {
                MacAddrTextBox.Focus();
                errorProvider1.SetError(MacAddrTextBox, "MAC地址格式不对,必须是12个字符长,16进制");
                return;
            }

            String filename = String.Format("{0}.txt", MacAddrTextBox.Text);

            filename = Path.Combine(OutputPathTextBox.Text, filename);
            if (File.Exists(filename))
            {
                if (MessageBox.Show("MAC地址已经用过,你确定要这么做吗?", "错误", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            // check current for flashing
            float current = device.Current;

            if (current < 10 || current > 30)
            {
                if (MessageBox.Show("电流不正常,无法刷机。一定要尝试吗?", "错误", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            timeout        = 60;
            timer2.Enabled = true;
            // disable controls
            RunButton.Enabled        = false;
            BoardIdTextBox.ReadOnly  = true;
            MacAddrTextBox.ReadOnly  = true;
            OperatorTextBox.ReadOnly = true;
            InitializControlForRun();

            foreach (Control c in groupBox1.Controls)
            {
                CheckBox cb = c as CheckBox;
                if (cb == null)
                {
                    continue;
                }

                cb.Checked   = false;
                cb.ForeColor = SystemColors.ControlText;
            }


            // enable status textbox
            label3.Text    = "刷机";
            label3.Visible = true;


            // generate mac.txt file
            using (fs = new StreamWriter(File.OpenWrite("mac.txt")))
            {
                fs.WriteLine("@1800");
                fs.WriteLine(String.Format("{0} 00 01 01 {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2}\r\nq",
                                           testingCheckbox.Checked?"01":"00",
                                           addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]));
            }


            fs = new StreamWriter(File.OpenWrite(filename));

            fs.WriteLine("测试记录,MAC地址:{0} 批号:{1} 操作员:{2}", MacAddrTextBox.Text, BoardIdTextBox.Text, OperatorTextBox.Text);

            ProcessStartInfo startInfo = new ProcessStartInfo("bsl.exe");

            startInfo.Arguments              = "prog";
            startInfo.CreateNoWindow         = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.WindowStyle            = ProcessWindowStyle.Minimized;
            //startInfo.RedirectStandardError = true;
            //startInfo.RedirectStandardInput = true;
            //startInfo.WindowStyle = ProcessWindowStyle.Minimized;
            startInfo.UseShellExecute = false;

            currentstatus  = Status.BurnFinish;
            timer2.Enabled = true;

            process = Process.Start(startInfo);
            process.EnableRaisingEvents = true;
            process.Exited             += process_Exited;
            process.OutputDataReceived += process_OutputDataReceived;
            process.BeginOutputReadLine();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Sowhat2112/KreyosFirmware
        private void OnFinished(Status status)
        {
            if (status == Status.BurnFinish)
            {
                // continue next step
                currentstatus = Status.TestFinish;
                label3.Text   = "测试";
                process       = null;

                if (ValidateCurrent("$$OK FLASHING"))
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo("bsl.exe");
                    startInfo.Arguments              = "reset";
                    startInfo.WindowStyle            = ProcessWindowStyle.Minimized;
                    startInfo.RedirectStandardOutput = true;
                    //startInfo.RedirectStandardError = true;
                    //startInfo.RedirectStandardInput = true;
                    startInfo.UseShellExecute = false;
                    startInfo.CreateNoWindow  = true;
                    //startInfo.WindowStyle = ProcessWindowStyle.Minimized;

                    resetprocess = Process.Start(startInfo);
                    resetprocess.EnableRaisingEvents = true;
                    resetprocess.Exited             += process_Exited;
                    resetprocess.OutputDataReceived += process_OutputDataReceived2;
                    resetprocess.BeginOutputReadLine();

                    return;
                }
                else
                {
                    ResultLabel.Text = "FAIL";
                    fs.WriteLine("FAIL {0} {1} {2}", MacAddrTextBox.Text, BoardIdTextBox.Text, OperatorTextBox.Text);
                }
            }
            else if (status != Status.Done)
            {
                currentstatus = Status.Done;
                if (status == Status.Fail)
                {
                    // warning
                    ResultLabel.Text = "出错了";
                    fs.WriteLine("FAIL {0} {1} {2}", MacAddrTextBox.Text, BoardIdTextBox.Text, OperatorTextBox.Text);
                }
                else
                {
                    ResultLabel.Text = "测试通过";
                    fs.WriteLine("OK {0} {1} {2}", MacAddrTextBox.Text, BoardIdTextBox.Text, OperatorTextBox.Text);
                }
            }
            fs.Close();
            // save the result
            timer2.Enabled = false;

            // enable the control, get ready for next
            RunButton.Enabled       = true;
            MacAddrTextBox.ReadOnly = false;
            label3.Text             = "测试通过,下一个";

            MacAddrTextBox.Focus();
            MacAddrTextBox.SelectAll();
            LogTextBox.Clear();
        }