pymodbus icon indicating copy to clipboard operation
pymodbus copied to clipboard

Function code 43 fails because of incomplete receival of bytes

Open balaARR opened this issue 3 years ago • 9 comments

Versions

  • Python: 3.6.5
  • OS: Windows 11
  • Pymodbus: 2.5.3
  • Hardware ():
    - ic7 Danfoss drive with RS485 support - Drive has been directly connected to the Test PC through DTech( USB to RS485) cable and tested through a small python code.

Pymodbus Specific

  • Server(master): rtu- async
  • Client(slave): rtu - async

Description

What were you trying, what has happened, what went wrong, and what did you expect?

We were trying to execute function code 43/14 through the pymodbus package in the above-mentioned drive specification. For any baud rate less than 115200, the execution of function code 43/14 fails as pymodbus package fails to read all the response bytes. Possible root cause/issue found in _wait_for_data() function**(available in sync.py)**. This function sleeps for 10 ms after each iteration of reading from serial port, if no new data/bytes are received in the next iteration, it breaks the loop and returns the incomplete response. So in some cases like ours (with FC43/14) and at lower baud rates this delay is not sufficient.

Code and Logs

The below-mentioned sample python code has been used to execute the function code 43/14

from pymodbus.client.sync import ModbusTcpClient as ModbusTCPClient from pymodbus.client.sync import ModbusSerialClient as ModbusClient from pymodbus.payload import BinaryPayloadBuilder from pymodbus.mei_message import * from pymodbus.diag_message import * from pymodbus.constants import * from pymodbus.pdu import ExceptionResponse from pymodbus.framer.socket_framer import * from pymodbus.framer.rtu_framer import * from pymodbus.factory import ClientDecoder from pymodbus.transaction import ModbusTransactionManager from pymodbus.payload import BinaryPayloadBuilder from pymodbus.pdu import ModbusExceptions from pymodbus.exceptions import ModbusException #from utility.logger import Logger import re import struct from pymodbus.bit_read_message import * from pymodbus.bit_write_message import * from pymodbus.register_read_message import * from pymodbus.register_write_message import * from pymodbus.utilities import computeCRC from pymodbus.transaction import ModbusTransactionManager from pymodbus.payload import BinaryPayloadBuilder from pymodbus.mei_message import ReadDeviceInformationRequest from pymodbus.pdu import ExceptionResponse from pymodbus.pdu import ModbusExceptions from pymodbus.exceptions import ModbusException import time

class ModbusRTU(): def init(self): self.connection = None

def connect(self, method, port): self.connection = ModbusClient(method=method, port=port, baudrate=19200, parity='E', strict=False) if self.connection.connect(): print("RTU Connected")

def read_device_information(self): request = ReadDeviceInformationRequest(1, 1, unit=1) result = self.connection.execute(request) print(result)

modbusrtu = ModbusRTU() modbusrtu.connect('rtu', 'COM4') modbusrtu.read_device_information()

The following image is the output of the above-mentioned snippet: image

Here in our scenario, we are expecting a response of byte size 82, but actually, we are not receiving the complete bytes. Hence that fails our test scenario.

Could you please consider this issue and provide us with some solution for that?

balaARR avatar Jun 13 '22 07:06 balaARR

Will increasing read timeout helps ?

dhoomakethu avatar Jun 14 '22 06:06 dhoomakethu

very likely.

janiversen avatar Jun 14 '22 07:06 janiversen

Will increasing read timeout helps?

@dhoomakethu If you are pointing out the timeout which is getting specified as part of "connect" method, which is also passed to wait_for_data() and used as timeout then increasing that timeout is not helping us.

balaARR avatar Jun 16 '22 04:06 balaARR

@balaARR I would suggest to use a patched version of pymodbus if you think that helps. I couldn't find datasheet or modbus spec for the device (ic7 Danfoss drive with RS485 support ) and with out logs or anything else to take a more closer look there is nothing much we can do here.

dhoomakethu avatar Jun 17 '22 12:06 dhoomakethu

@dhoomakethu

Could you please let me know what kind of logs we need to provide for this issue? So, we will try to provide those logs accordingly.

balaARR avatar Jun 22 '22 05:06 balaARR

@balaARR just enable debug logs

dhoomakethu avatar Jul 13 '22 05:07 dhoomakethu

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 13 '22 03:08 github-actions[bot]

Still on the list to be corrected.

janiversen avatar Aug 13 '22 06:08 janiversen

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 13 '22 04:09 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 14 '22 04:10 github-actions[bot]

@balaARR please check with version 3.0.2, it should be solved.

janiversen avatar Nov 07 '22 06:11 janiversen

@janiversen Yeah sure will try. Thank you for sharing this information.

balaARR avatar Nov 07 '22 06:11 balaARR

I just added a commit on dev, that might help a bit more.

janiversen avatar Nov 11 '22 15:11 janiversen

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Dec 12 '22 02:12 github-actions[bot]

still open, getting close to the top of my list

janiversen avatar Dec 12 '22 07:12 janiversen

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Feb 15 '23 02:02 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Feb 20 '23 02:02 github-actions[bot]