-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsamsung-modbus.py
executable file
·143 lines (98 loc) · 4.1 KB
/
samsung-modbus.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Example script to read data from a Samsung Heat Pump or HVAC unit using MIM-B19N Modbus module
import minimalmodbus
import serial
import struct
import time
def millis():
return int(round(time.time() * 1000))
def C(val):
return struct.pack('!H', val)
instrument = minimalmodbus.Instrument('/dev/ttyUSB0',1)
#instrument = minimalmodbus.Instrument('/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0', 1)
instrument.serial.port # this is the serial port name
instrument.serial.baudrate = 9600 # Baud
instrument.serial.bytesize = 8
instrument.serial.parity = serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout = 1 # seconds
instrument.debug = False
instrument.address = 1 # this is the slave address number
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
################################################################
# READ COMMANDS
################################################################
################################################################
# HIDDEN REGESITERS
################################################################
# Flow rate in L/min
# FR control
# 3 way valve position. 0=CH, 1=DHW
# OutdoorT
instrument.write_registers(7005,[0x42E9, 0x42F1, 0x4067, 0x8204])
time.sleep(0.5)
# Outdoor temp
outdoor_temp = round(0.1*(instrument.read_register(5,functioncode=3,signed=True)),2)
print ("Outdoor temp: " + str(outdoor_temp))
time.sleep(0.5)
# Flow rate in L/min
flowrate = round(0.1*(instrument.read_register(87,functioncode=3)),2)
print ("Flow rate: " + str(flowrate))
time.sleep(0.5)
# 3 way valve position. 0=CH, 1=DHW
time.sleep(0.5)
threeway_valve_position = instrument.read_register(89,functioncode=3)
print ("3 way valve position: " + str(threeway_valve_position))
# Compressor Freq (%)
compressor_freq = instrument.read_register(88,functioncode=3)
print ("Compressor freq %: " + str(compressor_freq))
time.sleep(1)
################################################################
# MAIN REGESITERS
################################################################
dhw_temp = round(0.1*(instrument.read_register(75,functioncode=3,signed=True)),2)
time.sleep(0.5)
return_temp = round(0.1*(instrument.read_register(65,functioncode=3,signed=True)),2)
time.sleep(0.5)
flow_temp = round(0.1*(instrument.read_register(66,functioncode=3,signed=True)),2)
time.sleep(0.5)
target_flow_temp = round(0.1*(instrument.read_register(68,functioncode=3)),2)
time.sleep(0.5)
dhw_status = instrument.read_register(72,functioncode=3)
time.sleep(0.5)
target_dhw_temp = round(0.1*(instrument.read_register(74,functioncode=3)),2)
time.sleep(0.5)
away_status = instrument.read_register(79,functioncode=3)
time.sleep(0.5)
ch_status = instrument.read_register(52,functioncode=3)
time.sleep(0.5)
indoor_temp = round(0.1*(instrument.read_register(59,functioncode=3,signed=True)),2)
time.sleep(0.5)
target_indoor_temp = round(0.1*(instrument.read_register(58,functioncode=3,signed=True)),2)
time.sleep(0.5)
defrost_status = instrument.read_register(2,functioncode=3)
print ("Central heating status: " + str(ch_status))
print ("Target indoor temp: " + str(target_indoor_temp))
print ("Indoor temp: " + str(indoor_temp))
print ("Target flow temp: " + str(target_flow_temp))
print ("Flow temp: " + str(flow_temp))
print ("Return temp: " + str(return_temp))
print ("DHW status: " + str(dhw_status))
print ("DHW target temp: " + str(target_dhw_temp))
print ("DHW temp: " + str(dhw_temp))
print ("Away mode status: " + str(away_status))
print ("Defrost operation status: " + str(defrost_status))
################################################################
# WrITE COMMANDS (CONTROL)
################################################################
# Switch on DHW
# instrument.write_register(72,1)
# Switch on CH
# instrument.write_register(52,1)
# Set DHW temp to 50 deg C
#instrument.write_register(74,550)
# Set flow temp to 40 deg C
# instrument.write_register(68,400)
# Set indoor target temp to 21 deg C
# instrument.write_register(58,210)
# Set away mode on
# instrument.write_register(79,1)