changeset 4:787d9c8fdec6

Add working example when run as an exe
author Daniel O'Connor <darius@dons.net.au>
date Sun, 19 Nov 2017 18:08:13 +1030
parents 6d0fe22566ab
children 982eeffe9d95
files epro.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/epro.py	Sun Nov 19 18:07:55 2017 +1030
+++ b/epro.py	Sun Nov 19 18:08:13 2017 +1030
@@ -1,5 +1,8 @@
 #!/usr/bin/env python
 
+import serial
+import sys
+
 # View facing ePro from the back
 #   +---+
 # +-|   |-|
@@ -216,6 +219,7 @@
         self.packets = []
 
     def process(self, dat):
+        added = False
         for d in dat:
             d = ord(d)
             if d == 0xff and self.state != 4:
@@ -258,8 +262,23 @@
                 else:
                     p = Packet(self.dstadr, self.srcadr, self.devid, self.msgtype, self.data)
 
-                print p
                 self.packets.append(p)
+                added = True
+        return added
+
+def main():
+    if len(sys.argv) != 2:
+        print 'Bad usage'
+        exit(1)
+
+    s = serial.Serial(sys.argv[1], 2400, parity='E')
+    s.timeout = 0.2
+
+    p = Processor()
+    while True:
+        res = p.process(s.read(1024))
+        while len(p.packets) > 0:
+            print(p.packets.pop(0))
 
 if __name__ == '__main__':
     main()