# HG changeset patch # User Daniel O'Connor # Date 1638752141 -37800 # Node ID 0a571da65068945c36890428da53aeb750313f73 # Parent b4d6c60490243cd3c029fc927f1e5d182c04513c Use logging rather than print. diff -r b4d6c6049024 -r 0a571da65068 epro.py --- a/epro.py Sun Dec 05 18:02:32 2021 +1030 +++ b/epro.py Mon Dec 06 11:25:41 2021 +1030 @@ -1,8 +1,11 @@ #!/usr/bin/env python +import logging import serial import sys +logger = logging.getLogger('epro') + # View facing ePro from the back # +---+ # +-| |-| @@ -223,13 +226,13 @@ for d in dat: d = ord(d) if d == 0xff and self.state != 4: - print "Packet corruption" + logger.warn("Packet corruption") continue if self.state == 0: # Waiting for destination address (MSB set but not 0xff as that is EOM) if d == 0xff or d & 0x80 == 0: - print "Skipping byte" + logger.info("Skipping byte") continue self.dstadr = d & 0x7f self.data = [] @@ -255,7 +258,7 @@ if self.msgtype in Processor.PKT_TYPES: t = self.PKT_TYPES[self.msgtype] if len(self.data) != t.LEN: - print "Packet length incorrect, expected %d got %d" % (t.LEN, len(self.data)) + logger.warn("Packet length incorrect, expected %d got %d", t.LEN, len(self.data)) continue p = self.PKT_TYPES[self.msgtype](self.dstadr, self.srcadr, self.devid, self.msgtype, self.data) @@ -268,7 +271,7 @@ def main(): if len(sys.argv) != 2: - print 'Bad usage' + print('Bad usage') exit(1) s = serial.Serial(sys.argv[1], 2400, parity='E')