You are on page 1of 1

Tinkering → Asyncserial

https://tinkering.xyz/async-serial/

Virtual serial ports with socat

Create a pair of virtual serial ports


socat -d -d -v pty, rawer, echo=0,link=./reader pty,rawer,echo=0,link=./writer

 -d -d specifies the logging level.


 -v writes the data sent to each device to the terminal.
 ptyspecifies that the device should be a pseudoterminal.

socat creates two virtual serial ports in /dev/ that are connected to one another.
link=<path> creates a symlink at <path> to the device in /dev/
Two symlinks located at ./reader and ./writer
Options of socat
http://www.dest-unreach.org/socat/doc/socat.html

Synchronous serial communication

from serial import Serial

ser = Serial(‘/dev/ttysomething’, baudrate=9600, timeout=0.5)


ser.write(b’foo’)
ser.read(num_bytes)

Create a Serial object by telling it which device to connect to and how the connection should be
configured. Once you have the Serial object you can send or receive bytes from the serial port via
the Serial.write and Serial.read methods respectively. To create a class you can just pass the Serial
object into the constructor.

You might also like