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

查看:99
本文介绍了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天全站免登陆