如何将一系列 AT 命令发送到 bash 中的串行端口? [英] How to send a sequence of AT commands to a serial port in bash?

查看:29
本文介绍了如何将一系列 AT 命令发送到 bash 中的串行端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux 中,我需要将一系列 AT 命令发送到串行端口,例如/dev/ttyS0,在发送下一个命令之前必须等待 OK 回答.我可以想象做类似的事情

In Linux I need to send a sequence of AT commands to a serial port on e.g. /dev/ttyS0, which has to wait for an OK answer before the next command is sent. I could imagine doing something like

echo 'AT' > /dev/ttyS0
echo 'ATS0=0' > dev/ttyS0
...

但这不会评估来自该端口上的设备的答案.

but this does not evaluate the answer from the device on that port.

是否有一种非常的方法可以在 bash 脚本中自动化,可能在 socat 和/或 的帮助下microcom 但没有在最简单的linux系统上找不到的工具.

Is there a very simple way to automate this within a bash script, probably with the help of socat and/or microcom but no tools which cannot found on the most simple linux system.

推荐答案

如果您安装了 PPP 包,您可以使用它附带的 chat 程序.或者你可以使用 kermit.或者uucp自带的cu程序.但是用纯 shell 来做这件事比较棘手.您可以使用 read 和 printf 函数,并将 stdio 重定向到端口.

If you install the PPP package you can use the chat program that comes with it. Or you can use kermit. Or the cu program that comes with uucp. But to do it with pure shell is trickier. You might be able to use the read and printf functions, with stdio redirected to the port.

一些片段:

stty -F /dev/ttyS0 38400 raw
chat -f script.txt < /dev/ttyS0 > /dev/ttyS0

应该让你开始.

这篇关于如何将一系列 AT 命令发送到 bash 中的串行端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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