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
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfkjka
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20