From c9b44b5bb6ad1ef293f5f03c6a22ce44a6f82dce Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 8 May 2017 10:29:59 -0400 Subject: [PATCH] serialhdl: Support working with pseudo serial devices Support working with devices that aren't really serial ports and thus do not have a baud rate. Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 6 +++++- klippy/serialhdl.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 71d58760..5d63af72 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -376,8 +376,12 @@ class MCU: def __init__(self, printer, config): self._printer = printer # Serial port - baud = config.getint('baud', 250000) self._serialport = config.get('serial', '/dev/ttyS0') + if self._serialport.startswith("/dev/rpmsg_"): + # Beaglbone PRU + baud = 0 + else: + baud = config.getint('baud', 250000, minval=2400) self.serial = serialhdl.SerialReader( printer.reactor, self._serialport, baud) self.is_shutdown = False diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index 35e2a135..85e3b80e 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -64,12 +64,17 @@ class SerialReader: while 1: starttime = self.reactor.monotonic() try: - self.ser = serial.Serial(self.serialport, self.baud, timeout=0) + if self.baud: + self.ser = serial.Serial( + self.serialport, self.baud, timeout=0) + else: + self.ser = open(self.serialport, 'rb+') except (OSError, serial.SerialException), e: logging.warn("Unable to open port: %s" % (e,)) self.reactor.pause(starttime + 5.) continue - stk500v2_leave(self.ser, self.reactor) + if self.baud: + stk500v2_leave(self.ser, self.reactor) self.serialqueue = self.ffi_lib.serialqueue_alloc( self.ser.fileno(), 0) self.background_thread = threading.Thread(target=self._bg_thread)