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

查看:106
本文介绍了如何将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程序.但是用纯外壳来做则比较棘手.您可能可以使用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天全站免登陆