I'm currently working with ESP8266 as a master and can read data from EEM-MA370 which is already configured with the gateway.
Imagine that I want to read the value of U12.
ModbusIP mb; //ModbusIP object
IPAddress remote(10, 30 ,21 ,75); // Address of Modbus Slave device
const int REG = 32768; //Dec value of U12
void loop(void){
if (mb.isConnected(remote)) { // Check if connection to Modbus Slave is established
mb.readHreg(remote, REG, &res); // Initiate Read Coil from Modbus Slave
} else {
mb.connect(remote);
Serial.print("Trying");
// Try to connect if no connection
}
When I run the code, it shows me the value as 60664
etc. I know that Modbus only supports 16bit, so I found a code that convert to 32 bit. But i didn't understand how it works actually. How would I know values of the var1 and var2 manually?
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
int main()
{
uint16_t var1 = 255; // 0000 0000 1111 1111
uint16_t var2 = 255; // 0000 0000 1111 1111
uint32_t var3 = (var1 << 16) + var2;
printf("%#"PRIx32"\n", var3);
}
I would like to know, how can I read float values.
Many thanks