通过Arduino IDE在虚拟串口上传Arduino代码 [英] Upload Arduino code on virtual serial port through Arduino IDE

查看:119
本文介绍了通过Arduino IDE在虚拟串口上传Arduino代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了几个提供虚拟 COM 端口的软件.这些 COM 端口确实出现在 设备管理器 中,可以从 Arduino IDE 菜单中选择上传工具 -> 串口 -> COM3.它开始上传并达到 90%,然后它要么超时,要么什么都不做.

I downloaded several software that provide virtual COM ports. These COM ports do appear in the Device Manager and can be selected for upload from the Arduino IDE, menu Tools -> Serial Port -> COM3. It starts uploading and reaches 90% and then it either times out or just does nothing.

我想上传到虚拟 COM 端口,这样我就可以在另一个程序中读取编译输出文件.我根本不想使用我的 Arduino,也不想在上传时手动获取详细的输出文件.当我在真正的 Arduino 上上传时不会发生这个问题.

I want to upload onto the virtual COM port so I could then read the compilation output files in another program. I don't want to use my Arduino at all, and I don't want to manually get the verbose output files when uploading. This problem doesn't happen when I upload on the real Arduino.

该应用程序应适用于所有平台.这个任务在 Linux 上似乎很容易,我在 Windows 上面临着上述问题,任何有关 Mac 的帮助也很有用.

The application should work on all platforms. This task seems easy on Linux, and I am facing the stated problem on Windows and any help with Mac would also be useful.

该应用程序将成为硬件模拟和可视化的教育工具,试图为用户提供比其他模拟器更多的动手体验.因此,这可能会让您了解我为什么要这样做.

The application will be an educational tool for hardware simulation and visualization trying to give a more hands-on experience for users than other simulators out there. So may be this will give you an idea of why I want to do so.

我该如何开始?

推荐答案

我想您可能会假设将代码上传到 Arduino 是一种单向通信:这就像将草莓放入搅拌机中,然后 Daquiri 出来了.如果这是真的,您可以将 IDE 转储到串行端口的任何内容保存到文件中,然后您就有了一个 Arduino 二进制文件.(如果对细节不感兴趣,请跳到 TL;DR.结果:这个假设是不正确的).

I think you might be assuming that uploading code to Arduino is one-way communications: this would be like putting strawberries in a blender, and a Daquiri comes out. If that was true, you could just take whatever the IDE dumps to the serial port, save it to a file, and you have an Arduino binary. (Skip to TL;DR if not interested in details. Upshot: this assumption is not correct).

1-way 通信假设并不完全正确:Arduino 上有一个程序(称为a bootloader") 负责与程序员(程序员":对 Arduino 进行编程的程序,假设它现在是 Arduino IDE)进行通信.在最自然"的状态下,Arduino CPU 无法跨串行线路进行编程.相反,这些芯片是通过系统编程 (ISP) 或通过 JTAG 协议.引导加载程序是一个在 Arduino CPU 上运行并通过串行端口加载草图/程序的程序.该程序在启动时运行并通过串行端口查找编程命令.

The 1-way communication assumption is not entirely correct: there is a program on the Arduino (called "a bootloader") which is responsible for communicating with the programmer ("programmer": a program that programs the Arduino, assume it is the Arduino IDE for now). In their most "natural" state, the Arduino CPUs cannot be programmed across serial lines. Rather these chips are programmed either via the in system programming (ISP) or via the JTAG protocol. The bootloader is a program that runs on an Arduino CPU and loading of sketches/programs over the serial port. This program runs at startup and looks for programming commands over the serial port.

如果它发现程序员正在尝试传递编程信息,它将读取来自串行链接的编译后的 Arduino 二进制文件,将其存储在闪存中,通过串行链接将其发送回以进行验证,如果一切正常成功,退出并启动存储的草图.如果串行端口上没有出现编程信息,即没有程序员尝试编写新的草图,则引导加载程序只需退出并启动已存储在闪存中的程序.

If it discovers that a programmer is trying to communicate programming information, it will read the compiled Arduino binary coming over the serial link, store it in flash memory, send it back to over the serial link for verification, and if everything is successful, exit and launch the stored sketch. If no programming information appears on the serial port, that is, no programmer is trying to write a new sketch, then the bootloader simply quits and launches the program already stored in flash.

TL;DR:为了在您的串行端口上实现伪 Arduino,您必须编写一些代码来模拟虚拟串行端口另一端的 Arduino(引导加载程序).所以当程序员/IDE 对 Arduino 说你在吗?"您的程序将响应是!",就像 Arduino 一样.

TL;DR: In order to implement a pseudo-Arduino on your serial port you must write a program some code that simulates an Arduino (bootloader) on the other end of your virtual serial port. So when a programmer/IDE says to Arduino "are you there?" your program will respond "yes!", just like an Arduino would.

默认的 Arduino 引导加载程序是 STK-500 兼容:这意味着它实现了 STK-500 命令 - 可以在 此处 找到其参考.如果您决定这样做,那么最简单的方法可能是从现有的引导加载程序开始,例如 ArduinoAdaFruit(有其他人),并修改它.这样的引导加载程序应该已经实现了所有命令,而且由于它是用 C 编写的(我不会选择要修改的程序集引导加载程序:),所以修改起来应该很容易.

The default Arduino bootloader is STK-500 compatible: that means that it implements STK-500 commands - the reference for which can be found here. If you decide to do this, then the easiest thing might be to start with an existing bootloader, such as Arduino's or AdaFruit's (there are others too), and modify it. Such a bootloader would have all the commands already implemented, and since it is written in C (I wouldn't choose an assembly bootloader to modify :), it should be easy enough to modify.

或者,您可能认为 STK-500 太难实施.如果是这种情况,您可以使用任何

Alternatively, you might decide that STK-500 is too difficult to implement. If this is the case, you can use any programmer protocol that Avrdude supports: Avrdude is a program for programming AVR chips, and Arduino IDE uses Avrdude internally to send the sketch to the Arduino. If you do this, then you'd have to change the settings in Arduino IDE for which programmer you are using.

就个人而言,我认为兼容 STK-500 是最好的选择,但 YMMV.

Personally, I think STK-500 compatible is the best option for this, but YMMV.

这篇关于通过Arduino IDE在虚拟串口上传Arduino代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