Data are binary and such is transferred on the bus. How to interpret these data and what they represent depends on specifications. For signed values for example it is common to use the
Two's complement - Wikipedia[
^].
The
QModbusDataUnit::value()
function returns an
quint16. That is a 16 bit unsigned binary value containing the content of the requested register. How to interpret that content depends on the device.
If that uses two's complement for signed 16 bit values, it will send 0xFFFF for -1. Converting that to a string using
QString::number()
results in 65535. To get it as negative number you have to cast the value to
qint16
first so that the function knows that you have a signed value:
const QString entry_hs_in_temp = QString::number(static_cast<qint16>(unit.value(0)));
That should work in most cases. But if the device is using a different method to represent signed values, you have to use the corresponding reverse procedure to convert the received binary data to a basic signed integer type.