diff --git a/include/riden_modbus/riden_modbus.h b/include/riden_modbus/riden_modbus.h index 0d60e0a..f303555 100644 --- a/include/riden_modbus/riden_modbus.h +++ b/include/riden_modbus/riden_modbus.h @@ -306,7 +306,7 @@ class RidenModbus double value_to_voltage(const uint16_t value); double value_to_voltage_in(const uint16_t value); double value_to_current(const uint16_t value); - double value_to_power(const uint16_t value); + double values_to_power(const uint16_t *values); uint16_t voltage_to_value(const double voltage); uint16_t current_to_value(const double current); double values_to_temperature(const uint16_t *values); diff --git a/include/riden_modbus/riden_modbus_registers.h b/include/riden_modbus/riden_modbus_registers.h index 248aff0..9b25e22 100644 --- a/include/riden_modbus/riden_modbus_registers.h +++ b/include/riden_modbus/riden_modbus_registers.h @@ -24,8 +24,8 @@ enum class Register { CurrentSet = 9, VoltageOut = 10, CurrentOut = 11, - AH = 12, // ??? - PowerOut = 13, + PowerOut_H = 12, + PowerOut_L = 13, VoltageIn = 14, Keypad = 15, Protection = 16, // OVP_OCP diff --git a/src/riden_modbus/riden_modbus.cpp b/src/riden_modbus/riden_modbus.cpp index c1363a5..deeddfe 100644 --- a/src/riden_modbus/riden_modbus.cpp +++ b/src/riden_modbus/riden_modbus.cpp @@ -122,7 +122,7 @@ bool RidenModbus::get_all_values(AllValues &all_values) all_values.current_set = value_to_current(values[+Register::CurrentSet]); all_values.voltage_out = value_to_voltage(values[+Register::VoltageOut]); all_values.current_out = value_to_current(values[+Register::CurrentOut]); - all_values.power_out = value_to_power(values[+Register::PowerOut]); + all_values.power_out = values_to_power(&(values[+Register::PowerOut_H])); all_values.voltage_in = value_to_voltage_in(values[+Register::VoltageIn]); all_values.keypad_locked = values[+Register::Keypad] != 0; all_values.protection = value_to_protection(values[+Register::Protection]); @@ -237,7 +237,7 @@ bool RidenModbus::get_current_out(double ¤t) bool RidenModbus::get_power_out(double &power) { - return read_power(Register::PowerOut, power); + return read_power(Register::PowerOut_H, power); } bool RidenModbus::is_keypad_locked(bool &keypad) @@ -624,11 +624,11 @@ bool RidenModbus::write_current(const Register reg, const double current) bool RidenModbus::read_power(const Register reg, double &power) { - uint16_t value; - if (!read_holding_registers(reg, &value)) { + uint16_t values[2]; + if (!read_holding_registers(reg, values, 2)) { return false; } - power = value_to_power(value); + power = values_to_power(values); return true; } @@ -739,8 +739,9 @@ double RidenModbus::value_to_current(const uint16_t value) return double(value) / i_multi; } -double RidenModbus::value_to_power(const uint16_t value) +double RidenModbus::values_to_power(const uint16_t *values) { + uint32_t value = (values[0] << 16) + values[1]; return double(value) / p_multi; }