pymodbus icon indicating copy to clipboard operation
pymodbus copied to clipboard

Issue with Modbus Error: [Input/Output] No Response received from the remote unit

Open pawelmarkowski opened this issue 9 years ago • 24 comments

Hello, I am checking out pymodbus.version '1.3.2' library and attached code does not work, but code copy in pymodbus3 works fine.

What did I do wrong?

import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

from pymodbus.client.sync import ModbusTcpClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.constants import Endian

client = ModbusTcpClient('192.168.174.82', port = 502)
registers_set = 1
address = 7505
count = registers_set * 2
unit = 1

result = client.read_holding_registers(address, count, unit = unit)
print(result)
print(result.registers)

for i in range(registers_set):
    j = i * 2
    k = (i + 1) * 2
    print (j, k, "register range")
    decoder = BinaryPayloadDecoder.from_registers(result.registers[j:k], endian = Endian.Big)
    print("{0:.2f}".format(decoder.decode_32bit_float()))
client.close()

DEBUG:pymodbus.transaction:Running transaction 1 DEBUG:pymodbus.transaction:send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x1d 0x51 0x0 0x2 DEBUG:pymodbus.transaction:recv: 0x0 0x1 0x0 0x0 0x0 0xb 0x1 0x3 0x8 0x45 0xae 0x6f 0x8c DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0xb 0x1 0x3 0x8 0x45 0xae 0x6f 0x8c DEBUG:pymodbus.transaction:getting transaction 1 Traceback (most recent call last): Modbus Error: [Input/Output] No Response received from the remote unit File "/home/pawel/workspace/scripts/python/modbus/lumel.py", line 23, in print(result.registers) AttributeError: 'ModbusIOException' object has no attribute 'registers'


import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

from pymodbus3.client.sync import ModbusTcpClient
from pymodbus3.payload import BinaryPayloadDecoder
from pymodbus3.constants import Endian



client = ModbusTcpClient('192.168.174.82', port = "502")
registers_set = 1

address = 7505

count = registers_set * 2

unit = 1

result = client.read_holding_registers(address, count, unit = unit)
print(result)
print(result.registers)

for i in range(registers_set):
    j = i * 2
    k = (i + 1) * 2
    print (j, k, "register range")
    decoder = BinaryPayloadDecoder.from_registers(result.registers[j:k], endian = Endian.Big)
    print("{0:.2f}".format(decoder.decode_32bit_float()))
client.close()

DEBUG:pymodbus3.transaction:Running transaction 1 DEBUG:pymodbus3.factory:Factory Response[3] DEBUG:pymodbus3.transaction:adding transaction 1 DEBUG:pymodbus3.transaction:getting transaction 1 ReadRegisterResponse (4) [17838, 28486, 16777, 24065] 0 2 register range 5581.91

Thanks for help.

pawelmarkowski avatar Sep 20 '17 15:09 pawelmarkowski

@pawelmarkowski , would you mind sharing your findings? Was it a problem with your setup?

dhoomakethu avatar Sep 21 '17 14:09 dhoomakethu

no it was not a problem with setup. It still does not work ... interesting thing is that the device has address = 7505 with 32bit registry ... I found other 16bit address that works and I can read a data so I closed the ticket. It is strange that a pymodbus3 works fine.

pawelmarkowski avatar Sep 21 '17 15:09 pawelmarkowski

Are you working with a real modbus device ? If yes can you please share the details/specs?

dhoomakethu avatar Sep 21 '17 16:09 dhoomakethu

http://www.lumel.com.pl/en/download/measuring_transducers/p30o/

pawelmarkowski avatar Sep 21 '17 17:09 pawelmarkowski

@pawelmarkowski the device talks only about serial interface but your code is for Modbus TCP, Is there a RTU-TCP gateway you are talking to ? But any how I will try to reproduce this issue with your code using the simulations and update.

dhoomakethu avatar Sep 22 '17 03:09 dhoomakethu

Gateway, but I will confirm it on Monday.

pawelmarkowski avatar Sep 22 '17 10:09 pawelmarkowski

