-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
I have a problem with receiving MEI message, when use UDP sync client and RtuFramer.
Versions
- Python 3.5.2 / Python 3.6.2
- OS: Ubuntu 16.04.4 LTS / Microsoft Windows [Version 10.0.10586]
- Pymodbus: 1.4.0
- Modbus Hardware (if used): RS-485 unit (slave) connected to hardware virtual serail gateway (ethernet)
Here comes a snippet of the code:
import logging
from pymodbus.client.sync import ModbusUdpClient
from pymodbus.transaction import ModbusRtuFramer as ModbusFramer
from pymodbus.mei_message import *
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
_logger = logging.getLogger(__name__)
with ModbusUdpClient(host='192.168.26.3', port=6014, framer=ModbusFramer, timeout=1) as client:
client.read_holding_registers(address=27, unit=199).registers
log.debug("Running ReadDeviceInformationRequest")
client.execute(ReadDeviceInformationRequest(unit=199))
I don't have any problems with read_holding_registers:
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:send: 0xc7 0x3 0x0 0x1b 0x0 0x1 0xe5 0x6b
DEBUG:pymodbus.transaction:recv: 0xc7 0x3 0x2 0x60 0xc7 0x59 0xc7
DEBUG:pymodbus.factory:Factory Response[3]
DEBUG:pymodbus.transaction:adding transaction 0
DEBUG:pymodbus.transaction:getting transaction 1
What about ReadDeviceInformation:
DEBUG:root:Running ReadDeviceInformationRequest
DEBUG:pymodbus.transaction:Running transaction 2
DEBUG:pymodbus.transaction:send: 0xc7 0x2b 0xe 0x1 0x0 0xf8 0x66
DEBUG:pymodbus.transaction:Expected - 1024 bytes, Actual - 78 bytes
DEBUG:pymodbus.transaction:Transaction failed. (timed out)
I've used debugger to find what causes problems and it seems that it's actually in transaction.py:
162: result = self.client._recv(expected_response_length or 1024)
163: while result and expected_response_length and len(
164: result) < expected_response_length:
With read_holding_registers: expected_response_length = 7 and it works fine.
With ReadDeviceInformation: expected_response_length = None
I thought it should work fine as well, but after self.client._recv value is expected_response_length = 1024
Why is this happening:
130: result = self._recv(expected_response_length or 1024)
If I change this line to:
130: result = self._recv(expected_response_length)
Than all works OK:
DEBUG:root:Running ReadDeviceInformationRequest
DEBUG:pymodbus.transaction:Running transaction 2
DEBUG:pymodbus.transaction:send: 0xc7 0x2b 0xe 0x1 0x0 0xf8 0x66
DEBUG:pymodbus.transaction:recv: 0xc7 0x2b 0xe 0x1 0x83 0x0 0x0 0x3 0x0 0xe 0x55 0x72 0x61 0x6c 0x54 0x65 0x78 0x49 0x73 0x20 0x4c 0x74 0x64 0x2e 0x1 0xf 0x55 0x52 0x50 0x54 0x2d 0x34 0x38 0x35 0x2e 0x31 0x2e 0x34 0x78 0x2d 0x78 0x2 0x21 0x34 0x2e 0x31 0x32 0x39 0x2d 0x31 0x30 0x20 0x28 0x4a 0x61 0x6e 0x20 0x32 0x35 0x20 0x32 0x30 0x31 0x37 0x20 0x40 0x20 0x31 0x30 0x3a 0x31 0x35 0x3a 0x34 0x39 0x29 0xeb 0xe9
DEBUG:pymodbus.factory:Factory Response[43]
DEBUG:pymodbus.transaction:adding transaction 0
DEBUG:pymodbus.transaction:getting transaction 2
{0: b'UralTexIs Ltd.', 1: b'URPT-485.1.4x-x', 2: b'4.129-10 (Jan 25 2017 @ 10:15:49)'}