Closed AlexanderLanin closed 9 months ago
Let's start by the basic, the mdap header (first 7 bytes) says the data length is 2, and you receive 84 02.... why do you think you only receive 84 ?
A modbus package is minimum 2 byte (funcion code and data byte).
But anyhow if the code change solve your problem, then please submit a pull request so other can benefit from it.
I am still wondering why wireshark says it is a malformed mode tcp-packet, that seems to be another problem.
@janiversen Unfortunately I have no idea about modbus, but I followed the data a little following your 2 byte hint.
The second byte is truncated here (error = False): https://github.com/pymodbus-dev/pymodbus/blob/6913e9c829009f3704f75d7cb7fff019c27c6770/pymodbus/framer/socket_framer.py#L144
So a totally different code change that fixes my problem is deleting the - 1
from those two lines:
https://github.com/pymodbus-dev/pymodbus/blob/6913e9c829009f3704f75d7cb7fff019c27c6770/pymodbus/framer/socket_framer.py#L99
https://github.com/pymodbus-dev/pymodbus/blob/6913e9c829009f3704f75d7cb7fff019c27c6770/pymodbus/framer/socket_framer.py#L80
By doing that, I get an IllegalAddress
instead of an IllegalFunction
which does sound even better. But I have no idea what deleting the - 1
breaks.
I will take a closer look later this week, I can easily simulate the wireshark packet.
P.S. I mentioned the data is only 0x84. That's what I get looking at data
in _helper
. That's because in the debug log above self._buffer
is printed. However, as you see in the code above, self._buffer
is not being used! It's using the value from getFrame()
.
Solved in #1925
Versions
Pymodbus Specific
Description
Current State
When I query my sungrow inverter with a register I'm not supposed to be querying, I'm gettting a malformed package and the connection is dopped.
Wireshark:
TCP Payload: 00 02 00 00 00 02 01 84 02
Request
This line of code assumes that
data
has more than a single element. However,data
in my case is only b'\x84'. The response is being assigned correctly: Exception Response(132, 4, IllegalFunction) But in the marked line I'm getting an pymodbus.logging:General exception: index out of rangeSee https://github.com/pymodbus-dev/pymodbus/blob/6913e9c829009f3704f75d7cb7fff019c27c6770/pymodbus/factory.py#L351
I can fix this locally by changing
to
but I really have no idea what I'm doing here.
However that change allows me to handle the error super nicely on the response object:
Code and Logs