Serial devices
Terminal devices, or Short TeleTypeWriter (TTY) are serial devices. Theses devices are located to /dev/tty*.
The file /proc/tty/driver/serial contains details of serial ports.
Configuration of Serial port
The stty command is used to configure serial communication.
To get current configuration of serial device.
stty -a -F /dev/ttyUSBS0
speed 115200 baud; rows 45; columns 169; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc ocrnl -onlcr -onocr onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
To set bitrate and suppress echo back to terminal of the tty device connection.
stty -F /dev/ttyUSBS0 115200 -echo
In a terminal window:
In a terminal window:
# Open a file for writing using a file descriptor
exec 4 > /dev/ttyUSB0
echo "data" >&4
echo ….
# close the file descriptor
exec 4>&-
Read received data
In a terminal window:
cat &4
# close the file descriptor
exec 4>&-