comparison iec1107.py @ 2:8f1a773a3cd5

Don't strip lines to make printing easier.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 20 Nov 2013 13:16:56 +1030
parents 99f25c8ab92f
children 535076e31660
comparison
equal deleted inserted replaced
1:99f25c8ab92f 2:8f1a773a3cd5
75 75
76 # Read result lines 76 # Read result lines
77 while True: 77 while True:
78 line = s.readline() 78 line = s.readline()
79 cksum ^= reduce(lambda x, y: x ^ y, map(ord, line)) 79 cksum ^= reduce(lambda x, y: x ^ y, map(ord, line))
80 line = line.strip()
81 if len(line) == 0: 80 if len(line) == 0:
82 raise Error('Timeout during message') 81 raise Error('Timeout during message')
83 if line == '!': 82 if line == '!':
84 break 83 break
85 lines.append(line) 84 lines.append(line)
93 92
94 # Validate checksum 93 # Validate checksum
95 cksum ^= ord(fin[0]) 94 cksum ^= ord(fin[0])
96 if cksum != ord(fin[1]): 95 if cksum != ord(fin[1]):
97 raise Error('Checksum mismatch, expected 0x%02x, got 0x%02x' % (cksum, ord(fin[1]))) 96 raise Error('Checksum mismatch, expected 0x%02x, got 0x%02x' % (cksum, ord(fin[1])))
98 self.reading = lines 97 self.rawreading = lines
99 del s 98 del s
100 99
101 def main(): 100 def main():
102 if len(sys.argv) != 2: 101 if len(sys.argv) != 2:
103 print 'Bad usage' 102 print 'Bad usage'
104 print '\t%s portname' % (sys.argv[0]) 103 print '\t%s portname' % (sys.argv[0])
105 sys.exit(1) 104 sys.exit(1)
106 105
107 res = IEC1107Reading(sys.argv[1]) 106 res = IEC1107Reading(sys.argv[1])
108 print res.reading 107 map(sys.stdout.write, res.rawreading)
109 108 print res
110 if __name__ == '__main__': 109 if __name__ == '__main__':
111 main() 110 main()
112 111
113 # Meter number is 1288004 112 # Meter number is 1288004
114 # 1.8.0 is import 113 # 1.8.0 is import