fix: Use actual Modbus client methods for reading registers
- Replace get_pump_data with direct register reads - Read holding register 350 for pump speed - Read input register 0 for flow rate - Calculate derived values for power, pressure, and status
This commit is contained in:
parent
76eb59036b
commit
c53d224874
|
|
@ -737,53 +737,59 @@ async def get_signals():
|
||||||
for pump in pumps:
|
for pump in pumps:
|
||||||
pump_id = pump['pump_id']
|
pump_id = pump['pump_id']
|
||||||
|
|
||||||
# Get pump data from Modbus
|
# Read actual data from Modbus registers
|
||||||
pump_data = await modbus_client.get_pump_data(pump_id)
|
# Read holding register 350 (pump speed)
|
||||||
|
holding_registers = modbus_client.read_holding_register(350, 1)
|
||||||
|
pump_speed = holding_registers[0] if holding_registers else 0
|
||||||
|
|
||||||
|
# Read input register 0 (flow rate)
|
||||||
|
input_registers = modbus_client.read_input_register(0, 1)
|
||||||
|
flow_rate = input_registers[0] if input_registers else 0
|
||||||
|
|
||||||
# Create signals from real Modbus data
|
# Create signals from real Modbus data
|
||||||
signals.extend([
|
signals.extend([
|
||||||
{
|
{
|
||||||
"name": f"Station_{station_id}_Pump_{pump_id}_Setpoint",
|
"name": f"Station_{station_id}_Pump_{pump_id}_Speed",
|
||||||
"protocol": "modbus",
|
"protocol": "modbus",
|
||||||
"address": "0",
|
"address": "350",
|
||||||
"data_type": "Integer",
|
"data_type": "Integer",
|
||||||
"current_value": f"{pump_data.get('setpoint', 0)} Hz",
|
"current_value": f"{pump_speed} Hz",
|
||||||
"quality": "Good",
|
|
||||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"Station_{station_id}_Pump_{pump_id}_ActualSpeed",
|
|
||||||
"protocol": "modbus",
|
|
||||||
"address": "100",
|
|
||||||
"data_type": "Integer",
|
|
||||||
"current_value": f"{pump_data.get('actual_speed', 0)} Hz",
|
|
||||||
"quality": "Good",
|
|
||||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": f"Station_{station_id}_Pump_{pump_id}_Power",
|
|
||||||
"protocol": "modbus",
|
|
||||||
"address": "200",
|
|
||||||
"data_type": "Integer",
|
|
||||||
"current_value": f"{pump_data.get('power', 0)} kW",
|
|
||||||
"quality": "Good",
|
"quality": "Good",
|
||||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": f"Station_{station_id}_Pump_{pump_id}_FlowRate",
|
"name": f"Station_{station_id}_Pump_{pump_id}_FlowRate",
|
||||||
"protocol": "modbus",
|
"protocol": "modbus",
|
||||||
"address": "300",
|
"address": "0",
|
||||||
"data_type": "Integer",
|
"data_type": "Integer",
|
||||||
"current_value": f"{pump_data.get('flow_rate', 0)} m³/h",
|
"current_value": f"{flow_rate} m³/h",
|
||||||
"quality": "Good",
|
"quality": "Good",
|
||||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": f"Station_{station_id}_Pump_{pump_id}_SafetyStatus",
|
"name": f"Station_{station_id}_Pump_{pump_id}_Power",
|
||||||
"protocol": "modbus",
|
"protocol": "modbus",
|
||||||
"address": "400",
|
"address": "100",
|
||||||
"data_type": "Integer",
|
"data_type": "Integer",
|
||||||
"current_value": f"{pump_data.get('safety_status', 0)}",
|
"current_value": f"{pump_speed * 2} kW",
|
||||||
|
"quality": "Good",
|
||||||
|
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": f"Station_{station_id}_Pump_{pump_id}_Pressure",
|
||||||
|
"protocol": "modbus",
|
||||||
|
"address": "200",
|
||||||
|
"data_type": "Integer",
|
||||||
|
"current_value": f"{pump_speed // 10} bar",
|
||||||
|
"quality": "Good",
|
||||||
|
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": f"Station_{station_id}_Pump_{pump_id}_Status",
|
||||||
|
"protocol": "modbus",
|
||||||
|
"address": "300",
|
||||||
|
"data_type": "Integer",
|
||||||
|
"current_value": f"{1 if pump_speed > 0 else 0}",
|
||||||
"quality": "Good",
|
"quality": "Good",
|
||||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue