示例#1
0
 private void ResetCom()
 {
     try
     {
         Value.serialPort1.Close();
     }
     catch { }
     try
     {
         Value.serialPort1               = new System.IO.Ports.SerialPort();
         Value.serialPort1.PortName      = Ini.Read("COM");
         Value.serialPort1.BaudRate      = 115200;
         Value.serialPort1.DataReceived += Port1_DataReceived;
         Value.serialPort1.Open();
     }
     catch { (new SetPort()).ShowDialog(); if (FailCount++ > 2)
             {
                 return;
             }
             ResetCom(); }
 }
示例#2
0
        private void Sensor_Load(object sender, EventArgs e)//加载窗口
        {
            int i;

            Value.App_Run = true;
            tabControl1.TabPages.RemoveAt(2);
            if (int.TryParse(Ini.Read("StartTabIndex"), out i))
            {
                tabControl1.SelectedIndex = i;
            }
            tabControl1.SelectedTab.BackColor = groupBox2.BackColor;
            OpenFileDialog Dlg = new OpenFileDialog();

            ResetCom();
            DrawHumi        = new DrawWatch();
            DrawTemp        = new DrawWatch();
            DrawVol         = new DrawWatch();
            DrawUserate_CPU = new DrawWatch();
            DrawHumi.Init();
            DrawTemp.Init();
            DrawVol.Init();
            DrawUserate_CPU.Init();
            ServiceThread = new Thread(new ThreadStart(GetAngle));
        }
示例#3
0
文件: SetPort.cs 项目: wpmyj/csharp
 private void button1_Click(object sender, EventArgs e)
 {
     Ini.Write("COM", comboBox1.Text);
     this.Close();
 }
示例#4
0
 private void Supper_Face_FormClosing(object sender, FormClosingEventArgs e)
 {
     Ini.Write("窗口宽度", this.Width.ToString());
     Ini.Write("窗口高度", this.Height.ToString());
 }
示例#5
0
 private void CustomItem_Click(object sender, EventArgs e)
 {
     Ini.Write("COM", ((ToolStripMenuItem)sender).Text);
     Tools.ResetCom();
 }
示例#6
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     Ini.Write("附件路径", comboBox1.Text);
 }
示例#7
0
        private void 烧写()
        {
            int      PageSize;
            uint     LostCount = 0;
            UInt32   Error     = 0;
            FileInfo fi;
            uint     len;

            byte[] buffer;
            try
            {
                fi  = new FileInfo(Application.StartupPath + "\\File\\" + Ini.Read("附件路径"));
                len = (uint)fi.Length;
                FileStream fs = fi.OpenRead();
                buffer = new byte[len];
                fs.Read(buffer, 0, (int)len);
                fs.Close();
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message);
                return;
            }

            PageSize = (int)len / 1024;
Ai:
            Count = 0;
            while (Value.App_Run)
            {
                button4_Click(null, null);
                for (int z = 0; z < 5; z++)
                {
                    Thread.Sleep(10);
                    if (Count > 0)
                    {
                        goto Ci;
                    }
                }
            }
Ci:
            Count = 0;
            Erase((uint)fi.Length);
            Thread.Sleep(2000);
            for (int z = 0; z < 5300; z++)
            {
                Thread.Sleep(1);
                if (Count > 0)
                {
                    goto Bi;
                }
            }
            goto Ai;
Bi:
            Thread.Sleep(1000);
            Count = 0;
            int i = 0;

            while (Value.App_Run)
            {
                if (i == Count)
                {
                    Error = 0;
                    if (len >= 1024)
                    {
                        Write1024(buffer, i, 1024); len -= 1024;
                        LostCount = 1024;
                        goto B;
                    }
                    if (len < 1024)
                    {
                        if (len > 0)
                        {
                            Write1024(buffer, i, (int)len); len = 0;
                            LostCount = len;
                            goto B;
                        }
                    }
                    if (len == 0)
                    {
                        break;
                    }
B:
                    i++;
                }
                else
                {
                    Error++;
                }
                if (Error == 100)
                {
                    i--; len += LostCount;
                }
                BeginInvoke(new MethodInvoker(delegate()
                {
                    progressBar1.Maximum = PageSize + 1;
                    progressBar1.Value   = i;
                }));
                Thread.Sleep(10);
            }
            BeginInvoke(new MethodInvoker(delegate()
            {
                richTextBox1.SelectionColor = Color.Blue;
                richTextBox1.AppendText("烧写完成!\r\n");
                button1.Text = "烧写";
            }));
            button3_Click(null, null);
            Thread.Sleep(100);
            button3_Click(null, null);
            BeginInvoke(new MethodInvoker(delegate()
            {
                richTextBox1.SelectionColor = Color.Blue;
                richTextBox1.AppendText("程序开始执行!\r\n");
                button1.Text = "烧写";
                Value.queue.Enqueue(DateTime.Now.ToString() + "固件下载LOG:" + richTextBox1.Text);
                comboBox1.Enabled = true;
            }));
        }
示例#8
0
 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {
     tabControl1.SelectedTab.BackColor = groupBox2.BackColor;
     Ini.Write("StartTabIndex", tabControl1.SelectedIndex.ToString());
 }