Broken reception: Modbus Error: [Input/Output] Unable to decode request

2,155 views
Skip to first unread message

Sophie Coates

unread,
Jun 1, 2021, 6:55:41 AM6/1/21
to pymodbus
Hi all,

I am running as a client of a Midea Gateway CCM-18A/N-U, which communicates with an air conditioning unit. My very basic test code is:

---

#!/usr/bin/env python3
# encoding: utf-8

from pymodbus.client.sync import ModbusTcpClient as mbTCPClient
import time

tcp_client = mbTCPClient("192.168.2.130", port=502, timeout=1)
if tcp_client.connect():
    print("Connected!")

else:
    print("Connection Failed!")
    exit()

while True:
    rr = tcp_client.read_input_registers(1, 3, unit=1)

if rr.isError():
    print(rr)
else:
    print("Read OK! " + str(rr.registers[1]))
    time.sleep(1)

---

I am able to connect to it but when I try to read coils or registers, the received packets are reported as errors: "Modbus Error: [Input/Output] Unable to decode request". I have tested this on a Raspberry Pi and a Windows PC, both using pymodbus version 2.5.2.

Curiously if I read 24 coils it works, so there may be some bizarre buffering going on that temporarily resolves the issue.

I am able to interrogate the same system using QModMaster and it appears quite happy to decode the packets and display the requested data.

I have run a Wireshark trace on the target's outgoing packets and it doesn't report them as being valid Modbus TCP frames, but [TCP segments of a reassembled PDU]. I can see that the packets that do arrive as a valid Modbus/TCP frame are assembled from a packet with data length 11, and another with data length 1 (12 bytes).

So my best guess is that pymodbus is seeing the first returned packet (11 bytes), maybe deciding it can't decode it due to the missing byte, then junking the remaining byte (which, ironically is the actual data value).

Does pymodbus know how to recombine split data packets?

Whilst writing this I feel I may have wandered into the solution though; can anyone tell me if I simply need to switch from Sync to Async operation?

Many thanks,

Soph 

Sophie Coates

unread,
Jun 2, 2021, 12:29:44 PM6/2/21
to pymodbus
I don't believe it's the fact I'm using Sync over Async, but pymodbus appears to be ignoring the second Modbus/TCP packet containing the data of interest.

DEBUG:pymodbus.transaction:Running transaction 20
DEBUG:pymodbus.transaction:SEND: 0x0 0x14 0x0 0x0 0x0 0x6 0x1 0x1 0x0 0x0 0x0 0x1
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Incomplete message received, Expected 12 bytes Recieved 10 bytes !!!!
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0x0 0x14 0x0 0x0 0x0 0x6 0x1 0x1 0x1 0x1
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x14 0x0 0x0 0x0 0x6 0x1 0x1 0x1 0x1
DEBUG:pymodbus.framer.socket_framer:Frame check failed, ignoring!!
DEBUG:pymodbus.transaction:Getting transaction 20
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response
DEBUG:pymodbus.transaction:Current transaction state - TRANSACTION_COMPLETE

I would appreciate any help please :)

Sanjay KV

unread,
Jun 2, 2021, 12:47:14 PM6/2/21
to pymo...@googlegroups.com
Unfortunately pymodbus does not have a foolproof solution with handling of incomplete data. There have been multiple attempts to fix but we get a new hardware with which the fix does not work. Having said that, here are the couple of things you can try.
1. Increase read timeout
2. Have some delay between reads.
3. Heck the pymodbus code to handle your hardware.




ಬುಧ, ಜೂನ್ 2, 2021 21:59 ದಿನಾಂಕದಂದು Sophie Coates <ipet...@gmail.com> ಅವರು ಬರೆದಿದ್ದಾರೆ:
--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pymodbus/d7747f34-704a-4690-afd9-5b63605ebab0n%40googlegroups.com.

Sophie Coates

unread,
Jun 2, 2021, 12:51:37 PM6/2/21
to pymodbus
Thanks for replying :)

1) I've tried most timeouts between 0.5 and 20 seconds (radical I know but had to try), no effect.
2) Delay between reads, as in inter character timeout (which I believe was only for RTU)?
3) Yeah it's looking that way...

It was just interesting that I could read coils only when I specified a count between 17 and 24, which might be related to your point 2), if you know of a method I haven't tried for Modbus/TCP?

Thanks!

Sanjay KV

