Modbus Communications: How to Set Floating Point Values
Paul Peterkin, Danbury CT
In industrial settings, Modbus is one of the oldest protocols for devices to communicate their data digitally to a central controller.?It allows transmitters to send integer data to controllers, and controllers to send integer data to SCADAs used in large, fully-monitored mission critical facilities such as data centers. Here we will give a pithy explanation of successfully encoding floating point values via Modbus.
Floating Point Values Via Modbus: Recap of Modbus Data Model
Modbus encodes analog values either as Holding Registers or Input Registers.
Modbus Encoding for Floating Point Values
IEEE 754 Single-Precision Floating Point Format is the most popular method for representing floating point numbers but requires 32-Bits. Manufacturers have settled on using 2 consecutive Modbus register for encoding floating point values. This sounds easy… but, not so fast. Although it was agreed to use 2 consecutive register to encode floating point values, there is no standard method for the order in which the data is sent.
Example: for the floating-point value 50.123 the IEE 754 single precision floating point representation is as shown below.
领英推荐
Split into two, 16 Bit Words (Registers): High 0x4248 Low 0x7df4. Encode for Modbus Holding Register 40001 & 40002. Some manufacturers send the High Word first, and then the Low Word.
Other manufacturers send the Low Word First, and then the High Word.
How to read Modbus floating point values
Most Modbus Masters provide a means to swap the word order for floating point values. Consult the communications point list for the device in question to determine the word (register) order used to encode floating point values. Configure the Master device based on that setting.
If no information is provided on how the data is sent, it becomes a trial and error process. Pick a format and configure the Master device to read the value in that format. If the value read back is very inaccurate, then swap the words, and often that will correct the value read back.
Sr. Systems Engineer at Analytical & Combustion Systems Inc.
2 年Nicely done Paul.
Combustion Controls Specialist ? Educator ? Mentor
2 年I used to teach about this in a PLC programming course, and I would also say if you don’t know for sure if you’re starting address or offset is correct then you can be fooled into thinking you have it correct when you start reading one register late and have a swapped word order. This is particularly true when one of the values is zero anyway so it hides this.
Southeast Regional Manager at Preferred Utilities Manufacturing Corporation
2 年Thank you Paul! Questions like this come up frequently.
Regional Manager at Preferred Utilities
2 年Paul did a great job of presenting the topic clearly, even a sales guy could understand it. At least enought to ask the right questions.
working as seniour Engr in MID Arabia Contracting NEOM project, UPDA( MME) Qatar Certified Engineer
2 年Perfect information