This isn't a question, just figured I'd post this for anyone else that may need to do what I did. I have an Arduino Duemilanove board that interfaces to a C# application. That works well, but I always had to go back to the Arduino IDE to upload changes to the board.
I needed to be able to also upload new versions of the code from the C# application, so after poking around the forums I wrote something that seemed to me to be useful enough (not limited to C# apps, once you see what it does) to post back. The following snippet of code is called as a result of a button push in my C# application....
private void aVRUpdateButton_Click(object sender, EventArgs e)
{
// These files must be part of the installation.
// They come from the Arduino installation directory arduino/hardware/tools/avr/bin
if (!File.Exists(installDir + "\\avr\\avrdude.exe"))
{
MessageBox.Show("avrdude tool not installed", "AVRUpdate error");
return;
}
if (!File.Exists(installDir + "\\avr\\avrdude.conf"))
{
MessageBox.Show("avrdude config file not installed", "AVRUpdate error");
return;
}
if (!File.Exists(installDir + "\\avr\\cygwin1.dll"))
{
MessageBox.Show("avrdude cygwin dll not installed", "AVRUpdate error");
return;
}
if (!File.Exists(installDir + "\\avr\\libusb0.dll"))
{
MessageBox.Show("avrdude usb dll not installed", "AVRUpdate error");
return;
}
// THis file is the new image to be uploaded to the Arduino board...
if (!File.Exists(installDir + "\\avr\\AVRImage.hex"))
{
MessageBox.Show("AVR image not installed", "AVRUpdate error");
return;
}
textBox_Trace.Text += "(DO NOT RESET OR TURN OFF TILL THIS COMPLETES)\r\n";
MessageBox.Show("Click OK to Start", "AVR Update");
string avrport = "COM" + numericUpDown_Port.Value.ToString();
string dir = installDir;
dir.Replace("\\", "/");
Process avrprog = new Process();
StreamReader avrstdout, avrstderr;
StreamWriter avrstdin;
ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
avrprog.StartInfo = psI;
avrprog.Start();
avrstdin = avrprog.StandardInput;
avrstdout = avrprog.StandardOutput;
avrstderr = avrprog.StandardError;
avrstdin.AutoFlush = true;
//avrstdin.WriteLine(installDir + "\\avr\\avrdude.exe -Cavr/avrdude.conf -patmega328p -cstk500v1 -P" + avrport + " -b57600 -D -Uflash:w:" + dir + "/avr/AVRImage.hex:i");
avrstdin.WriteLine("avr\\avrdude.exe -Cavr/avrdude.conf -patmega328p -cstk500v1 -P" + avrport + " -b57600 -D -Uflash:w:avr/AVRImage.hex:i");
avrstdin.Close();
textBox_Trace.Text = avrstdout.ReadToEnd();
textBox_Trace.Text += avrstderr.ReadToEnd();
}
The code assumes that a few files taken from the Arduino bin directory are found under the path whose string is contained within "installDir" (specifcally: avrdude.exe, avrdude.conf, cygwin1.dll & libusb0.dll). The function simply opens a process running CMD and then issues the avrdude command line that will pump a new image to the arduino board on the comport taken from a numeric-up-down tool within the GUI. The output of the process is copied back into a textbox (textbox_Trace) for viewing by the user.
Obviously the arguments passed to avrdude depend on your configuration, but I think (please correct me if I'm wrong) this is a fairly generic approach.
Enjoy! If you happen to use it and find any bugs, please post back.