I'm trying to send data via serial port and receive the response. Currently I'm looping the interface physically to emulate the device. first I do:
# stty -F /dev/ttyUSB0 -echo
if I try to read after write, it doesn't print anything:
# echo "foo" > /dev/ttyUSB0; cat /dev/ttyUSB0
I have to fork the read before write to get the response.
# cat /dev/ttyUSB0 &
[1] 7881
# echo -ne "foo\xA\0"
foo
Is there a work around?
Thank you!
Assuming that you've got the correct read and write privileges for /dev/ttyUSB0. You simply need to have the echo
running on one terminal:
echo -ne 'foo\xA\0' > /dev/ttyUSB0
and the cat
running on another terminal (use the -v
option to make all characters readable):
cat -v /dev/ttyUSB0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.