Arduino 通过串口发送旧数据 [英] Arduino Sends Old Data Through Serial

查看:38
本文介绍了Arduino 通过串口发送旧数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的问题最好用一个例子来解释.这是一些 Arduino 代码:

I think my problem would best be explained with an example. Here is some Arduino Code:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(millis());
  delay(1);
}

...这是输出:

现在,开头的那些数字不仅仅是您通常的旧串行数据首字节总是乱七八糟的数字.这些数字是我上次打开串行监视器时遗留下来的.我怎么知道这个?因为我数了数自上次打开串口监视器已经过去了多少秒,结果都匹配了.

Now, those numbers at the beginning aren't just your regular old first-bytes-of-serial-data-are-always-messed-up numbers. Those numbers are left over from the last time I opened the serial monitor. How do I know this? Because I counted how many seconds had gone by since I last opened the serial monitor, and it all matched up.

所以这是一个大问题,

我该如何停止?它破坏了我的 Java 程序,该程序应该从 Arduino 的当前运行实例"(我不知道正确的术语)读取数据,而不是最后一个.

How do I make this stop? It's breaking my java program that's supposed to read data from the Arduino's current "run instance"(I don't know the correct term), and not the last one.

推荐答案

您的 Arduino 没有任何问题.请记住,USB 连接不是真正的 RS-232 串行接口,它是通过 USB 模拟的.而那个 USB 连接是由一个带有自己缓冲区的芯片控制的.

There is nothing wrong with your Arduino. Remember, the USB connection is not a real RS-232 serial interface, it's simulated through USB. And that USB connection is controlled by a chip with its own buffer.

坏消息是,如果您使用 USB 电缆传输 RS-232 信号,除了发送一些填充字符"来清除缓冲区之外,您无能为力.太多缓冲区无处不在:) 发送一些终端仿真命令,如清除屏幕"和换页"等,以清空缓冲区中的管道.

Bad news is, nothing you can do if you're using the USB cable to carry your RS-232 signals, other than to send some "filler characters" to purge the buffer. Too many buffers everywhere :) Send some terminal emulation commands like "clear the screen" and "form feed" etc. to empty the pipeline of stuff in the buffer.

这让我想起了——我们都应该停止使用糟糕的 Arduino 串行监视器并直言不讳.相反,请使用 TeraTerm 或 Putty 或您选择的任何其他优质终端模拟器.

Which reminds me -- we should all quit using the crummy Arduino serial monitor and be vocal about it. Instead, use TeraTerm or Putty or any other good-quality terminal emulator of your choice.

或者连接真正的 RS232 和一个适配器和电缆.我的开发机器有三个串口,但这就是我所做的.现在的计算机常常连一个手头都没有.

Or connect with real RS232 and an adapter and cable. My development machine has three serial ports, but that's what I do. Often computers today don't even have one handy.

这篇关于Arduino 通过串口发送旧数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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