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 <kevin@koconnor.net>
This commit is contained in:
parent
2255176228
commit
c9b44b5bb6
|
@ -376,8 +376,12 @@ class MCU:
|
||||||
def __init__(self, printer, config):
|
def __init__(self, printer, config):
|
||||||
self._printer = printer
|
self._printer = printer
|
||||||
# Serial port
|
# Serial port
|
||||||
baud = config.getint('baud', 250000)
|
|
||||||
self._serialport = config.get('serial', '/dev/ttyS0')
|
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(
|
self.serial = serialhdl.SerialReader(
|
||||||
printer.reactor, self._serialport, baud)
|
printer.reactor, self._serialport, baud)
|
||||||
self.is_shutdown = False
|
self.is_shutdown = False
|
||||||
|
|
|
@ -64,12 +64,17 @@ class SerialReader:
|
||||||
while 1:
|
while 1:
|
||||||
starttime = self.reactor.monotonic()
|
starttime = self.reactor.monotonic()
|
||||||
try:
|
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:
|
except (OSError, serial.SerialException), e:
|
||||||
logging.warn("Unable to open port: %s" % (e,))
|
logging.warn("Unable to open port: %s" % (e,))
|
||||||
self.reactor.pause(starttime + 5.)
|
self.reactor.pause(starttime + 5.)
|
||||||
continue
|
continue
|
||||||
stk500v2_leave(self.ser, self.reactor)
|
if self.baud:
|
||||||
|
stk500v2_leave(self.ser, self.reactor)
|
||||||
self.serialqueue = self.ffi_lib.serialqueue_alloc(
|
self.serialqueue = self.ffi_lib.serialqueue_alloc(
|
||||||
self.ser.fileno(), 0)
|
self.ser.fileno(), 0)
|
||||||
self.background_thread = threading.Thread(target=self._bg_thread)
|
self.background_thread = threading.Thread(target=self._bg_thread)
|
||||||
|
|
Loading…
Reference in New Issue