title: Pymodbus TCP `read_holding_registers` returns stale/old data
body: <p>I've started using <code>pymodbus</code> to read values from modbus to store in a database off site. I've been struggling with an issue that the value received in the response is not the same as the value I can see on the Jace. </p>
  
  <p>I've tried <code>modbus-tk</code> as well and I'm getting the same incorrect response, so it must be something in my Python code that is causing this issue. The readings retrieved from our legacy system (VB.Net) are the same as the outputs I see on the Jace. </p>
  
  <p>This is the simple function retrieving the data from modbus. We have 2 registers at <code>40160</code> and <code>40162</code> the first one is reading <code>366</code> which is correct and the 2nd one is reading <code>367</code> (This is the one I'm having the problem with). I've also seen the same issue with other registers where the reading does not update even though I can see on the Jace that the value has increased. </p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  from __future__ import division, print_function, unicode_literals
  
  from pymodbus.client.sync import ModbusTcpClient
  from pymodbus.constants import Endian
  from pymodbus.payload import BinaryPayloadDecoder
  
  def get_modbus_register_data(ip_address, register, device, count=2):
          """
          Retrieve modbus data.
          """
          client = ModbusTcpClient(ip_address, timeout=10)
          client.connect()
  
          # Read registers
          response = client.read_holding_registers(
              address=register,  # 40162
              count=count,       # 2
              unit=device)       # 4
  
          decoder = BinaryPayloadDecoder.fromRegisters(
              registers=response.registers,
              byteorder=Endian.Big,
              wordorder=Endian.Little)
  
          value = decoder.decode_32bit_float()
  
          client.close()
  
          return value # 366 and it should be 367
  </code></pre>
  
  <p><strong>Pymodbus debug logs</strong></p>
  
  <pre><code>DEBUG:pymodbus.transaction:Current transaction state - IDLE
  DEBUG:pymodbus.transaction:Running transaction 1
  DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x4 0x3 0x0 0xa0 0x0 0x2
  DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
  DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
  DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
  DEBUG:pymodbus.transaction:RECV: 0x0 0x1 0x0 0x0 0x0 0x7 0x4 0x3 0x4 0x0 0x0 0x43 0xb7
  DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x4 0x3 0x4 0x0 0x0 0x43 0xb7
  DEBUG:pymodbus.factory:Factory Response[ReadHoldingRegistersResponse: 3]
  DEBUG:pymodbus.transaction:Adding transaction 1
  DEBUG:pymodbus.transaction:Getting transaction 1
  DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/OoIt2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OoIt2.png" alt="Jace reading"></a></p>
  
  <p><a href="https://i.stack.imgur.com/D7Bey.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D7Bey.png" alt="Config"></a></p>
  
  <p><strong>Update</strong></p>
  
  <p>With the help of Sanju, it was pointed out to me that the offset I'm using might be incorrect. This was indeed the case, by changing the offset by 1 (40162 - 40001 = 161) I was able to retrieve the correct values from the register, the <code>wordorder</code> needed to change to <code>Endian.Big</code>. </p>
  
  <p><strong>Updated code</strong></p>
  
  <pre><code>def get_modbus_register_data(ip_address, register, device, count=2):
          """
          Retrieve modbus data.
          """
          client = ModbusTcpClient(ip_address, timeout=10)
          client.connect()
  
          # Read registers
          response = client.read_holding_registers(
              address=register,  # 40161
              count=count,       # 2
              unit=device)       # 4
  
          decoder = BinaryPayloadDecoder.fromRegisters(
              registers=response.registers,
              byteorder=Endian.Big,
              wordorder=Endian.Big)
  
          value = decoder.decode_32bit_float()
  
          client.close()
  
          return value # 367
  </code></pre>