0

I have basic C# form which program microcontroller but I have hard time on fuse programming.

Command line code to program fuse is: "atprogram.exe –t atmelice –i jtag -d atmega2561 write -fs --values E299FF"

  • As you can see in image fuse program successfully in command line
  • In Visual Studio form same command line return nothing.
  • When I substitute fuse code with chip erase code form return result. This only happen when I program the fuse.
  • I have also tires WaitForExit(); still nothing

Original C# file can be downloaded from: Microchip Visual Studio form code

public StreamReader RunProgram_atprogram(String programName, String cmd, String programPath) {
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo.CreateNoWindow = true;
    proc.StartInfo.FileName = programName;
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.RedirectStandardInput = true;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.Start();
    if (programPath.Length > 13) {
        proc.StandardInput.WriteLine(programPath[0].ToString() + ":");
        if (cmd.Length != 0) {
            proc.StandardInput.WriteLine("cd " + programPath.Substring(0, (programPath.Length - 13)));
        }
    }
    proc.StandardInput.WriteLine(cmd);
    StreamReader reader = proc.StandardOutput;
    proc.StandardInput.WriteLine("exit");
    proc.Close();
    return reader;
}

  

private void program_Click(object sender, EventArgs e)
            {
                StreamReader reader;
                string outline;
                string failflag = null;
                string buffer = null;
               

            if ((textBox1.Text == "") || (textBox2.Text == ""))
            {
                MessageBox.Show("Please choose atpgrogram.exe application and programming file");
                return;
            }

            program_status.Clear();
            program_status.AppendText("Programming...");


            
            // Program Fuse

            reader = RunProgram_atprogram("cmd.exe", "atprogram.exe –t atmelice –i jtag -d atmega2561 write -fs --values E299FF", textBox1.Text);
            while (!reader.EndOfStream)
            {
                outline = reader.ReadLine();
                cmd_execution_info.AppendText(outline + "\r\n");

                if (outline.Length > 8)
                {
                    if (outline.Substring(0, 8) == "Firmware")
                    {
                        failflag = reader.ReadLine();
                        cmd_execution_info.AppendText(failflag + "\r\n");

                    }
                }

            }
            if (failflag != ("Chiperase completed successfully"))
            {
                 program_status.Clear();
                 program_status.AppendText("Fail");
                 return;
            }

Please let me know if you have additional questions.

Command Line enter image description here Form

Shahreza
  • 113
  • 5
  • You need to Close _StandardInput_. The following may be helpful: https://stackoverflow.com/a/72818271/10024425 – Tu deschizi eu inchid Apr 06 '23 at 21:30
  • @user09938 I just try adding proc.StandardInput.Close(); and didnt work. – Shahreza Apr 06 '23 at 21:33
  • Very seldom is it necessary to use `cmd.exe`. See the example in the URL in my previous comment. Filename should be fully-qualifed path of `atprogram.exe`, not `cmd.exe`. Then everything after `atprogram.exe` goes in [Arguments](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.arguments?source=recommendations&view=net-7.0). – Tu deschizi eu inchid Apr 06 '23 at 21:36
  • After further review, you probably don't have to redirect _StandardInput_ at all, but may (or may not) need to run your app as an administrator. The following may be helpful: https://stackoverflow.com/a/71344930/10024425. `cd` probably isn't going to work, so figure out how to make it work without it such as using fully-qualified paths and/or setting [WorkingDirectory](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.workingdirectory?view=net-6.0). – Tu deschizi eu inchid Apr 06 '23 at 21:52
  • @user09938 then how come other command such chiperase or program the flash workfine. – Shahreza Apr 06 '23 at 21:56
  • I have no idea - I don't use any of those apps. If you're looking for a solution, I recommend trying something that you haven't already tried, such as my suggestions. If you'd like the same results you're already experiencing, then stick with your current approach. – Tu deschizi eu inchid Apr 06 '23 at 23:10

0 Answers0