再会,
我致力于Master(使用Lazarus的Raspberry pi 2B)和Slave-Arduino Nano之间的I2C通信。在Arduino上,我定义了
typedef union
{
float Temperature;
uint8_t bytes[4];
} floatuint;
floatuint fu;
我在Raspberry pi上定义了
TFloatUint = packed record
case Boolean of
False: (dabDouble: Double);
True: (dabByte: packed array[0..3] of cuint8);
end;
使用命令
count := FpRead(I2DeviceHandle, fl.dabByte, 4);
我收到相同的字节数组值,但是fl.dabDouble显示不同的结果。
例如:
fu.Temperature = 19.19;
fu.bytes = (0, 128, 153, 65);
fl.dabByte = (0, 128, 153, 65);
fl.dabDouble = 2.6656892163191751e-314
我在哪里弄错了?
Double
的大小为8字节(帕斯卡)。使用的Single
是4个字节。
TFloatUint = packed record
case Boolean of
False: (dabSingle: Single);
True: (dabByte: packed array[0..3] of cuint8);
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句