Two's complement, need help to read values


#1

Dear all, I have a modbus TCP device which I am trying to read.
On the manufacturer’s guide I read the following (sorry if I translate to english not properly)

Data format corrensponds to the following standard types used in C programming language
short consists of 2 bytes codified as 16 bit two's complement
integer consists of 4 bytes codified as 4 bytes two's complement
float consists of 4 bytes codified as IEEE 754 floating point on 32 bit
double consists of 8 bytes codified as IEEE 754 floating point on 64 bit

All registers can be read using the Modbus function “03 : Read Holding Registers”

I am trying to read register number 0 (zero) which contains an integer of 4 bytes.
If I use the “modbus read data” tool within the data source editing page, I receive the following result:

0 ==> 0f55
1 ==> 2102

The result in the decimal sistem should be 35738895 (it is the serial number of the device, and I am sure of it because it is written on top of the device).
I’ve noticed that I could obtain the result if I compose the HEX number this way 0221550f, which means that I should put the above numbers in the following order:
4th couple 3rd couple 2nd couple 1st couple and convert it to decimal

Using the standard modbus data types which are available through the dropdown menu does not lead anywhere.

Do you gents have any idea on how I can resolve this issue?
Thanks


#2

I’ve investigated a byt further the issue, and seems there is no solution using mango 1.13 or ScadaBR.

To decode the numbers represented in the above standards it is necessary to swap dwords words and bytes, so in the case I described I was right

The words are 0f55 2102 to obtain the corrensponding decimal value one should first of all swap words

0f55 2102 ==> 2102 0f55

then swap bytes 2102 0f55 ==> 0221550f

then convert to decimal 0221550f => 35738895

So, If I need to read a double made this way (starts from register 8 ends on register 11)

8 ==> 9418
9 ==> 0456
10 ==> ae98
11 ==> c240

first of all I should swap dwords words and bytes this way ==> 40c2 98ae 5604 1894
then I should convert it using the IEEE-754 standard for 64 bits, and the resulting number is 9521.362000000001 wich is right.

This is too much complicated to do, so I have to give up with reading this piece of hardware.
Regards