Hello, sorry for 1 week delay :). I updated above link - device has modbus TCP interface.

pawelmarkowski avatar Oct 02 '17 09:10 pawelmarkowski

I have the same problem with version '1.3.2'. The length of received package through sync TCP client is not correct.

Following is the logging information:

DEBUG:root:Read a holding register DEBUG:pymodbus.transaction:Running transaction 1 DEBUG:pymodbus.transaction:send: 0x0 0x1 0x0 0x0 0x0 0x6 0x7e 0x3 0x9c 0x42 0x0 0x1 DEBUG:pymodbus.transaction:recv: 0x0 0x1 0x0 0x0 0x0 0x5 0x7e 0x3 0x2 0x0 DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x5 0x7e 0x3 0x2 0x0 DEBUG:pymodbus.transaction:getting transaction 1 Modbus Error: [Input/Output] No Response received from the remote unit error 'ModbusIOException' object has no attribute 'registers'

DEBUG:pymodbus.transaction:Running transaction 2 DEBUG:pymodbus.transaction:send: 0x0 0x2 0x0 0x0 0x0 0x6 0x7e 0x3 0x9c 0x42 0x0 0x1 DEBUG:pymodbus.transaction:recv: 0x1 DEBUG:pymodbus.transaction:0x1 error 'len'

DEBUG:pymodbus.transaction:Running transaction 3 DEBUG:pymodbus.transaction:send: 0x0 0x3 0x0 0x0 0x0 0x6 0x7e 0x3 0x9c 0x42 0x0 0x1 DEBUG:pymodbus.transaction:recv: 0x0 0x2 0x0 0x0 0x0 0x5 0x7e 0x3 0x2 0x0 0x1 DEBUG:pymodbus.transaction:0x0 0x2 0x0 0x0 0x0 0x5 0x7e 0x3 0x2 0x0 0x1 DEBUG:pymodbus.factory:Factory Response[3] DEBUG:pymodbus.transaction:adding transaction 2 DEBUG:pymodbus.transaction:getting transaction 3 DEBUG:pymodbus.transaction:getting transaction 0 None error 'NoneType' object has no attribute 'registers'

The recv data in the first transaction was truncated into 2 transactions and caused all the following transaction to be incorrect even though the length is actually correct.

In addition, I managed to get the correct data by using pymodbus3 package instead.

lixiangabcd08 avatar Oct 03 '17 04:10 lixiangabcd08

@lixiangabcd08 In your case I see you are trying to read the absolute address (40002), Could you just pass the offset (0x1) as address and see if you can get the expected result?

dhoomakethu avatar Oct 03 '17 04:10 dhoomakethu

@pawelmarkowski could you give a try with this branch and let me know if it works ?

https://github.com/riptideio/pymodbus/tree/217-fix-tcp-client or with this pymodbus-1.4.0rc1.tar.gz

dhoomakethu avatar Oct 03 '17 05:10 dhoomakethu

@dhoomakethu thank you very much for your suggestion, but changing the base address doesn't work. Same problem persists. As I have said, there are some problems regarding the number of bytes in the first 2 received packages. From 3rd package onwards, the received package length becomes ok. But since it's synchronous, it doesn't work out very nicely.

lixiangabcd08 avatar Oct 03 '17 07:10 lixiangabcd08

@dhoomakethu By the way, the code works correctly when I initiate the ModbusTcpClient with library from pymodbus3 and use the read_input_registers function from pymodbus. So I believe there is some bug inside initiation of client code. Hope it helps debugging.

lixiangabcd08 avatar Oct 03 '17 07:10 lixiangabcd08

@lixiangabcd08 please see the comment above , please try the pymodbus from that branch or use the tar file to install pymodbus.

@pawelmarkowski could you give a try with this branch and let me know if it works ?

https://github.com/riptideio/pymodbus/tree/217-fix-tcp-client or with this pymodbus-1.4.0rc1.tar.gz

dhoomakethu avatar Oct 03 '17 07:10 dhoomakethu

@dhoomakethu It works in your version. Only what I have to change is decoding. Data in the registry is stored in reverse order.

