Bash 从 ttyUSB0 读取并发送到 URL

发布于 2024-10-16 17:10:01 字数 454 浏览 11 评论 0原文

我是一个 bash 新手,我正在努力将它们组合在一起。

我想做的是:

1)设置端口(stty)
2) 从 dev/ttyUSB0 读取 - 数据应类似于 000118110000101(cat 或 Gawk?)
3) 将读取的数据设置为变量(例如 DATA)并创建 URL,例如 http://domain.com/get_data .php?data=$DATA
4) 使用 wget 加载 URL?
5) 等待来自 ttyUSB0 的更多数据(轮询或循环?)

我尝试过 php DIO 扩展,它确实有效,但不可靠,因为它由于某种原因停止/启动。

任何建议将不胜感激,如果有人能建议最好的方法,我将非常感激,

谢谢

布伦特

I am a bash novice and I am struggling with putting it all together.

What I am trying to do is:

1) Set Port (stty)
2) Read from dev/ttyUSB0 - data should look like 000118110000101 (cat or Gawk?)
3) Set read data into a variable eg DATA and create a URL eg http://domain.com/get_data.php?data=$DATA
4) load the URL with wget?
5) Wait for more data from ttyUSB0 (polling or loop?)

I have tried the php DIO extention that does work but is not reliable because it stops/starts for some reason.

ANY suggestions would be much appreciated, I will be very great-full if anyone could advise the best way to do this

Thanks

Brent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独﹏钓一江月 2024-10-23 17:10:01

这就是我用的。

#Set permisions
sudo chmod o+rwx /dev/ttyUSB0


#!/bin/bash

# Port setting
stty -F /dev/ttyUSB0 cs7 cstopb -ixon raw speed 1200

# Loop
while [ 1 ]; 
do
    echo 'LOADING...'
    READ=`dd if=/dev/ttyUSB0 count=22 | sed 's/ //g'`
    echo $READ
    wget http://localhost/BASHtest/test.php?signal=$READ
    echo '[PRESS Ctrl + C TO EXIT]'
done

This is what I used.

#Set permisions
sudo chmod o+rwx /dev/ttyUSB0


#!/bin/bash

# Port setting
stty -F /dev/ttyUSB0 cs7 cstopb -ixon raw speed 1200

# Loop
while [ 1 ]; 
do
    echo 'LOADING...'
    READ=`dd if=/dev/ttyUSB0 count=22 | sed 's/ //g'`
    echo $READ
    wget http://localhost/BASHtest/test.php?signal=$READ
    echo '[PRESS Ctrl + C TO EXIT]'
done
过潦 2024-10-23 17:10:01

对于第一步,我建议读取一个文件,然后使用 od 来获取八进制(据我所知没有二进制)表示,因为标准 awk 不处理 NUL(我认为 gawk 也是如此)。因此,在获得字节后,您可以通过 sed 脚本将其通过管道将八进制更改为二进制,使用 $() (或撇号)获取输出并创建一个 URL,将其提供给 wget

我能看到的唯一问题是从 USB 读取阻塞/非阻塞。如果有请报告。

For the first step i would advise to read to a file and then use od to get an octal (there's no binary as far as i can see) representation, because standard awk doesn't cope with NULs (i think gawk too). So after you get the bytes, you pipe it through sed script to change octals to binaries, grab the output with $() (or apostrophs) and make an URL, which you feed to wget.

The only problem i can see is blocked/nonblocked read from usb. Please report if there will be one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文