Hello, I’m new here.
I am trying to read an Eastron smart meter with Modbus IEE754
I sent the modbus string to Smartmeter and received the bytes.
But this is the IEE75 with floating point. I found an Arduino code that works well, but I don’t understand it and therefore can’t implement it in processing.
//uint32_t VAL = 0x4368DBD9; //232.86
uint32_t VAL = 0xc3663334; //-230.2
//uint32_t VAL = 0x43663334; //230.2
float X = *(float*) & VAL;
It would be nice if someone could help me there.
Hello @Holle ,
I gleaned some insight from here:
This may help to understand that snippet of code:
C in a Nutshell Chapter 4. Type Conversions In C
See section on Implicit Pointer Conversions.
Some code I dabbled with:
Arduino Code < Click to open!
uint32_t v0 = 0xc3663334; // This has an address in memory
uint32_t x0 = v0;
int address = &v0; // address of v0
Serial.println(address); // prints address
Serial.println(x0) ; // prints integer value
uint32_t *p1 = &v0; // pointer to v0
float x1 = *p1; // This won't work!
uint32_t *p2 = &v0; // pointer to v0
uint32_t x2 = *p2;
uint32_t *p3 = &v0;
float x3 = *(float*)p3 ; // Implicit conversion to float works!
Many thank for this.
float f = Float.intBitsToFloat( inBuffer<<24 | inBuffer<<16 | inBuffer<<8 | inBuffer );