Exemple #1
0
        private void stLinkDownFile(object Object)
        {
            ProcessStartInfo si = new ProcessStartInfo(@"ST-LINK_CLI.exe");

            si.WindowStyle            = ProcessWindowStyle.Hidden;
            si.CreateNoWindow         = true;
            si.UseShellExecute        = false;
            si.RedirectStandardOutput = true;

            //erase all flash
            si.Arguments = "-c -me";
            Process po = Process.Start(si);

            po.OutputDataReceived += new DataReceivedEventHandler(Po_OutputDataReceived);
            po.BeginOutputReadLine();
            po.WaitForExit();

            DeviceOperation device = new DeviceOperation();

            List <FirmwareInfomation> firmwares = isp.GetDataToWrite(ref device, g_curDeviceId, g_curDelayOut); ///读取文件
            string args        = "";
            int    probarValue = 100 / firmwares.Count;

            foreach (FirmwareInfomation ff in firmwares)
            {
                if (ff.Name == "data")
                {
                    //set data
                    int[] dd = converData(ff.Data);
                    for (int i = 0; dd[i] != 0; i++)
                    {
                        string aa = Convert.ToString(dd[i], 16);
                        args += " -w32 " + (ff.BaseAddress + i).ToString("X") + " " + aa;
                    }
                    si.Arguments           = args;
                    po                     = Process.Start(si);
                    po.OutputDataReceived += new DataReceivedEventHandler(Po_OutputDataReceived);
                    po.BeginOutputReadLine();
                    po.WaitForExit();
                    args = "";
                }
            }
            args = "";
            foreach (FirmwareInfomation ff in firmwares)
            {
                //down file
                if (ff.Name != "data")
                {
                    args += string.Format(" -p {0} {1} ", ff.Name, ff.BaseAddress.ToString("X"));
                }
            }
            // SerialFlash.AppendText(args);
            si.Arguments           = args + " -rst";
            po                     = Process.Start(si);
            po.OutputDataReceived += new DataReceivedEventHandler(Po_OutputDataReceived);
            po.BeginOutputReadLine();
            po.WaitForExit();
        }
Exemple #2
0
 private void ShowDeviceInfo(ref DeviceOperation device)//显示芯片信息
 {
     device.BootloaderVer = this.isp.BootloaderVer;
     device.ChipType      = this.isp.ChipType;
     device.OptionByte    = this.isp.OptionByte;
     device.UniqueID      = this.isp.UniqueID;
     this.rtbSerial.AppendText("串口" + this.isp.PortName + "打开成功,波特率" + this.isp.PortBaudRate + "\r\n");
     this.rtbSerial.AppendText("芯片类型:" + device.ChipType + "\r\n");
     this.rtbSerial.AppendText("芯片内部bootloader版本号:" + device.BootloaderVer + "\r\n");
     this.rtbSerial.AppendText("芯片FLASH容量为:" + this.isp.ChipSize + "字节\r\n");
     this.rtbSerial.AppendText("设备唯一ID:" + device.UniqueID + "\r\n");
     this.rtbSerial.AppendText("选项字节:" + device.OptionByte + "\r\n");
 }
Exemple #3
0
        private bool EraseCheckSerial(int baudRate)
        {
            int    index    = 3;
            var    initType = (ISPProgramerL071.InitialType)index;
            string portName = this.cbxCom.SelectedItem as string;

            this.rtbSerial.AppendText("串口: " + portName + "\r\n");

            bool IspInitState = this.isp.Init(portName, baudRate, initType);

            DeviceOperation temp = new DeviceOperation(); ///打印信息

            this.ShowDeviceInfo(ref temp);
            return(IspInitState);
        }
 public static bool SaveResult(string path, DeviceOperation result)
 {
     try
     {
         using (StreamWriter writer = new StreamWriter(path, true, Encoding.Unicode))
         {
             writer.NewLine = "\r\n";
             writer.WriteLine(result.Time + ";" + result.UniqueID + ";" + result.OptionByte + ";" + result.ChipType + ";" + result.BootloaderVer + ";" + result.File1 + ";" + result.File2 + ";" + result.FirmwareVer + ";" + result.SerialID);
             writer.Flush();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #5
0
        private void StartEraseFlash_Click(object sender, EventArgs e)
        {
            Button bt = (Button)sender;

            bt.BackColor = Color.GreenYellow;
            bt.Text      = "下载中";
            if (!checkInputData())
            {
                MessageBox.Show("输入数据格式不正确");
                return;
            }
            // send serial object and port name ,rich
            isp.UseISPProgramerL071(serialPort1, cbxCom.Text, rtbSerial);

            if (g_DownFileMode == true)
            {
                // uart down
                DeviceOperation device = new DeviceOperation();
                // get write file
                List <FirmwareInfomation> firmwares = isp.GetDataToWrite(ref device, g_curDeviceId, g_curDelayOut); ///读取文件
                Action <bool>             runAction = new Action <bool>((re) =>
                {
                    this.btnStartWrite.Text = "取消";
                    bt.BackColor            = Color.White;
                    StartEraseCount         = 0;
                });

                if (firmwares == null)
                {
                    this.rtbSerial.AppendText("请选择烧写文件\r\n");
                    bt.BackColor = Color.Red;
                    return;
                }
                // begin start down file to device
                Thread oneThread = new Thread(new ParameterizedThreadStart(usartDownFile));
                oneThread.Start(firmwares); //启动线程
            }
            else
            {
                Thread oneThread = new Thread(new ParameterizedThreadStart(stLinkDownFile));
                oneThread.Start(); //启动线程
            }
        }