问题
I noticed the Arduino IDE automatically resets on startup/exit by the built in serial application due to
one of the hardware flow control lines (DTR) of the FT232RL is connected to the reset line of the ATmega1280 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the chip.
I noticed that behaviour does not happen with my serial C# application. I would like the reset feature to work with my C# application. What am I not doing to get my Arduino Mega to reset by my C# application?
Working Code for Arduino and C#:
I got it working in about 5 minutes by hooking up a wire from PWM Port12 to the RESET Port. On the Arduino, I checked for the text RESET on the incoming SerialEvent3. When RESET is found do:
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
As for as the C# it was as simple as:
if (serialPort1.IsOpen)
{
serialPort1.Write("RESET");
}
Reset seems to work as expected.
回答1:
DTR works fine for me from the .NET SerialPort class.
Just set the property:
port.DtrEnable = true;
I have noticed different defaults if you use the SerialPort in the WinForms designer, but DtrEnable
is in fact true
(by default) when using it from a console app.
来源:https://stackoverflow.com/questions/11236884/how-do-i-reset-my-arduino-mega2560-with-my-c-sharp-application