Problems with measuring of values the TUF2000M with Arduino,MAXRS485 SOLVED

Hi everyone, I working with achivieve the values for Modbus RTU.

Hardware used - Arduino Mega 2560, MAX RS485;

Libs used - I liked more use the lib ModbusMaster of Github, others i had some problems;

this code i used is:

#include <ModbusMaster.h>
/!
We’re using a MAX485-compatible RS485 Transceiver.
Rx/Tx is hooked up to the hardware serial port at ‘Serial’.
The Data Enable and Receiver Enable pins are hooked up as follows:
/
#define MAX485_DE 21
#define MAX485_RE_NEG 22
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 9600 baud
Serial.begin(9600);
Serial1.begin(9600,SERIAL_8N1); // o padrão do equipamento pode ser ajustado pelo seu menu;
// Modbus slave ID 1
node.begin(0x01, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
// bool state = true;
void loop()
{
uint16_t result;
uint32_t data[6];

result = node.readHoldingRegisters(0x20, 2);

if (result == node.ku8MBSuccess)
{
Serial.print("Passive Total Flow: “);
Serial.println(node.getResponseBuffer(0x00),BIN);
Serial.println(” ");
Serial.println(node.getResponseBuffer(0x01),BIN);
}
delay(1000);
}

the problem i belive, not is the code, i’m printing in binary just for test,
i see another question this forum about the same thing, and one person talk about the Standart of values -IEEE 754, i like know if anybody knows how i convert the value of binary on decimal, (the register read is the Temperature) , the manual is here :

int4 — dec

 result = node.readHoldingRegisters(0x20, 2);

You're reading one 16bit value from "Net energy decimal fraction" and one 16bit value from "Temperature #1/inlet". Does that make sense for you?

I believe that the numbers of registers given are in DEC for the reason i put in HEX, and more other thing i searched of registers modbus and the number de holding registers have offset for 4000 .
I would like to know if the class does this offset or I have to (for someone who has worked with the class).

Searching on GitHub ModbusMaster class ISSUES, I found a solution to my problem, at least for now, i will share here.

#include<ModbusMaster.h> //include Modbus library
//#include<SoftwareSerial.h>
#define MAX485_DE 22 //high to enable
#define MAX485_RE_NEG 21 //low to enable
ModbusMaster node;
void preTransmission()
{
digitalWrite (MAX485_RE_NEG, 1);
digitalWrite (MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite (MAX485_RE_NEG, 0);
digitalWrite (MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(9600);
Serial1.begin(9600,SERIAL_8N1);
node.begin(1, Serial1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
union
{
uint32_t i;
float f;
}u;
uint8_t result = node.readHoldingRegisters(0x20, 2); // for 3000xx registers
Serial.println("Result : " + String(result,HEX));// to get error type
if (result == node.ku8MBSuccess)
{
u.i=(((unsigned long)node.getResponseBuffer(0x01)<<16) | (node.getResponseBuffer(0x00)));// shifting 2nd register to left & stiching with 1st register
}
Serial.println("Reading is "+String(u.f,5));
delay(2000);
}

Forgot to attach as images test, are attached

I believe that the numbers of registers given are in DEC for the reason i put in HEX, and more other thing i searched of registers modbus and the number de holding registers have offset for 4000 .

Exactly the manual provides them in decimal format and you just insert the same number but to be interpreted as hexadecimal. Do you really think this will work?

On some PLCs you cannot specify the register type so they add some offsets to differentiate between the types. On the Arduino you don't have to do that as you have different methods for the different types. BTW, the offset is 40'000.

Yes, I'm working with Arduino, so there's no need to use offset , I'm showing in the attached images that the code is working, thanks for your attention.