How do I reset my Arduino Mega2560 with my C# application?

╄→гoц情女王★ 提交于 2020-01-04 07:20:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!