Beispiel #1
0
        private void timerCallBack(object sender, EventArgs e)
        {
            if (this.beginWrite)
            {
                this.progressBar.Visible = true;
                this.progressBar.Value   = progressCount;
                //if (progressCount == 100)
                //   this.beginWrite = false;

                if (progressState == 0x00020000)
                {
                    //  if(MessageBox.Show("是否烧写","是否用版本号" + FirmwareManage.WriteFirmwareGetDeviceSoftVer().ToString() + "替换为版本号" + FirmwareManage.HexFileGetFileVer().ToString(), MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                    //   {
                    FirmwareManage.WriteFirmwareBeginWrite();
                    //  }
                    //  else
                    // {
                    //     this.beginWrite = false;
                    // }
                }
            }
            else
            {
                this.progressBar.Visible = false;
            }
        }
Beispiel #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //BluetoothCtrl.DetecteBluetoothDevice();
            this.firmwareManage = new FirmwareManage();
            this.com            = new SerialPort();
            this.portComboBox.Items.AddRange(SerialPort.GetPortNames());
            this.beginWrite    = false;
            this.progressCount = 0;

            tmr          = new System.Windows.Forms.Timer();
            tmr.Interval = 10;
            tmr.Tick    += new EventHandler(timerCallBack);
            tmr.Start();
        }
Beispiel #3
0
        private void runWriteFirmware()
        {
            progressCount   = 0;
            this.beginWrite = true;

            /*while (this.beginWrite)
             * {
             *  progressCount++;
             *  Thread.Sleep(100);
             * }*/
            int secNum = this.firmwareManage.SectionNum;

            if (secNum < 1)
            {
                return;
            }
            int    dataLength;
            UInt32 beginAddr;

            byte[] dataBuff = new byte[0x10000];
            this.firmwareManage.GetSectionData(0, out beginAddr, dataBuff, out dataLength);
            UInt32 ver = this.firmwareManage.GetSoftVersion(50);

            /*int division2k = dataLength >> 11;
             *
             * for(int i = 0; i < division2k; i ++)
             * {
             * if(this.firmwareManage.FirmwareSetAddr((UInt32)(beginAddr + i * 0x800)) != 0)
             * {
             *     MessageBox.Show("设置地址错误");
             *     this.com.Close();
             *     return;
             * }
             *
             * for(int j = 0; j < 0x80; j ++)
             * {
             *     if(this.firmwareManage.WriteDataToDevice(dataBuff, i * 0x800 + j * 16,16) != 0)
             *     {
             *         MessageBox.Show("设置数据错误");
             *         this.com.Close();
             *         return;
             *     }
             * }
             *
             * if(this.firmwareManage.FirmwareCkAndPro(dataBuff, i * 0x800,0x800) != 0)
             * {
             *     MessageBox.Show("数据段校验错误");
             *     this.com.Close();
             *     return;
             * }
             * progressCount = (i + 1) * 100 / (division2k + 1);
             * }
             *
             * int leftData = dataLength & 0x7ff;
             * if(leftData != 0)
             * {
             * int division16 = leftData / 16;
             * int leftData16 = leftData & 0x0f;
             *
             * if (this.firmwareManage.FirmwareSetAddr((UInt32)(beginAddr + division2k * 0x800)) != 0)
             * {
             *     MessageBox.Show("设置地址错误");
             *     this.com.Close();
             *     return;
             * }
             *
             * for (int j = 0; j < division16; j++)
             * {
             *     if (this.firmwareManage.WriteDataToDevice(dataBuff, division2k * 0x800 + j * 16, 16) != 0)
             *     {
             *         MessageBox.Show("设置数据错误");
             *         this.com.Close();
             *         return;
             *     }
             * }
             *
             * if (leftData16 > 0)
             * {
             *     if (this.firmwareManage.WriteDataToDevice(dataBuff, division2k * 0x800 + division16 * 16, leftData16) != 0)
             *     {
             *         MessageBox.Show("设置数据错误");
             *         this.com.Close();
             *         return;
             *     }
             * }
             *
             * if (this.firmwareManage.FirmwareCkAndPro(dataBuff, division2k * 0x800, leftData) != 0)
             * {
             *     MessageBox.Show("数据段校验错误");
             *     this.com.Close();
             *     return;
             * }
             * }
             *
             * if (this.firmwareManage.FirmwareSetInf(dataBuff, (UInt32)dataLength,beginAddr, 0x01000000) != 0)
             * {
             * MessageBox.Show("设置固件信息错误");
             * this.com.Close();
             * return;
             * }
             *
             */

            FirmwareManage.WriteFirmwareInit();
            while (beginWrite)
            {
                byte[] buff      = new byte[256];
                byte[] outBuff   = new byte[32];
                int    outLength = 0;
                int    length    = this.com.BytesToRead;
                if (length > 0)
                {
                    if (length > 256)
                    {
                        length = 256;
                    }
                    this.com.Read(buff, 0, length);
                }

                progressState = FirmwareManage.WriteFirmwareUpdate(buff, length, outBuff, out outLength, (UInt32)Environment.TickCount);
                progressCount = (int)progressState & 0x0000ffff;

                if (outLength > 0)
                {
                    this.com.Write(outBuff, 0, outLength);
                }

                if ((progressState >> 16) == 15)
                {
                    Thread.Sleep(100);
                    beginWrite = false;
                    break;
                }

                //         Thread.Sleep(1);
            }

            this.com.Close();
        }