Read ModBus address 30002 with 2 register

How Can I read address 30002 with 2 register? I need to read volume flow of water. Using modscan32 and a usb adapter for rs485 I can read the correct value, but with arduino and this library the read value is different. According to the manual address 30002 is read as inputRegister.

I’m using the mega arduino and the RS-485 TTL MODBUS converter

I am using the IFC050 flow sensor (modbus manual link below) look at page 12:

http://www.conaut.com.br/produtos?task=callelement&format=raw&item_id=50&element=943615ec-1ce8-4738-9563-523b9801c59c&method=download

What’s wrong with the code below?


//Code used in the project.

#include <ModbusMaster.h>

#define MAX485_DE 3
#define MAX485_RE_NEG 2

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(19200);

node.begin(1, Serial1);

node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}

void loop(){
uint8_t result;
uint16_t data[6];

result = node.readInputRegisters(30002, 2);

if (result == node.ku8MBSuccess){
Serial.print("Flow: ");
Serial.println(node.getResponseBuffer(0x00));
}else{
Serial.println(“Error”);
}
delay(500);
}

Searching the internet I identified that the reading is wrong because according to the IFC050 manual to read the address 30002 I have to read 2 Byte. Code used for my project only read 1 byte, so I need to change the code to read the 2 bytes. How can I change the code? And help me understand how to read the 2 byte?

the RS-485 TTL MODBUS converter

Link to that device? Better a link to it's schematics.

The default serial configuration of your sensor is 19200baud with 8E1, so your serial configuration should read:

Serial1.begin(19200, SERIAL_8E1);

You then read the two flow registers that hold a float value but you print only one of them. You have to convert the two 16bit integers to a 32bit floating point value.

Link of schematics.

How to convert the two 16bit integers to a 32bit floating point value?

Thanks

How to convert the two 16bit integers to a 32bit floating point value?

Unfortunately the manual doesn't tell us anything about that and the ModBus standard doesn't know floats.
I would expect it to work if you simply put the two integers into a 32bit value and cast it to a float:

typedef union {
  struct {
    uint16_t high;
    uint16_t low;
  } word;
  float value;
} conv;
conv t;

t.word.high = reg1;
t.word.low = reg2;
Serial.println(t.value);