annotate iec1107.py @ 7:8031548a5d48

Add some hardware notes.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 20 Nov 2013 23:26:45 +1030
parents b686ad203c1e
children 08b192a6e189
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
4
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
2 #
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
3 # Copyright (c) 2013
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
5 #
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
6 # Redistribution and use in source and binary forms, with or without
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
7 # modification, are permitted provided that the following conditions
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
8 # are met:
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
10 # notice, this list of conditions and the following disclaimer.
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
13 # documentation and/or other materials provided with the distribution.
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 #
4
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
25 # SUCH DAMAGE.
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
26 #
10a16898903d Add license.
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
27 # Most of this is derived from the extremely helpful post at
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 # http://www.domoticaforum.eu/viewtopic.php?f=71&t=7489
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 #
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30
3
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
31 import datetime
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 import exceptions
3
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
33 import re
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 import serial
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 import sys
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 import time
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 baudtable = {'0' : 300, '1' : 600, '2' : 1200, '3' : 2400, '4' : 4800, '5' : 9600, '6' : 19200}
3
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
39 parsere = re.compile('([0-9A-Z](\.[0-9A-Z]){1,})\((.*)\)')
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 class Error(exceptions.BaseException):
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 pass
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
44 class IEC1107Reading(object):
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
45 def __init__(self, port, force300bps = True):
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 # Open port
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
47 s = serial.Serial(port, baudrate = 300, bytesize = 7, parity = 'E', stopbits = 1)
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
48 s.timeout = 2.5
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 # Send ident message
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
51 s.write('/?!\r\n')
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
52 rtn = s.readline()
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
53 if len(rtn) == 0:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
54 raise Error('No reply to probe')
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 if len(rtn) < 6 or rtn[0] != '/' or rtn[-1] != '\n' or rtn[-2] != '\r':
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 raise Error('Invalid line "%s"' % (rtn))
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
57
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 rtn = rtn.strip()
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 self.mfg = rtn[1:4]
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 if self.mfg[2].isupper():
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 self.restime = 0.2
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 else:
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 self.restime = 0.02
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
66 if force300bps:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
67 self.baudid = '0'
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
68 else:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
69 self.baudid = rtn[4]
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 if self.baudid not in baudtable:
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 raise Error('Invalid baud rate %c from "%s"' % (selfbaudid, rtn))
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 else:
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 self.baud = baudtable[self.baudid]
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 if rtn[5] == '/':
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 self.mode = rtn[6]
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 self.mfg = rtn[7:]
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 else:
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 self.mode = None
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 self.mfg = rtn[5:]
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 # Send ACK/option message
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 # Byte Meaning
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 # 0 ACK (0x06)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 # 1 Protocol character ('0' = normal, '1' = secondary, '2' = HDLC protocol)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 # 2 Baud rate ID ('0', '1', etc)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 # 3 Mode control('0' = read data, '1' = device prog)
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
88 s.write('\x060%c0\r\n' % (self.baudid))
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 time.sleep(self.restime)
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
91 s.setBaudrate(self.baud)
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
92
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
93 lines = []
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
94 cksum = 0
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
96 # Read STX
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
97 head = s.read(1)
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
98 if len(head) == 0:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
99 raise Error('No reply to query')
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
100 if head != '\x02':
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
101 raise Error('Invalid reply header 0x%02x' % (ord(head)))
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
102
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
103 # Read result lines
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
104 while True:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
105 line = s.readline()
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
106 if len(line) == 0:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
107 raise Error('Timeout during message')
3
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
108
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
109 cksum ^= reduce(lambda x, y: x ^ y, map(ord, line))
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
110 if line.strip() == '!':
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
111 break
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
112 lines.append(line)
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
114 # Read trailer
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
115 fin = s.read(2)
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
116 if len(fin) != 2:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
117 raise Error('Timeout reading trailer')
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
118 if fin[0] != '\x03':
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
119 raise Error('Trailer malformed, expected 0x03, got 0x%02x' % (ord(fin[0])))
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
121 # Validate checksum
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
122 cksum ^= ord(fin[0])
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
123 if cksum != ord(fin[1]):
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
124 raise Error('Checksum mismatch, expected 0x%02x, got 0x%02x' % (cksum, ord(fin[1])))
2
8f1a773a3cd5 Don't strip lines to make printing easier.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
125 self.rawreading = lines
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
126 del s
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
127
3
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
128 self.parse()
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
129 self.readdate = datetime.datetime.now()
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
130
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
131 def parse(self):
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
132 for l in self.rawreading:
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
133 m = parsere.match(l)
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
134 if m == None:
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
135 raise Error('Unable to parse result \"%s\"' % (l))
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
136
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
137 (code, xxx, value) = m.groups()
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
138 if code == 'C.1':
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
139 self.meterid, date = value.split('(')
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
140 # XXX: The meter I have is an hour slow
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
141 self.meterdate = datetime.datetime.strptime(date, '%H:%M %d-%m-%y')
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
142 elif code == '1.8.0':
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
143 self.importWh = int(value[0:-3])
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
144 elif code[0:4] == '1.8.':
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
145 # Differing tarrifs which I don't care about
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
146 pass
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
147 elif code == '2.8.0':
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
148 self.exportWh = int(value[0:-3])
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
149 else:
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
150 print 'Unknown code', code
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
151
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
152 def __str__(self):
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
153 return 'Time: %s, Meter: %s, Import: %d Wh, Export: %d Wh' % (self.readdate.strftime('%Y/%m/%d %H:%M'),
535076e31660 Parse the result.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
154 self.meterid, self.importWh, self.exportWh)
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155 def main():
1
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
156 if len(sys.argv) != 2:
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
157 print 'Bad usage'
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
158 print '\t%s portname' % (sys.argv[0])
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
159 sys.exit(1)
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
160
99f25c8ab92f Make class version actually work, remove procedure.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
161 res = IEC1107Reading(sys.argv[1])
2
8f1a773a3cd5 Don't strip lines to make printing easier.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
162 print res
5
b686ad203c1e Don't print the raw value AND the parsed ones.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
163
0
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 if __name__ == '__main__':
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165 main()
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 # Meter number is 1288004
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 # 1.8.0 is import
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 # 1.8.1 is ??
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 # 1.8.2 is ??
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
171 # 1.8.3 is ??
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 # 2.8.0 is export
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 # C.1(12880041.0(22:25 18-11-13)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 # 1.8.1(0000000597*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176 # 1.8.2(0000000000*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 # 1.8.3(0000264238*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178 # 1.8.0(0000264835*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179 # 2.8.0(0000511354*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181 # ==> /?!<0D><0A>
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 # <== /ACE5SMLCD
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
183 # ==> <06>050<0D><0A>
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
184 # <== -- STX --
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 # <== C.1(12880041.0(22:48 18-11-13)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 # <== 1.8.1(0000000597*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 # <== 1.8.2(0000000000*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188 # <== 1.8.3(0000264460*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 # <== 1.8.0(0000265057*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190 # <== 2.8.0(0000511354*Wh)
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191 # <== !
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 # <== -- ETX --
fd8520d969c4 Initial commit, only readmeter function works
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
193 # <== -- BCC --