bojan gavrilovic bojan gavrilovic - 17 days ago 5
C Question

C to Pascal type conversion

Good day,

I work on I2C communication between Master (Raspberry pi 2B, using Lazarus) and Slave - Arduino Nano.
On Arduino I have defined

typedef union
{
float Temperature;
uint8_t bytes[4];
} floatuint;
floatuint fu;


On Raspberry pi I have defined

TFloatUint = packed record
case Boolean of
False: (dabDouble: Double);
True: (dabByte: packed array[0..3] of cuint8);
end;


Using command

count := FpRead(I2DeviceHandle, fl.dabByte, 4);


I receive the same values for byte array, but fl.dabDouble shows different result.

For example:

fu.Temperature = 19.19;
fu.bytes = (0, 128, 153, 65);

fl.dabByte = (0, 128, 153, 65);
fl.dabDouble = 2.6656892163191751e-314


Where I made a mistake?

Thanks in advance

Bojan

Answer

Double is 8 bytes in size in pascal. use Single which is 4 bytes.

TFloatUint = packed record
   case Boolean of
     False: (dabSingle: Single);
     True: (dabByte: packed array[0..3] of cuint8);
 end;
Comments