Modbus.Float (modbus v0.4.0)

IEEE754 float converter

Based on https://www.h-schmidt.net/FloatConverter/Float.html.

Link to this section Summary

Functions

Converts a list of 2n 16-bit registers to a list of IEEE754 big endian floats.

Converts a list of 2n 16-bit registers to a list of IEEE754 little endian floats.

Converts a list of IEEE754 big endian floats to a list of 2n 16-bit registers.

Converts a list of IEEE754 little endian floats to a list of 2n 16-bit registers.

Link to this section Functions

Link to this function

from_be(list_of_regs)

Converts a list of 2n 16-bit registers to a list of IEEE754 big endian floats.

Example

[+5.0] = Float.from_be([0x40a0, 0x0000])
[-5.0, +5.0] = Float.from_be([0xc0a0, 0x0000, 0x40a0, 0x0000])
Link to this function

from_le(list_of_regs)

Converts a list of 2n 16-bit registers to a list of IEEE754 little endian floats.

Example

[+5.0] = Float.from_le([0x0000, 0x40a0])
[-5.0, +5.0] = Float.from_le([0x0000, 0xc0a0, 0x0000, 0x40a0])
Link to this function

to_be(list_of_floats)

Converts a list of IEEE754 big endian floats to a list of 2n 16-bit registers.

Example

[0x40a0, 0x0000] = Float.to_be([+5.0])
[0xc0a0, 0x0000, 0x40a0, 0x0000] = Float.to_be([-5.0, +5.0])
Link to this function

to_le(list_of_floats)

Converts a list of IEEE754 little endian floats to a list of 2n 16-bit registers.

Example

[0x0000, 0x40a0] = Float.to_le([+5.0])
[0x0000, 0xc0a0, 0x0000, 0x40a0] = Float.to_le([-5.0, +5.0])