DEBUG:pymodbus.transaction:Running transaction 1 DEBUG:pymodbus.transaction:send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x3 0x17 0x7a 0x0 0x2 DEBUG:pymodbus.transaction:recv: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0xfc 0xbb 0x45 0xc0 DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0xfc 0xbb 0x45 0xc0 DEBUG:pymodbus.factory:Factory Response[3] DEBUG:pymodbus.transaction:adding transaction 1 DEBUG:pymodbus.transaction:getting transaction 1 ReadRegisterResponse (2) [64699, 17856] 6175.59 DEBUG:pymodbus.transaction:Running transaction 2 DEBUG:pymodbus.transaction:send: 0x0 0x2 0x0 0x0 0x0 0x6 0x1 0x3 0x1d 0x51 0x0 0x1 DEBUG:pymodbus.transaction:recv: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0x45 0xc0 0xfc 0xbb DEBUG:pymodbus.transaction:0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0x45 0xc0 0xfc 0xbb DEBUG:pymodbus.factory:Factory Response[3] DEBUG:pymodbus.transaction:adding transaction 2 DEBUG:pymodbus.transaction:getting transaction 2 ReadRegisterResponse (2) [17856, 64699] -7778993684926939764378185074730860544.00

thank You!

pawelmarkowski avatar Oct 03 '17 07:10 pawelmarkowski

@pawelmarkowski thanks for confirming, I will wait on @lixiangabcd08 to confirm so that I can push this to master and close the issue

dhoomakethu avatar Oct 03 '17 07:10 dhoomakethu

@dhoomakethu I am very sorry that I am unable to verify it until next week:(

lixiangabcd08 avatar Oct 03 '17 11:10 lixiangabcd08

will be tracked with #221

dhoomakethu avatar Oct 03 '17 12:10 dhoomakethu

@dhoomakethu Sorry for the late reply, I have tried your version. It does not solve the problem. However the error is a bit different now. Instead of receiving 10 packages in the first transaction, 1 package in the second transaction and 11 (correct number) packages in the rest of transactions, now I receive 10 package in every transaction.

Debugging infomation as followed: 169.254.82.110:502 DEBUG:pymodbus.transaction:Running transaction 1 DEBUG:pymodbus.transaction:send: 0x0 0x1 0x0 0x0 0x0 0x6 0x7e 0x4 0x9d 0x7 0x0 0x1 DEBUG:pymodbus.transaction:recv: 0x0 0x1 0x0 0x0 0x0 0x5 0x7e 0x4 0x2 0x0 DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x5 0x7e 0x4 0x2 0x0 DEBUG:pymodbus.transaction:getting transaction 1 Modbus Error: [Input/Output] No Response received from the remote unit

169.254.82.110:502 DEBUG:pymodbus.transaction:Running transaction 1 DEBUG:pymodbus.transaction:send: 0x0 0x1 0x0 0x0 0x0 0x6 0x7e 0x4 0x9d 0x7 0x0 0x1 DEBUG:pymodbus.transaction:recv: 0x0 0x1 0x0 0x0 0x0 0x5 0x7e 0x4 0x2 0x0 DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x5 0x7e 0x4 0x2 0x0 DEBUG:pymodbus.transaction:getting transaction 1 Modbus Error: [Input/Output] No Response received from the remote unit

And this TCP connection works fine with pymodbus3.

lixiangabcd08 avatar Oct 12 '17 05:10 lixiangabcd08

@lixiangabcd08 , Are you sure you are using the correct pymodbus version ? The behaviour you are observing is not expected , with the changes ModbusTCP client would now will receive up to 1024 bytes of data in one read. Please uninstall and install pymodbus again (the version with patch in this comment thread above ) and confirm. Thanks

dhoomakethu avatar Oct 12 '17 09:10 dhoomakethu

@dhoomakethu Thank you for your reply! I believe I am using the correct pymodbus library since I have uninstall and install for a few time. The received modbus data from execution using the offical version and the version in this thread are different. And I only observe this behavior for one type of our TCP device while the other TCP devices work fine with pymodbus.

lixiangabcd08 avatar Oct 12 '17 13:10 lixiangabcd08