Help with script issue involving serial device
Dave Stevens
geek at uniserve.com
Wed Jun 22 23:43:42 UTC 2022
I have a IOT device that communicates with my Mint computer using a
UART as a level shifter, so 3.3V at the device becomes 5V at the USB
plug and socket. dmesg correctly shows the cp210x converter attached to
/dev/tty/USB0. I then copy incoming data from the device to a file
using cp and get meaningful data. The script looks like this
filename=$(date +%F%T)
touch $filename
cp dev/tty/USB0 $filename
The filename correctly reflects the file creation date and time, this
is the intended effect.
When I first ran the script I got occasional errors and I traced it
down to inadequate initialization of the serial port on my part. I
found I could run this commend to get reliable operation:
stty raw -R /dev/ttyUSB0 9600 cs8 -cstopb -parenb -ixon -ixoff
so the sequence was, run stty then the three line script and all is
good. The difficulty arose as soon as I inserted the stty command into
the script as the new line 1. Then the script fails to run. If I back
up to running the stty command standalone first then the three liner
works with no problems.
Can anyone see why this is? Not a dealbreaker but irritating.
Thanks,
Dave
--
Sometimes I wonder whether the world is being run by
smart people who are putting us on or by imbeciles who
really believe it.
Mark Twain
More information about the ubuntu-users
mailing list