• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Linux的串口监听器和跨preTER

用户头像
it1352
帮助1

问题说明

我使用的是串行设备的项目,我想要实现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?

感谢

正确答案

#1

这是你要找的?不是

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfkjka
系列文章
更多 icon
同类精品
更多 icon
继续加载