【问题标题】:How to upload a HEX file to Arduino in Java?如何在 Java 中将 HEX 文件上传到 Arduino?
【发布时间】:2013-01-30 13:11:04
【问题描述】:

我想将准备好的 HEX 文件上传到 Arduino 板。如何在 Java 代码中做到这一点?

我应该在 Java 中实现 STK500 协议吗? Java 中是否有任何可行的解决方案或示例?

PS。我在Erlang 中找到了STK500 implementation,但我不知道。

【问题讨论】:

  • 没有 hex 文件这样的东西。只有文件。它们中的内容与上传过程无关。这里没有足够的信息来回答这个问题。你如何与董事会互动?
  • hex 文件是由 Arduino IDE 生成的编译草图文件(确切地说是由编译器)并准备上传。 Arduinos 通常通过串行接口
  • @user1103561:适当的术语是“二进制文件”; hex(十六进制的缩写)只是表示值的基础。
  • 对不起,我知道了
  • @EJP:OP 指的是 Intel Hex 文件格式:en.wikipedia.org/wiki/Intel_HEX

标签: java erlang arduino protocols


【解决方案1】:

轮子存在。使用轮子。
使用优秀的 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);

【讨论】:

  • 如何在安卓应用中使用?不希望使用本机代码,因为它取决于 cpu 架构,我必须为每个 cpu 架构编译、测试和维护它。这就是为什么我要java
  • 您没有提及从 Android 应用上传。在 Android 上,如果不对 FTDI 驱动程序实施某种形式的替换,您将无法获得串行端口。
  • 问题是关于使用 java 上传,因为 Android 使用 java 并且问题不在于串行,而在于与引导加载程序交互的方式。
【解决方案2】:

我可以很容易地使用 Stk500 协议(Uno,仅限旧 arduinos)做到这一点。唯一需要注意的是 DTR/RTS。

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 2011-09-17
    • 2013-05-18
    • 2023-03-31
    • 2019-07-02
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 2016-11-12
    相关资源
    最近更新 更多