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

查看:1217
本文介绍了从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 '\x12\x02' > /dev/ttyS0

什么都没发生.

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

Can somebody please direct me to the right direction?

推荐答案

echo '\x12\x02'

将不被解释,并且将字面意义上将字符串\x12\x02(并添加换行符)写入指定的串行端口.改为使用

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

echo -n ^R^B

您可以在命令行上通过输入 Ctrl V Ctrl R Ctrl来构造

V Ctrl B .或者,使用编辑器键入脚本文件也更容易.

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天全站免登陆