-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEastron_SDM120.py
88 lines (68 loc) · 2.49 KB
/
Eastron_SDM120.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# VenusOS module for support of Eastron SDM120-Modbus
# might work also with other Eastron devices > Product code on 0x001c (type u16b) to be added into models overview
#
import logging
import Eastron_device as device
import probe
from register import *
log = logging.getLogger()
class Reg_f32b(Reg_num):
coding = ('>f', '>2H')
count = 2
rtype = float
nr_phases = [ 1, 1, 3, 3 ]
phase_configs = [
'1P',
'1P',
'3P.1',
'3P.n',
]
class Eastron_SDM120(device.EnergyMeter):
productid = 0xB023 # id assigned by Victron Support
productname = 'Eastron SDM120-Modbus'
min_timeout = 0.5
hardwareversion = '1'
firmwareversion = '0'
serial = '0'
def __init__(self, *args):
super().__init__(*args)
self.info_regs = [
Reg_u16( 0xfc02, '/HardwareVersion'),
Reg_u16( 0xfc03, '/FirmwareVersion'),
Reg_f32b(0x000a, '/PhaseConfig', text=phase_configs, write=(0, 3)),
Reg_u32b(0xfc00, '/Serial'),
]
def phase_regs(self, n):
s = 0x0002 * (n - 1)
return [
Reg_f32b(0x0000 + s, '/Ac/L%d/Voltage' % n, 1, '%.1f V'),
Reg_f32b(0x0006 + s, '/Ac/L%d/Current' % n, 1, '%.1f A'),
Reg_f32b(0x000c + s, '/Ac/L%d/Power' % n, 1, '%.1f W'),
Reg_f32b(0x0048 + s, '/Ac/L%d/Energy/Forward' % n, 1, '%.1f kWh'),
Reg_f32b(0x004a + s, '/Ac/L%d/Energy/Reverse' % n, 1, '%.1f kWh'),
]
def device_init(self):
self.read_info()
phases = nr_phases[int(self.info['/PhaseConfig'])]
regs = [
Reg_f32b(0x000c, '/Ac/Power', 1, '%.1f W'),
Reg_f32b(0x0006, '/Ac/Current', 1, '%.1f A'),
Reg_f32b(0x0046, '/Ac/Frequency', 1, '%.1f Hz'),
Reg_f32b(0x0048, '/Ac/Energy/Forward', 1, '%.1f kWh'),
Reg_f32b(0x004a, '/Ac/Energy/Reverse', 1, '%.1f kWh'),
]
for n in range(1, phases + 1):
regs += self.phase_regs(n)
self.data_regs = regs
def get_ident(self):
return 'cg_%s' % self.info['/Serial']
# identifier to be checked, if register identical on all SDM120 (only first 16 bytes in u16b of 32 bit register 0xfc02)
models = {
32: {
'model': 'SDM120Modbus',
'handler': Eastron_SDM120,
},
}
probe.add_handler(probe.ModelRegister(Reg_u16(0xfc02), models,
methods=['tcp','rtu'],
units=[1]))