Linux的串口监听器和跨preTER? [英] Linux serial port listener and interpreter?

查看:120
本文介绍了Linux的串口监听器和跨preTER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是串行设备的项目,我想要实现PC端,监听由串行设备,除preting查询发送的命令,运行某些code根据查询,并发送回结果

I'm using a serial device for a project, and what I'm trying to accomplish PC side, is listening for a command sent by the serial device, interpreting the query, running some code depending on the query, and transmitting back the result.

说实话,我尝试了使用PHP作为监听器,和它的作品,遗憾的是使脚本充当接收器所需的无限循环,加载CPU到25%。因此,它不是真正的最好的选择。

To be honest I tried out using PHP as the listener, and it works, unfortunately the infinite loop required to make the script act as a receiver, loads the CPU to 25%. So it's not really the best option.

我用cygwin的,现在,我想使用Linux的本机命令来创建一个bash脚本。

I'm using cygwin right now, I'd like to create a bash script using linux native commands.

我可以用接收数据:

cat /dev/ttyS2

和发送响应与:

echo "command to send" > /dev/ttyS2

我的问题是,如何让我的听众自动给能够接收和发送数据?主要的问题我也有,其实是我该如何停止在猫的/ dev / ttyS2 命令,一旦接收到信息,把它放入,然后我可以用一个开关,或一系列的,如果比较的变量否则会阻塞。之后发回的响应,并从头开始循环?

My question is, how do I make an automated listener to be able to receive and send data? The main issue I have, is actually how do I stop the cat /dev/ttyS2 command once information was received, put it into a variable which then I could compare with a switch, or a series of if else then blocks. Afterwards send back a response and start the cycle all over again?

感谢

推荐答案

这是你要找的?不是

while read -r line < /dev/ttyS2; do
  # $line is the line read, do something with it
  echo $result > /dev/ttyS2
done

这篇关于Linux的串口监听器和跨preTER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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