fix modbus write for signed values

This commit is contained in:
MichaelDvP
2024-12-18 13:44:24 +01:00
parent 4b3205fc9c
commit c8822aff64

View File

@@ -2136,7 +2136,12 @@ int EMSdevice::modbus_value_to_json(uint8_t tag, const std::string & shortname,
return -4; return -4;
} }
if (dv.type == DeviceValueType::INT8 || dv.type == DeviceValueType::INT16) { // handle signed
jsonValue["value"] =
Helpers::numericoperator2scalefactor(dv.numeric_operator) * (float)(int16_t)((uint16_t)modbus_data[0] << 8 | (uint16_t)modbus_data[1]);
} else {
jsonValue["value"] = Helpers::numericoperator2scalefactor(dv.numeric_operator) * (float)((uint16_t)modbus_data[0] << 8 | (uint16_t)modbus_data[1]); jsonValue["value"] = Helpers::numericoperator2scalefactor(dv.numeric_operator) * (float)((uint16_t)modbus_data[0] << 8 | (uint16_t)modbus_data[1]);
}
} else if (dv.type == DeviceValueType::UINT24 || dv.type == DeviceValueType::UINT32 || dv.type == DeviceValueType::TIME) { } else if (dv.type == DeviceValueType::UINT24 || dv.type == DeviceValueType::UINT32 || dv.type == DeviceValueType::TIME) {
// these data types are 2 16 bit register // these data types are 2 16 bit register
if (modbus_data.size() != 4) { if (modbus_data.size() != 4) {