# HG changeset patch # User Daniel O'Connor # Date 1511077093 -37800 # Node ID 787d9c8fdec6e89576f74e8d0a2c0dfe734a2493 # Parent 6d0fe22566abeb1d4e1c6fa1644d54b9861ba5cb Add working example when run as an exe diff -r 6d0fe22566ab -r 787d9c8fdec6 epro.py --- 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()