-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Versions
- Python: 3.11
- OS: Windows 11
- Pymodbus: 3.6.4
- Modbus Hardware (if used): -
Pymodbus Specific
- Server: tcp/async
- Client: tcp/async
Description
First, great thanks fot that product!!
In my project I use sevetal conponents wiht pymodbus
one read data from sources, process it and exports through MBServer
another read it, send to UI and so on.
All worked at 3.4.3 for several month
till I try to update to latest ver 3.6.4
so MB Server sometimes begin to rise
'Unknown exception "unpack requires a buffer of 4 bytes" on stream server forcing disconnect'
so I repeat update step by step from 3.4.3 to trace beginning of problem
it begins from 3.6.2->3.63 update
exception is rising here:
pymodbus/pymodbus/register_read_message.py
Lines 43 to 48 in b4490ab
| def decode(self, data): | |
| """Decode a register request packet. | |
| :param data: The request to decode | |
| """ | |
| self.address, self.count = struct.unpack(">HH", data) |
debug shows that data is 5 bytes sometimes
maybe it related to "solve Socket_framer problem with Exception response (#1925)"
I view logs and see strange packets like this:
2024-02-14 17:35:57,574 MainThread DEBUG logging :103 Processing: 0x8 0xa4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa3 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
Is it correct?
when process such packet socet framer send 5 bytes data to decoder from here:
pymodbus/pymodbus/framer/socket_framer.py
Lines 145 to 146 in b4490ab
| data = self._buffer if error else self.getFrame() | |
| if (result := self.decoder.decode(data)) is None: |
and self.getFrame() frame length is what was changed at 3.6.3 (#1925)
Here is log part of 3.6.3 with
2024-02-14 17:35:57,355 - normal packet
2024-02-14 17:35:57,574 - ''double'' packet
2024-02-14 17:35:58,305 - next normal packet
Code and Logs
2024-02-14 17:35:57,355 MainThread DEBUG logging :103 Processing: 0xf 0x3b 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x0 0x2
2024-02-14 17:35:57,356 MainThread DEBUG logging :103 Factory Response[ReadHoldingRegistersResponse': 3]
2024-02-14 17:35:57,356 MainThread DEBUG logging :103 Getting transaction 3899
2024-02-14 17:35:57,356 MainThread DEBUG logging :103 send: 0xf 0x3c 0x0 0x0 0x0 0x6 0x1 0x1 0x0 0x0 0x0 0x1
2024-02-14 17:35:57,357 MainThread DEBUG logging :103 Adding transaction 3900
2024-02-14 17:35:57,371 MainThread DEBUG logging :103 recv: 0xf 0x3c 0x0 0x0 0x0 0x4 0x1 0x1 0x1 0x0 old_data: addr=None
2024-02-14 17:35:57,372 MainThread DEBUG logging :103 Processing: 0xf 0x3c 0x0 0x0 0x0 0x4 0x1 0x1 0x1 0x0
2024-02-14 17:35:57,372 MainThread DEBUG logging :103 Factory Response[ReadCoilsResponse': 1]
2024-02-14 17:35:57,372 MainThread DEBUG logging :103 Getting transaction 3900
2024-02-14 17:35:57,573 MainThread DEBUG logging :103 recv: 0x8 0xa4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa3 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 old_data: addr=None
2024-02-14 17:35:57,574 MainThread DEBUG logging :103 Handling data: 0x8 0xa4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa3 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
2024-02-14 17:35:57,574 MainThread DEBUG logging :103 Processing: 0x8 0xa4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa3 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
2024-02-14 17:35:57,574 MainThread DEBUG logging :103 Factory Request[ReadHoldingRegistersRequest': 3]
exception at framer _process decode call: unpack requires a buffer of 4 bytes
exception att framer _process decode call: b'\x03\x00\x16\x00\x02\x08'
2024-02-14 17:35:57,575 MainThread DEBUG logging :103 Resetting frame - Current Frame in buffer - 0x8 0xa4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa3 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
exception at processIncomingPacket: Modbus Error: [Input/Output] Unable to decode request
exception at processIncomingPacket data: b'\x08\xa4\x00\x00\x00\x06\x01\x03\x00\x16\x00\x02\x08\xa3\x00\x00\x00\x06\x01\x03\x00\x16\x00\x02'
exception at processIncomingPacket slave: [1]
2024-02-14 17:35:57,605 MainThread DEBUG logging :103 recv: 0x8 0xa5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa6 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 old_data: addr=None
2024-02-14 17:35:57,606 MainThread DEBUG logging :103 Handling data: 0x8 0xa5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa6 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
2024-02-14 17:35:57,606 MainThread DEBUG logging :103 Processing: 0x8 0xa5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa6 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
2024-02-14 17:35:57,606 MainThread DEBUG logging :103 Factory Request[ReadHoldingRegistersRequest': 3]
exception at framer _process decode call: unpack requires a buffer of 4 bytes
exception att framer _process decode call: b'\x03\x00\x16\x00\x02\x08'
2024-02-14 17:35:57,607 MainThread DEBUG logging :103 Resetting frame - Current Frame in buffer - 0x8 0xa5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2 0x8 0xa6 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x16 0x0 0x2
exception at processIncomingPacket: Modbus Error: [Input/Output] Unable to decode request
exception at processIncomingPacket data: b'\x08\xa5\x00\x00\x00\x06\x01\x03\x00\x16\x00\x02\x08\xa6\x00\x00\x00\x06\x01\x03\x00\x16\x00\x02'
exception at processIncomingPacket slave: [1]
2024-02-14 17:35:58,305 MainThread DEBUG logging :103 send: 0x6 0x21 0x0 0x0 0x0 0x6 0x1 0x2 0x0 0x0 0x0 0x8
2024-02-14 17:35:58,305 MainThread DEBUG logging :103 Adding transaction 1569
2024-02-14 17:35:58,306 MainThread DEBUG logging :103 send: 0xf 0x3d 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x0 0x0 0x2
2024-02-14 17:35:58,306 MainThread DEBUG logging :103 Adding transaction 3901
2024-02-14 17:35:58,307 MainThread DEBUG logging :103 setValues[3] address-1: count-2
2024-02-14 17:35:58,308 MainThread DEBUG logging :103 setValues[3] address-5: count-1
2024-02-14 17:35:58,308 MainThread DEBUG logging :103 setValues[3] address-17: count-2
2024-02-14 17:35:58,308 MainThread DEBUG logging :103 setValues[3] address-19: count-2
2024-02-14 17:35:58,308 MainThread DEBUG logging :103 setValues[3] address-21: count-2
2024-02-14 17:35:58,308 MainThread DEBUG logging :103 setValues[3] address-23: count-2
2024-02-14 17:35:58,309 MainThread DEBUG logging :103 setValues[3] address-25: count-2
2024-02-14 17:35:58,320 MainThread DEBUG logging :103 recv: 0xf 0x3d 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0x0 0x0 0x0 0x98 old_data: addr=None
2024-02-14 17:35:58,320 MainThread DEBUG logging :103 Processing: 0xf 0x3d 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0x0 0x0 0x0 0x98
2024-02-14 17:35:58,320 MainThread DEBUG logging :103 Factory Response[ReadHoldingRegistersResponse': 3]
2024-02-14 17:35:58,322 MainThread DEBUG logging :103 Getting transaction 3901