猛砸,串行I / O和Arduino的 [英] Bash, serial I/O and Arduino

查看:241
本文介绍了猛砸,串行I / O和Arduino的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在一个有点过我的头,我觉得我非常接近一个解决方案,但它只是不工作相当尚未。这里是我的情况:

So, I'm in a bit over my head, and I feel like I'm very close to a solution, but it's just not working quite yet. Here's my situation:

我与一个Arduino微控制器的工作,而我试图写两个的bash脚本(目前已经在Mac和NBSP运行; OS  X 10.6),将(一)打印所有串行数据出来Arduino的单元来标准输出,以及(b)请允许我为串行数据发送到Arduino单位。这些脚本将被使用的Adobe AIR的API的NativeProcess允许Arduino的单元和一个Flex 的Adobe AIR 应用程序之间的紧密集成称为

I'm working with an Arduino microcontroller, and I'm attempting to write two Bash scripts (right now running in Mac OS X 10.6) which will (a) print all serial data coming out of the Arduino unit to the standard output, and (b) allow me to send serial data to the Arduino unit. These scripts will then be called using Adobe AIR's NativeProcess API to allow a tight integration between the Arduino unit and a Flex Adobe AIR application.

我的两个脚本是非常简单的 -

My two scripts are very simple -

下面是我的WriteToSerial.sh脚本:

Here's my WriteToSerial.sh script:

echo $1 > $2

($ 1显然我的字符串,$ 2是串行端口的位置 - 目前/dev/tty.usbserial-A800eIUj)

($1 is obviously my string, $2 is the location of the serial port - currently /dev/tty.usbserial-A800eIUj)

这是我的ReadSerialOutput.sh脚本:

And here's my ReadSerialOutput.sh script:

tail -f $1

($ 1是我的串行口,目前/dev/tty.usbserial-A800eIUj的位置)

($1 is the location of my serial port, currently /dev/tty.usbserial-A800eIUj)

当我把其中任何一个脚本(或者即使我只需要直接键入命令到Bash的控制台),我的电脑只是挂起 - 我可以输入文字,但没有任何反应,直到我<大骨节病>控制 + <大骨节病> C 出来的过程。

When I call either of these scripts (or even if I just type the commands directly into the Bash console), my computer just hangs - I can type characters, but nothing happens until I Ctrl + C out of the process.

不过,如果我打开Arduino的IDE,并打开串行监视器,那么<​​code>尾-f 端口,关闭串口监视器,然后回声测试>串行端口,一切工作好了。

However, if I open the Arduino IDE and turn on the Serial Monitor, then tail -f the port, close the serial monitor, and then echo "test" > serial port, everything works just great.

这个建议,我认为在Arduino的IDE中打开串口监视器以某种方式初始化串口,这反过来又使我没有问题的尾巴了。这反过来建议,我认为我只是未能输入一些初始化命令的。不过,我一直在寻找高和低的天,似乎无法找到任何解决了这个问题。

This suggests to me that opening the Serial Monitor within the Arduino IDE is somehow initializing the serial port, which in turn allows me to tail it with no problem. This in turn suggests to me that I'm simply failing to input some sort of initialization command. However, I've been searching high and low for days and can't seem to find anything that addresses this issue.

如何解决?

推荐答案

请尝试使用工具的stty

stty -F /dev/my_serial_port <baud_rate> cs8 cread clocal

像往常一样,将上述前阅读手册页。 CREAD ,您可以接收数据。你可能想省略 CLOCAL 如果您正在使用的流量控制。如果你不知道上面的设置是什么,问了,我可以写一个更完整的答案。

As always, read the manpage before applying the above. cread allows you to receive data. You may want to omit clocal if you are using flow control. If you aren't sure what the above settings are, ask, and I can write up a more complete answer.

这篇关于猛砸,串行I / O和Arduino的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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