User Tools

Site Tools


linux:serial_ports

This is an old revision of the document!


Possible alternatives for virtual serial ports

  • Pseudo teletype – Linux C programming
  • socat – Command
  • fuse – Filesystem in userspace
  • named pipes – Heave data between processes

Scratchpad

termios man page

tty_ioctl man page

Seting up terminals

Serial programming guide for posix

errno
termios
tcgetattr 
cfsetospeed 
cfsetispeed 
tcsetattr 
posix_openpt
ioctl_tty

Använd noncanonical input processing mode

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.1601621342.txt.gz · Last modified: 2022/09/12 00:30 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki