Ejemplo n.º 1
0
        //更新固件
        private void updateimage(string filepath)
        {
            try
            {
                mfstrm = new FileStream(filepath, FileMode.Open, FileAccess.Read);
            }catch (Exception)
            {
                MessageBox.Show("Sorry, the firmware path is wrong!");
                return;
            }
            byte[] bytes = new byte[mfstrm.Length];
            try
            {
                mfstrm.Read(bytes, 0, bytes.Length);
            }
            catch (Exception)
            {
            }
            finally
            {
                if (null != mfstrm)
                {
                    mfstrm.Close();
                }
                mfstrm = null;
            }
            //开始创建线程
            int result = ReadHexInfor.HexToBin(bytes, out mbins, out binlen);

            if (result < 0)
            {
                #region
                if (result == -1)
                {
                    MessageBox.Show("Sorry, check hex failed!");
                    return;
                }
                else if (result == -2)
                {
                    MessageBox.Show("The length of the error");
                    return;
                }
                #endregion
            }
            else
            {
                //可以开始传送固件数据了
                mythread = new Thread(updateimage);
                mythread.Start();
            }
        }
Ejemplo n.º 2
0
        //选择Hex文件
        private void selectbtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog mofd = new OpenFileDialog();

            mofd.Filter = "all|*.hex";
            if (mofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                updatefiletxt.Text = mofd.FileName;
                ReadHexInfor.getfileinfor(mofd.FileName, out curhexmg);
                //更新固件信息
                sizetxt.Text    = curhexmg.filesize + " byte";
                versiontxt.Text = ((byte)(curhexmg.version >> 24)).ToString("D2") + ((byte)(curhexmg.version >> 16)).ToString("D2") + ((byte)(curhexmg.version >> 8)).ToString("D2") + ((byte)(curhexmg.version)).ToString("X2");
                devtypetxt.Text = curhexmg.GetDev();
            }
        }