Bash、串行 I/O 和 Arduino [英] Bash, serial I/O and Arduino

查看:25
本文介绍了Bash、串行 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 OS X 10.6 中运行),它们将 (a) 打印来自 Arduino 单元的所有串行数据到标准输出,以及 (b) 允许我将串行数据发送到 Arduino 单元.然后将使用 Adob​​e AIR 的 NativeProcess API 调用这些脚本,以允许 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.

我的两个脚本很简单-

这是我的 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 控制台中输入命令),我的计算机就会挂起 - 我可以输入字符,但是直到我 Ctrl +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 并打开串行监视器,然后 tail -f 端口,关闭串行监视器,然后 echo "test" > 串行端口,一切正常很棒.

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.

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

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