linux:serial_ports
Table of Contents
Possible alternatives for virtual serial ports
- Pseudo teletype – Linux C programming
- socat – Command
- fuse – Filesystem in userspace
named pipes – Heave data between processes<color #ed1c24>One-way</color>
| 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
glibc manual – Innehåller massa bra info!
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 <errno.h> #include <fcntl.h> #include <string.h> #include <termios.h> #include <unistd.h> 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
Serial port basics
| 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 |
Accessing a serial port
Pseudo teletype
linux/serial_ports.txt · Last modified: 2022/09/12 00:30 by 127.0.0.1


