Comments (4)
I think that i need to decode b before comparing b.decode('iso-8859-1')
from iec62056-21.
still no luck :(
from iec62056-21.
Hi.
I am assuming you are trying to read the meter over TCP.
It looks like the modem on the meter is not transforming the bytes received to the correct byte representation.
This is common on meters with integrated modems using IEC62056-21. They just slapped on a modem and connected it to the normal serial input.
So normal IEC 62056-21 over serial line uses 7E1 byte representation. 7 bits for the data, even parity and 1 stopbit.
See the code for the SerialTransport:
self.port = serial.Serial(
self.port_name,
baudrate=baudrate,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
writeTimeout=0,
timeout=self.timeout / 2,
rtscts=False,
dsrdtr=False,
xonxoff=False,
)
When we send it over TCP all 8 bits are used and are pushed out on the serial line, independent of the parity.
So to correct this you need to recalculate how the data should look like on the serial line and then send those bytes.
And when you receive data it will have the parity bit, that you need to remove.
I did this a while back ago for an EMH meter:
def remove_parity(input):
"""Function that converts 8bit byte string into 7bit byte string by removing the parity bit"""
data_list = []
for byte in input:
temp = byte & 0x7f
temp = chr(temp).encode('latin-1')
data_list.append(temp)
return b''.join(data_list)
def add_parity(input_string):
"""Function to add (even) parity to a string of hex byte representations.
For example '2f 3f 37 30' -> 'af 3f b7 30'.
"""
output = [] # Create empty list for output
for x in input_string: # Loop through all bytes in input_string
nonzero_bit_count = bin(x).count('1') # Count non-zero bits (i.e. 1s)
if nonzero_bit_count % 2 is 1: # If uneven amount of bits, parity is needed
temp = x | 0x80 # Add parity using bitwise OR with 0x80 (1000 000)
output.append(chr(temp))
else: # Parity bit not needed
output.append(chr(x)) # Byte is added unchanged
output_string = ''.join(output) # Converts list to string
return output_string.encode('latin-1')
The code is quite old and not fully functional with the state of the library as it is now. But I would recommend that you subclass the TcpTransport or BaseTransport and add this rewriting of the bytes as you send and receives.
If i run the data you have gotten:
print(remove_parity(data).decode('latin-1'))
I get:
/LGZ5\2ZMD4054459.B40
�F.F(00000000)
0.9.1(23:16:43)
0.9.2(21-01-04)
0.0.0()
C.1.0(54800102)
C.90.1(54800102)
C.90.2(01102)
0.2.2(B21)
0.1.0(04)
0.1.0*12(21-01-01 00:00)
0.1.0&12(20-12-30 16:02)
0.1.0*00(00-00-00 00:00)
0.1.0*00(00-00-00 00:00)
0.1.2(00:00)
0.1.3(21-01-01)
1.8.1(0302.8260*kWh)
1.8.1*12(0075.5341*kWh)
1.8.1&12(0000.0000*kWh)
1.8.1*00(0000.0000*kWh)
1.8.1*00(0000.0000*kWh)
1.8.2(0000.0000*kWh)
1.8.2*12(0000.0000*kWh)
1.8.2&12(0000.0000*kWh)
1.8.2*00(0000.0000*kWh)
1.8.2*00(0000.0000*kWh)
1.8.3(0000.0000*kWh)
1.8.3*12(0000.0000*kWh)
1.8.3&12(0000.0000*kWh)
1.8.3*00(0000.0000*kWh)
1.8.3*00(0000.0000*kWh)
1.8.0(0302.8260*kWh)
1.8.0*12(0075.5341*kWh)
1.8.0&12(0000.0000*kWh)
1.8.0*00(0000.0000*kWh)
1.8.0*00(0000.0000*kWh)
2.8.1(0000.0000*kWh)
2.8.1*12(0000.0000*kWh)
2.8.1&12(0000.0000*kWh)
2.8.1*00(0000.0000*kWh)
2.8.1*00(0000.0000*kWh)
2.8.2(0000.0000*kWh)
2.8.2*12(0000.0000*kWh)
2.8.2&12(0000.0000*kWh)
2.8.2*00(0000.0000*kWh)
2.8.2*00(0000.0000*kWh)
2.8.3(0000.0000*kWh)
2.8.3*12(0000.0000*kWh)
2.8.3&12(0000.0000*kWh)
2.8.3*00(0000.0000*kWh)
2.8.3*00(0000.0000*kWh)
2.8.0(0000.0000*kWh)
2.8.0*12(0000.0000*kWh)
2.8.0&12(0000.0000*kWh)
2.8.0*00(0000.0000*kWh)
2.8.0*00(0000.0000*kWh)
5.8.1(0064.3714*kvarh)
5.8.1*12(0016.0599*kvarh)
5.8.1&12(0000.0000*kvarh)
5.8.1*00(0000.0000*kvarh)
5.8.1*00(0000.0000*kvarh)
5.8.2(0000.0000*kvarh)
5.8.2*12(0000.0000*kvarh)
5.8.2&12(0000.0000*kvarh)
5.8.2*00(0000.0000*kvarh)
5.8.2*00(0000.0000*kvarh)
5.8.3(0000.0000*kvarh)
5.8.3*12(0000.0000*kvarh)
5.8.3&12(0000.0000*kvarh)
5.8.3*00(0000.0000*kvarh)
5.8.3*00(0000.0000*kvarh)
5.8.0(0064.3714*kvarh)
5.8.0*12(0016.0599*kvarh)
5.8.0&12(0000.0000*kvarh)
5.8.0*00(0000.0000*kvarh)
5.8.0*00(0000.0000*kvarh)
6.8.1(0000.0004*kvarh)
6.8.1*12(0000.0004*kvarh)
6.8.1&12(0000.0000*kvarh)
6.8.1*00(0000.0000*kvarh)
6.8.1*00(0000.0000*kvarh)
6.8.2(0000.0000*kvarh)
6.8.2*12(0000.0000*kvarh)
6.8.2&12(0000.0000*kvarh)
6.8.2*00(0000.0000*kvarh)
6.8.2*00(0000.0000*kvarh)
6.8.3(0000.0000*kvarh)
6.8.3*12(0000.0000*kvarh)
6.8.3&12(0000.0000*kvarh)
6.8.3*00(0000.0000*kvarh)
6.8.3*00(0000.0000*kvarh)
6.8.0(0000.0004*kvarh)
6.8.0*12(0000.0004*kvarh)
6.8.0&12(0000.0000*kvarh)
6.8.0*00(0000.0000*kvarh)
6.8.0*00(0000.0000*kvarh)
7.8.1(0000.0000*kvarh)
7.8.1*12(0000.0000*kvarh)
7.8.1&12(0000.0000*kvarh)
7.8.1*00(0000.0000*kvarh)
7.8.1*00(0000.0000*kvarh)
7.8.2(0000.0000*kvarh)
7.8.2*12(0000.0000*kvarh)
7.8.2&12(0000.0000*kvarh)
7.8.2*00(0000.0000*kvarh)
7.8.2*00(0000.0000*kvarh)
7.8.3(0000.0000*kvarh)
7.8.3*12(0000.0000*kvarh)
7.8.3&12(0000.0000*kvarh)
7.8.3*00(0000.0000*kvarh)
7.8.3*00(0000.0000*kvarh)
7.8.0(0000.0000*kvarh)
7.8.0*12(0000.0000*kvarh)
7.8.0&12(0000.0000*kvarh)
7.8.0*00(0000.0000*kvarh)
7.8.0*00(0000.0000*kvarh)
8.8.1(0000.0000*kvarh)
8.8.1*12(0000.0000*kvarh)
8.8.1&12(0000.0000*kvarh)
8.8.1*00(0000.0000*kvarh)
8.8.1*00(0000.0000*kvarh)
8.8.2(0000.0000*kvarh)
8.8.2*12(0000.0000*kvarh)
8.8.2&12(0000.0000*kvarh)
8.8.2*00(0000.0000*kvarh)
8.8.2*00(0000.0000*kvarh)
8.8.3(0000.0000*kvarh)
8.8.3*12(0000.0000*kvarh)
8.8.3&12(0000.0000*kvarh)
8.8.3*00(0000.0000*kvarh)
8.8.3*00(0000.0000*kvarh)
8.8.0(0000.0000*kvarh)
8.8.0*12(0000.0000*kvarh)
8.8.0&12(0000.0000*kvarh)
8.8.0*00(0000.0000*kvarh)
8.8.0*00(0000.0000*kvarh)
1.6.0(2.3966*kW)(21-01-03 11:45)
1.6.0*12(2.3939*kW)(20-12-31 20:15)
1.6.0&12(0.0000*kW)(00-00-00 00:00)
1.6.0*00(0.0000*kW)(00-00-00 00:00)
1.6.0*00(0.0000*kW)(00-00-00 00:00)
2.6.0(0.0000*kW)(00-00-00 00:00)
2.6.0*12(0.0001*kW)(20-12-30 16:13)
2.6.0&12(0.0000*kW)(00-00-00 00:00)
2.6.0*00(0.0000*kW)(00-00-00 00:00)
2.6.0*00(0.0000*kW)(00-00-00 00:00)
83.8.1(0000.4450*kWh)
83.8.1*12(0000.1108*kWh)
83.8.1&12(0000.0000*kWh)
83.8.1*00(0000.0000*kWh)
83.8.1*00(0000.0000*kWh)
83.8.4(0000.2163*kWh)
83.8.4*12(0000.0540*kWh)
83.8.4&12(0000.0000*kWh)
83.8.4*00(0000.0000*kWh)
83.8.4*00(0000.0000*kWh)
83.8.2(0000.0000*kWh)
83.8.2*12(0000.0000*kWh)
83.8.2&12(0000.0000*kWh)
83.8.2*00(0000.0000*kWh)
83.8.2*00(0000.0000*kWh)
83.8.5(0000.0000*kWh)
83.8.5*12(0000.0000*kWh)
83.8.5&12(0000.0000*kWh)
83.8.5*00(0000.0000*kWh)
83.8.5*00(0000.0000*kWh)
83.8.20(0004.4504*kWh)
83.8.20*12(0001.1089*kWh)
83.8.20&12(0000.0000*kWh)
83.8.20*00(0000.0000*kWh)
83.8.20*00(0000.0000*kWh)
83.8.19(0000.0216*kWh)
83.8.19*12(0000.0054*kWh)
83.8.19&12(0000.0000*kWh)
83.8.19*00(0000.0000*kWh)
83.8.19*00(0000.0000*kWh)
18.128(0000.0028*kWh)
18.128*12(0000.0002*kWh)
18.128&12(0000.0000*kWh)
18.128*00(0000.0000*kWh)
18.128*00(0000.0000*kWh)
28.128(0000.0101*kWh)
28.128*12(0000.0016*kWh)
28.128&12(0000.0000*kWh)
28.128*00(0000.0000*kWh)
28.128*00(0000.0000*kWh)
12.7.128(00.009)
11.7.128(00.013)
C.2.0(00000004)
C.2.1(20-12-30 16:14)
C.2.2(20-12-29)
C.6.0(000155*h)
C.6.3(6.5*V)
C.7.1(00000001)
C.7.2(00000000)
C.7.3(00000000)
C.7.0(00000009)
C.8.0(00008151*min)
C.8.0*12(00002435*min)
C.8.0&12(00000517*min)
C.8.0*00(00000000*min)
C.8.0*00(00000000*min)
C.8.1(00007930*min)
C.8.1*12(00002214*min)
C.8.1&12(00000296*min)
C.8.1*00(00000000*min)
C.8.1*00(00000000*min)
C.8.2(00000000*min)
C.8.2*12(00000000*min)
C.8.2&12(00000000*min)
C.8.2*00(00000000*min)
C.8.2*00(00000000*min)
C.8.3(00000221*min)
C.8.3*12(00000221*min)
C.8.3&12(00000221*min)
C.8.3*00(00000000*min)
C.8.3*00(00000000*min)
32.7.0(236.9*V)
52.7.0(238.1*V)
72.7.0(237.4*V)
31.7.0(03.47*A)
51.7.0(03.31*A)
71.7.0(03.43*A)
91.7.0(00.33*A)
14.7(49.97*Hz)
32.32.0(0001)(00-01-01 00:09)
52.32.0(0001)(00-01-01 00:09)
72.32.0(0001)(00-01-01 00:09)
32.36.0(0001)(20-12-30 16:24)
52.36.0(0001)(20-12-30 16:24)
72.36.0(0001)(20-12-30 16:24)
81.7.0( 0*Deg)
81.7.1( 120*Deg)
81.7.2( 240*Deg)
81.7.4( 14*Deg)
81.7.5( 129*Deg)
81.7.6( 254*Deg)
0.2.7(B21)
C.2.7(00-00-00)
13.7.0( 0.976)
13.0.0(0.976)
13.3.1(0.975)(21-01-01 02:45)
C.8.5(00000000*min)
C.8.5*12(00000000*min)
C.8.5&12(00000000*min)
C.8.5*00(00000000*min)
C.8.5*00(00000000*min)
1.8.5(0000.0000*kWh)
1.8.5*12(0000.0000*kWh)
1.8.5&12(0000.0000*kWh)
1.8.5*00(0000.0000*kWh)
1.8.5*00(0000.0000*kWh)
2.8.5(0000.0000*kWh)
2.8.5*12(0000.0000*kWh)
2.8.5&12(0000.0000*kWh)
2.8.5*00(0000.0000*kWh)
2.8.5*00(0000.0000*kWh)
!
�:
Looks ok but I am not sure that the 2.8.5*12
or the 2.8.5&12
value representation is part if the IEC 62056-21 standard.
from iec62056-21.
Hi,
thank You very much. It solved my problem. Case closed 👍
from iec62056-21.
Related Issues (20)
- switch baudrate HOT 3
- rest() from Iec6205621Client HOT 4
- read_single_value HOT 5
- ISk5MT174 - TimeoutError: Read in SerialTransport timed out HOT 3
- connecting via GSM HOT 11
- Update Pypi HOT 9
- support protocol mode = 2 in AckOptionSelectMessage HOT 2
- Move to attrs classes for messages
- Request support for HAN-NVE (a.k.a. Norwegian RJ45 HAN-port standard) interface over M-Bus HOT 1
- Implementing protocol to my client file. HOT 5
- Issue " connection being refused after dockerize and running mininet " HOT 4
- Socket Timeout HOT 3
- read 1.8.0
- Problem with client.read_value
- readout of landis + gyr120AP HOT 1
- trying to readout EMH - LZQJ-XC but cant build up connection HOT 9
- Not able to enter programming mode on EMH meter - serial transport
- EMH meter is only responding with ACK on read. HOT 1
- Not able to send address in init request over serial transport
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iec62056-21.