问题描述
我对Linux tty的经验不是很丰富.我的环境是带有大量USB串行接口的Raspbian.
有效方法:
stty -F/dev/ttyUSB0 38400cu -l/dev/ttyUSB0 -s 38400
将
cu
转换为/dev/ttyUSB0
即可.我可以在300毫秒内将命令写入终端,并从另一个终端获得响应.
什么不起作用:在一个终端中
echo"command">/dev/ttyUSB0
在另一个终端中(在回显之前运行)
cat</dev/ttyUSB0
或
tail -f/dev/ttyUSB0
没有输出.
但是当我 echo"command">/dev/ttyUSB0
并打开 cu
,我可以看到回显的命令以及那里另一个终端的响应.
我想念什么?
最诚挚的问候
Sundypha
ps:我也尝试过,是一个小的python脚本:
#!/usr/bin/python导入序列ser = serial.Serial('/dev/ttyUSB0',38400,xonxoff = True)ser.open()如果 ser.isOpen():ser.write('命令')响应= ser.readline()列印回应ser.close()
也不起作用,挂在ser.readline()
上如果在回显USB0设备时没有照顾到它,那么是的,您将不会看到它的输出,因为它已经消失了./p>
尝试类似的东西:
尾-f/dev/ttyUSB0
然后将内容回显到其中.
I'm not very experienced with the Linux tty's.My environment is a Raspbian with a prolific USB-serial.
What works:
stty -F /dev/ttyUSB0 38400
cu -l /dev/ttyUSB0 -s 38400
cu
to /dev/ttyUSB0
works. I can write my commands to the terminal and get response from the other terminal within 300ms.
What not works:in one terminal
echo "command" > /dev/ttyUSB0
in another terminal (running before echo)
cat < /dev/ttyUSB0
or
tail -f /dev/ttyUSB0
there is no output.
But when i echo "command" > /dev/ttyUSB0
and have cu
open, I can see the echoed command and the response from the other terminal there.
What am I missing?
best regards
Sundypha
ps: What I tried too, was a little python script:
#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttyUSB0', 38400, xonxoff=True)
ser.open()
if ser.isOpen():
ser.write('command')
response = ser.readline()
print response
ser.close()
did not work either, hangs on ser.readline()
If you are not cat'ing the USB0 device as you echo to it, then yes, you will not see its output because it has been and gone.
try something like:
tail -f /dev/ttyUSB0
and then echo stuff into it.
这篇关于从ttyUSB0写入和读取,无法获得响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!