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:)

1 Answer 1

9

try

stty -F /dev/ttyS0 cs7 cstopb -ixon raw speed 1200
5
  • 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, 2014 at 10:22
  • 1
    @SF. what resources would you recommend (sorry to ask that nearly 7 years later...)
    – Tom
    Dec 4, 2020 at 19:04
  • @TomS. Asking on StackOverflow. :-/
    – SF.
    Dec 4, 2020 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 Mar 17, 2021 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, 2021 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.