unread,
Jun 2, 2021, 1:08:59 PM6/2/21
to pymo...@googlegroups.com
Can you confirm if the reads are working fine with the other client (qmodbus) (for count other than 17-24).




ಬುಧ, ಜೂನ್ 2, 2021 22:21 ದಿನಾಂಕದಂದು Sophie Coates <ipet...@gmail.com> ಅವರು ಬರೆದಿದ್ದಾರೆ:

Sophie Coates

unread,
Jun 2, 2021, 1:11:34 PM6/2/21
to pymodbus
Actually yes, QModMaster is quite happy reading as little as one byte continuously. It will report a connection fail after a few minutes though, but a reconnect resolves it.

Sanjay KV

unread,
Jun 2, 2021, 1:15:59 PM6/2/21
to pymo...@googlegroups.com
Cool, if you are using pymodbus 2.5.2, can you try `reset_socket=False` while initializing the client ? 

ಬುಧ, ಜೂನ್ 2, 2021 22:41 ದಿನಾಂಕದಂದು Sophie Coates <ipet...@gmail.com> ಅವರು ಬರೆದಿದ್ದಾರೆ:

Sophie Coates

unread,
Jun 2, 2021, 1:28:52 PM6/2/21
to pymodbus
On the RPi I'm testing on I'm running 2.4.0, but tried regardless. Sadly no improvement. 

"tcp_client = ModbusTcpClient(host="192.168.2.130", port=502, timeout=1, reset_socket=False)"

---

DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x1 0x0 0x0 0x0 0x1
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Incomplete message received, Expected 12 bytes Recieved 10 bytes !!!!
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x1 0x1 0x1
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x1 0x1 0x1
DEBUG:pymodbus.framer.socket_framer:Frame check failed, ignoring!!
DEBUG:pymodbus.transaction:Getting transaction 1
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response
DEBUG:pymodbus.transaction:Current transaction state - TRANSACTION_COMPLETE


Sanjay KV

unread,
Jun 2, 2021, 2:03:47 PM6/2/21
to pymo...@googlegroups.com
`reset_socket` is not available in 2.4.0, please try 2.5.2 

ಬುಧ, ಜೂನ್ 2, 2021 22:58 ದಿನಾಂಕದಂದು Sophie Coates <ipet...@gmail.com> ಅವರು ಬರೆದಿದ್ದಾರೆ:

Sophie Coates

unread,
Jun 2, 2021, 2:27:45 PM6/2/21
to pymodbus
I'm unable to find a release greater than 2.5.0rc2 for Python3 on this repo I'm afraid. I gave that a try as it was newer than what I had at least, but the error prevails.

Soph

Sophie Coates

unread,
Jun 2, 2021, 4:34:38 PM6/2/21
to pymodbus
Thanks for helping anyway. For the time being I'm going to use a different driver :)

Sanjay KV

unread,
Jun 2, 2021, 10:25:25 PM6/2/21
to pymo...@googlegroups.com
You should be able to update via pip . The latest on master is 2.5.2. refer https://github.com/riptideio/pymodbus/releases/tag/v2.5.2

ಬುಧ, ಜೂನ್ 2, 2021 23:57 ದಿನಾಂಕದಂದು Sophie Coates <ipet...@gmail.com> ಅವರು ಬರೆದಿದ್ದಾರೆ:

Sophie Coates

unread,
Jun 14, 2021, 5:07:00 PM6/14/21
to pymodbus
Apologies for the delay... but the issue continues...

Since we last discussed this, I have managed to install 2.5.2, and have included reset_socket=False into the initialisation code. Sadly this doesn't resolve the issue and pymodbus still refuses to process the received split message as a whole.

Soph

Sophie Coates

unread,
Jun 15, 2021, 3:40:04 AM6/15/21
to pymodbus
Just a note to say that 2.5.2 worked on a clean Raspberry Pi OS / Raspbian install; my initial target system uses Buster which is still having trouble sourcing 2.5.2, but that's not very pertinent to the issue at hand right now.

Artur Rubcov

unread,
Dec 22, 2021, 10:55:40 AM12/22/21
to pymodbus
Hi, I`m working a lot with different Modbus device, and few weeks ago I get same problem with Midea Gateway as you wrote earlier.  Reading with such apps as CasScanner or ModbusPoll it is OK. But using Pymodbus library I get same Error.  I spent few days to try find problem, but no results .... 

вторник, 15 июня 2021 г. в 10:40:04 UTC+3, Sophie Coates:
Reply all
Reply to author
Forward
0 new messages