Modbus: convert collected integers to floating point numbers

Modbus devices prefer to store integer numbers in their registers, but a machine often needs to deliver floating point numbers to the customer. Modbus devices typically use one of four techniques to represent a floating point number:

  1. Store an integer number in a register and let the customer divide it by a number, such as 7014 divided by 100 to create 70.14.
  2. Store two integer numbers in two registers, such as 70 and 14, and let the customer append them to create 70.14.
  3. Same as #2 but the registers are in reverse order.
  4. Store the bytes of an IEEE Floating point number in multiple registers, and let the customer combine them, such as 0x428C47AE representing 70.14.

FairCom's Modbus connector supports all four techniques when it collects data from registers and converts it into JSON numbers.

Dividing collected integers

The machine stores an integer number in a register and requires the customer to divide it by a number, such as 10, 100, or 1000, to create a floating-point number.

  1. FairCom's Modbus connector uses the following JSON configuration to convert the integer value 7014 in register address 2000 into 70.14.
    {
      "propertyPath": "temperature",
      "modbusDataAddress": 2000,
      "modbusDataAccess": "holdingregister",
      "modbusUnitId": 5,
      "modbusDataLen": 1,
      "modbusRegisterType": "int16SignedAB",
      "modbusConvertToFloat": "divideByInteger",
      "modbusDivisor": 100
    },
  1. To configure the Modbus connector to convert an integer into a floating point number, add the "modbusConvertToFloat": "divideByInteger" and "modbusDivisor": 100 settings to the configuration. You can set "modbusDivisor" to 10, 100, 1000, 10000, or another integer number. The connector reads the value of the Modbus register, divides it by the integer number in the "modbusDivisor" property, and stores the result at the "propertyPath" location in the JSON document it generates.

Storing two separate integers

The machine stores two integer numbers in two registers to represent one floating point number.

  1. FairCom's Modbus connector uses the following JSON configuration to convert the integer value 70 in the specified register and 14 in the next register into 70.14. FairCom's Modbus connector always considers the decimal number as positive. So, if the value read is -14, for example, it will be converted to 14.

 

    {
      "propertyPath": "temperature",
      "modbusDataAddress": 2000,
      "modbusDataAccess": "holdingregister",
      "modbusUnitId": 5,
      "modbusDataLen": 1,
      "modbusRegisterType": "int16SignedAB",
      "modbusDecimalDigits":2,
      "modbusConvertToFloat": "appendAdjacentRegisters"
    },
  1. To configure the Modbus connector to convert integers in successive registers into a floating point number, add the "modbusConvertToFloat": "appendAdjacentRegisters " setting to the configuration. The connector reads the value of the specified Modbus register and the next register and appends them with a decimal point between them. It stores the result at the "propertyPath" location in the JSON document it generates.
  2. If you are using this configuration with a createOutput command, it is necessary to change "modbusDecimalDigits" to properly convert the float number to two integers. The default value is 2.

Storing two separate integers in reverse order

Store two integer numbers in two registers to represent one floating point number, but the fractional part is in the first register.

  1. FairCom's Modbus connector uses the following JSON configuration to convert the integer value 14 in the specified register and 70 in the next register into 70.14.
    {
      "propertyPath": "temperature",
      "modbusDataAddress": 2000,
      "modbusDataAccess": "holdingregister",
      "modbusUnitId": 5,
      "modbusDataLen": 1,
      "modbusRegisterType": "int16SignedAB",
      "modbusDecimalDigits":2,
      "modbusConvertToFloat": "appendAdjacentRegistersReversed"
    },
  1. To configure the Modbus connector to convert integers in successive registers into a floating point number, add the "modbusConvertToFloat": "appendAdjacentRegisters" setting to the configuration. The connector reads the value of the specified Modbus register and the next register and appends them with a decimal point between them. It stores the result at the "propertyPath" location in the JSON document it generates.
  2. If you are using this configuration with a createOutput command, it is necessary to change "modbusDecimalDigits" to properly convert the float number to two integers. The default value is 2.

Storing the bytes of an IEEE floating point number

Store the bytes of an IEEE Floating point number in multiple registers.

  1. FairCom's Modbus connector uses the following JSON configuration to convert the IEEE bytes stored in two registers. For example, the first two bytes, 0x428C, can be stored in register 2000, and the bytes 0x47AE can be stored in register 2001. The connector reads the bytes in both registers, combines them into four bytes, and treats them as an IEEE floating point number representing 70.14.
    {
      "propertyPath": "temperature",
      "modbusDataAddress": 2000,
      "modbusDataAccess": "holdingregister",
      "modbusUnitId": 5,
      "modbusDataLen": 2,
      "modbusRegisterType": "ieeefloat32ABCD"
    },
  1. To configure the Modbus connector to convert the bytes of an IEEE floating point number in successive registers into a floating point number, add the "modbusRegisterType": "ieeefloat32ABCD" setting to the configuration. You can assign any of the following values to "modbusRegisterType" to specify different byte orders and sizes of IEEE floating point numbers:
"ieeeFloat32ABCD"
"ieeeFloat32CDAB"
"ieeeFloat32DCBA"
"ieeeFloat32BADC"
"ieeeFloat64ABCDEFGH"
"ieeeFloat64BADCFEHG"
"ieeeFloat64CDABGHEF"
"ieeeFloat64DCBAHGFE"
"ieeeFloat64HGFEDCBA"
"ieeeFloat64GHEFCDAB"
"ieeeFloat64FEHGBADC"
"ieeeFloat64EFGHABCD"