简体   繁体   English

使用bash和raspberry pi 3从USB设备读取数据?

[英]Reading from a USB device using bash and raspberry pi 3?

I'm trying to catch the response from a device that is connected to the USB. 我正在尝试从连接到USB的设备上捕获响应。 With this code: 使用此代码:

sudo stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb -echo
sudo stty raw; cat > /home/received.log < /dev/ttyUSB0
echo "Monitor started"

On port ready, send the command request to the device 在端口就绪后,将命令请求发送到设备

echo -en '\x5A\x00\x00\x0D\x0A\x71' > /dev/ttyUSB0

then read the log and paste the response in another file converting it properly xxd -plain /home/received.log > /home/output.txt 然后阅读日志,并将响应粘贴到另一个将其正确转换的文件中xxd -plain /home/received.log> /home/output.txt

so I can show the data, cat -v < /home/output.txt 所以我可以显示数据,cat -v </home/output.txt

But I'm needing something more stable, that code is showing me this error: 但是我需要更稳定的东西,该代码向我显示此错误:

stty: 'standard input': Inappropriate ioctl for device

which is weird, because it was working... 这很奇怪,因为它正在工作...

I would like to catch the response and store it in a variable. 我想捕获响应并将其存储在变量中。

i suggest getting rid of the stty raw . 我建议摆脱stty raw

Unless you are sending/receiving special characters that the tty subsystem will process, which is unlikely - because you said it is working - you almost certainly won't need it. 除非您发送/接收tty子系统将要处理的特殊字符,否则这不太可能-因为您说它正在工作-几乎可以肯定不需要它。

If it did work, you might find some undesirable side effects such as: 如果确实有效,您可能会发现一些不良副作用,例如:

  • backspace does not erase a character that you miss-typed 退格键不会删除您错过键入的字符
  • control-c won't terminate your process control-c不会终止您的进程

and other things that you might rely on in your terminal session. 以及终端会话中可能依赖的其他内容。

FWIW, i am doing a similar thing with Arduino to Mac, Windows (cygwin) & Linux (read from the usb/serial port) and i have not been tempted to stty raw in any of those environments. FWIW,我做与Arduino的类似的事情在Mac,Windows(Cygwin的)和Linux(从USB /串口读取),我还没有被诱惑stty raw在任何这些环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM