是否可以在/dev/ttyUSB0接收数据时触发PHP或BASH脚本


Is it possible to trigger a PHP or BASH script when /dev/ttyUSB0 receives data?

我有一个连接到USB端口的设备,它每16秒传输一次信息。数据是十六进制的,看起来像这样:

10 00 00 00 00 00 00 00 12 80 07 08 00 05 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b2

当这些信息进入我的/dev/ttyUSB0时,我如何触发BASH或PHP(LAMP正在运行)?

一个解决方案是使用libnotice库。安装libnotify tools包,然后运行以下脚本。

while true
do    
    inotifywait -e CLOSE /dev/ttyUSB0 && run_the_command
done