changeset 12:0a571da65068

Use logging rather than print.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 06 Dec 2021 11:25:41 +1030
parents b4d6c6049024
children 4450cf739263
files epro.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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')