-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpymodbus_testing.py
More file actions
65 lines (51 loc) · 1.68 KB
/
pymodbus_testing.py
File metadata and controls
65 lines (51 loc) · 1.68 KB
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
from pymodbus.client import ModbusSerialClient
import struct
PORT = "/dev/ttyUSB0"
SLAVE_ID = 3
client = ModbusSerialClient(
port=PORT,
baudrate= 115200,
bytesize=8,
parity="N",
stopbits=1,
timeout=3
)
def read_float(address):
result = client.read_holding_registers(
address=address,
count=2,
device_id=SLAVE_ID
)
if result.isError():
print("Read error at", address)
return None
regs = result.registers
# Convert two 16-bit registers → 32-bit float
raw = struct.pack(">HH", regs[0], regs[1])
value = struct.unpack(">f", raw)[0]
return value
if client.connect():
print("FCU In:", read_float(0))
print("Condenser Out:", read_float(2))
print("Evaporator Out:", read_float(4))
print("FCU Out:", read_float(6))
print("Evaporator In:", read_float(8))
print("Geyser Out:", read_float(10))
print("LP Pressure:", read_float(12))
print("HP Pressure:", read_float(14))
print("Water Pressure:", read_float(16))
print("Condenser In:", read_float(18))
print("Geyser In:", read_float(20))
print("Air Chamber Temp:", read_float(22))
print("Cooler Cut ON:", read_float(24))
print("Heater Cut ON:", read_float(26))
print("Evaporator Setpoint:", read_float(28))
print("Cooler Mode Temp:", read_float(30))
print("Heater Mode Temp:", read_float(32))
print("Room Temp:", read_float(34))
print("Heater Actuator %:", read_float(36))
print("Chillwater Actuator %:", read_float(38))
print("Supply Actuator %:", read_float(40))
client.close()
else:
print("Connection failed")