我想将准备好的 HEX 文件上传到 Arduino 开发板。我如何在 Java 代码中做到这一点?
我应该用 Java 实现 STK500 协议(protocol)吗? Java 中是否有任何可行的解决方案或示例?
附言。我找到了一个 STK500 implementation在 Erlang ,但我不知道。
最佳答案
轮子存在。使用滚轮。
使用出色的 AVRdude 从 Java 上传。
/*
A command line looks like this in a stock Arduino IDE:
D:\arduino-dev\arduino-1.0.3\hardware/tools/avr/bin/avrdude
-CD:\arduino-dev\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf
-v -v -v -v -patmega328p -carduino
-P\\.\COM8 -b115200 -D -V
-Uflash:w:e:\Temp\build100458372319682483.tmp\Blink.cpp.hex:i
Just write the binary to the .HEX file and let the dude upload it:
*/
String hexfile = "e:\somefolder\Blink.cpp.hex";
String exefile = "D:\arduino-dev\arduino-1.0.3\hardware/tools/avr/bin/avrdude";
String conffile = "D:\arduino-dev\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf";
String opts = " -v -v -v -v -patmega328p -carduino -P\\.\COM8 -b115200 -D -V ";
String cmd = exefile +" -C"+ conffile + opts +" -Uflash:w:" + hexfile +":i";
Process proc = Runtime.getRuntime().exec(cmd);
int retcode = waitFor(proc);
关于java - 如何用 Java 将 HEX 文件上传到 Arduino?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14604866/