Skip to content

Instantly share code, notes, and snippets.

Created Jan 29, 2021
What would you like to do?
import serial
class Sender:
TERMINATOR = '\r'.encode('UTF8')
def __init__(self, device='/dev/ttyACM0', baud=9600, timeout=1):
self.serial = serial.Serial(device, baud, timeout=timeout)
def receive(self) -> str:
line = self.serial.read_until(self.TERMINATOR)
return line.decode('UTF8').strip()
def send(self, text: str) -> bool:
line = '%s\r\f' % text
# the line should be echoed.
# If it isn't, something is wrong.
return text == self.receive()
def close(self):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment