从linux命令行写入串口 [英] writing to serial port from linux command line

查看:22
本文介绍了从linux命令行写入串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 windows 中,我可以使用以下命令与串行端口设备通信:

From windows I can communicate with a serial port device using following commands:

mode com1: baud=9600 data=8 parity=n stop=1
copy con com1
alt+18alt+2ctrl+z

设备开始请求的操作.

当我尝试从独立的 debian 机器或从同一台 Windows 机器的 debian virtualbox 实例完成相同的操作时,到目前为止我没有运气.

When I try to accomplish the same operation from a stand alone debian box or from a debian virtualbox instance of the same windows machine, I had no luck so far.

这是等效的 linux 命令(至少我是这么认为的)

Here's equivalent linux commands(at least I think so)

stty -F /dev/ttyS0 speed 9600 cs8 -cstopb -parenb
echo 'x12x02' > /dev/ttyS0

什么都没有发生.

有人可以指导我正确的方向吗?

Can somebody please direct me to the right direction?

推荐答案

echo 'x12x02'

不会被解释,而是将字符串 x12x02 (并附加一个换行符)写入指定的串行端口.而是使用

will not be interpreted, and will literally write the string x12x02 (and append a newline) to the specified serial port. Instead use

echo -n ^R^B

你可以在命令行上输入 CtrlVCtrlRCtrlVCtrlB.或者使用编辑器输入脚本文件更容易.

which you can construct on the command line by typing CtrlVCtrlR and CtrlVCtrlB. Or it is easier to use an editor to type into a script file.

stty 命令应该可以工作,除非有其他程序干扰.一个常见的罪魁祸首是 gpsd,它会查找正在插入的 GPS 设备.

The stty command should work, unless another program is interfering. A common culprit is gpsd which looks for GPS devices being plugged in.

这篇关于从linux命令行写入串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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