6

Im trying to use bash to read from ttyS0 and need to set the following but im struggling to figure it out

databits = 7
stopbits = 2
parity = 0
flow control = 0

heres my code:

#!/bin/bash

# Port setting
stty -F /dev/ttyS0 raw speed 1200

# Loop
while [ 1 ]; 
do
    echo 'LOADING...'
    READ=`dd if=/dev/ttyS0 count=1`
    echo $READ


echo '[PRESS Ctrl + C TO EXIT]'
done

The script is working but I need to set the parameters. Any suggestions? And thanks:)

afro360
  • 620
  • 3
  • 9
  • 22

1 Answers1

9

try

stty -F /dev/ttyS0 cs7 cstopb -ixon raw speed 1200
Ortwin Angermeier
  • 5,957
  • 2
  • 34
  • 34
  • 21
    Allow me to disagree, `man stty` is a terrible reference, things that matter buried between tons of insignificant junk that might have mattered 50 years ago, and essential entries referenced elsewhere defined in non-searchable way (there's no entry for `cs8`, just `csN`). Sending people to `man stty` is just as bad as sending people wanting to unpack archive to `man tar` was until recently (with its tape sizes, tape-changing etc) – SF. Feb 28 '14 at 10:22
  • 1
    @SF. what resources would you recommend (sorry to ask that nearly 7 years later...) – Tom Dec 04 '20 at 19:04
  • @TomS. Asking on StackOverflow. :-/ – SF. Dec 04 '20 at 23:57
  • @SF. well you could have answered here as well in the comments, or at least show a stackexchange relevant answer... saying a tool is not working (when in fact still does) and not providing reference to a replacement it not helpful at all! and yes, if you want to unpack a `tar` file you would still have to read the `tar` manual page in 2021... and tapes are still the most long life storage choice – Costin Gușă Mar 17 '21 at 14:40
  • @CostinGușă The answer provided here is correct for the stated problem. If I *knew* a better source or explanation, I'd surely post it. The answer before edit contained `man stty is a good reference.` which was the part I disagreed with. – SF. Mar 17 '21 at 14:53