Mercurial > code > home > repos > homeauto
view service/arduinoNode/loggingserial.py @ 1153:e4f49cd9dda3
add :pointsAtLeastEvery control
Ignore-this: 9d0236b56b2a7592211ca68b87b4a5d1
darcs-hash:76e4d358cb6b039351c9b6f8e3bb825aaaefcc57
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 15 Apr 2018 04:41:00 -0700 |
parents | 70a5392b24d3 |
children |
line wrap: on
line source
# forked from /my/proj/house/frontdoor/loggingserial.py import serial, logging log = logging.getLogger('serial') class LoggingSerial(object): """like serial.Serial, but logs all data""" def __init__(self, port=None, ports=None, baudrate=9600, timeout=10): if ports is None: ports = [port] for port in ports: try: log.info("trying port: %s" % port) self.ser = serial.Serial(port=port, baudrate=baudrate, timeout=timeout, xonxoff=0, rtscts=0) except serial.SerialException: pass if not hasattr(self, 'ser'): raise IOError("no port found") def flush(self): self.ser.flush() def close(self): self.ser.close() def write(self, s): log.info("Serial write: %r" % s) self.ser.write(s) def read(self, n, errorOnTimeout=True): buf = self.ser.read(n) log.info("Serial read: %r" % buf) if errorOnTimeout and n > 0 and len(buf) == 0: raise ValueError("timed out") return buf