====== Possible alternatives for virtual serial ports ======
* Pseudo teletype -- Linux C programming
* socat -- Command
* fuse -- Filesystem in userspace
* named pipes -- Heave data between processes One-way
^ Method ^ Description ^ Pros ^ Cons ^ Dependencies ^
| pty | Virtual terminal device | Full duplex | Must create links to name them | native |
| socat | Multipurpose relay | Super flexible | External program.\\ Maybe less control | socat |
| fuse | Filesystem in userspace | ?? | ???? | libfuse-dev |
| fifo | Named pipes | Simple | One-way only | native |
====== Scratchpad ======
[[https://www.gnu.org/software/libc/manual/pdf/libc.pdf|glibc manual]] -- Innehåller massa bra info!
[[https://linux.die.net/man/3/termios|termios man page]]
[[https://linux.die.net/man/4/tty_ioctl|tty_ioctl man page]]
[[http://kirste.userpage.fu-berlin.de/chemnet/use/info/libc/libc_12.html#SEC237|Seting up terminals]]
[[https://www.cmrr.umn.edu/~strupp/serial.html|Serial programming guide for posix]]
errno
termios
tcgetattr
cfsetospeed
cfsetispeed
tcsetattr
posix_openpt
ioctl_tty
Använd noncanonical input processing mode för att kunna styra RTS och DTR
termios.h är en grej
#include
#include
#include
#include
#include
gör open på porten
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
Get info:
$ dmesg | egrep --color 'serial|ttyS'
Some commands to manage, read and write to the serial port
# Print info
$ setserial -g /dev/ttyS0
# Using cu (call-up). Exit by typing ~.
$ cu -l /dev/ttyS0 -s 115200
# Using screen. Exit with c-a k
$ screen /dev/ttyS0 115200
# Read current configuration using stty
$ stty -a < /dev/ttyS0
# or
$ stty -a -F=/dev/ttyS0
# Set baud rate and hardware flow control using stty
$ stty -F=/dev/ttyS0 9600 crtscts ixon
[[https://man7.org/linux/man-pages/man2/poll.2.html|Polla för satan!]]
[[https://man7.org/linux/man-pages/man7/signal.7.html|Läs på om signaler!]]
====== Serial port basics ======
{{ :linux:serial.jpg?400|}}
|DTE | Data terminal equipment (computer/MCU) |
|DCE | Data circuit-terminating equipment (modem/device) |
|RTS | Request to send |
|CTS | Clear to send |
|DTR | Data terminal ready |
|DSR | Data set ready |
{{:linux:db9-pinout.gif?400 |}}
====== Accessing a serial port ======
====== Pseudo teletype ======