-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
Versions
- Python: 3.9.2
- OS: Alpine Linux v.3.13 (on Docker 19.03.13)
- Pymodbus: v.2.5.0
- Modbus Hardware (if used): Modbus TCP, no specific hardware
Pymodbus Specific
- Server: tcp/rtu/ascii - sync/async
- Client: tcp/rtu/ascii - sync/async
Description
What were you trying, what has happened, what went wrong, and what did you expect?
Trying to connect to my SolarEdge SE3000H like on version v.2.4.0. Since v.2.5.0 however this always results in connection refused.
The weird thing however is that Wireshark/tcpdump shows a full SYN, SYN/ACK, ACK and even data transferred in both ways.
Reverting back (pymodbus==2.4.0) immediately solves the issue.
Code and Logs
2021-03-09 21:17:36,938 [pymodbus.client.sync] ERROR Connection to (10.10.180.50, 1502) failed: [Errno 111] Connection refused
Traceback (most recent call last):
File "/usr/src/app/test.py", line 38, in <module>
ans = client.read_holding_registers(address=SUNSPEC_I_MODEL_BLOCK_START, count=52, unit=1)
File "/usr/local/lib/python3.9/site-packages/pymodbus/client/common.py", line 114, in read_holding_registers
return self.execute(request)
File "/usr/local/lib/python3.9/site-packages/pymodbus/client/sync.py", line 108, in execute
raise ConnectionException("Failed to connect[%s]" % (self.__str__()))
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(10.10.180.50:1502)]
09:47:49.870838 IP 10.10.178.7.35007 > 10.10.180.50.1502: Flags [S], seq 1105518497, win 64240, options [mss 1460,sackOK,TS val 1785985442 ecr 0,nop,wscale 7], length 0
09:47:49.871287 IP 10.10.180.50.1502 > 10.10.178.7.35007: Flags [S.], seq 3895959532, ack 1105518498, win 28960, options [mss 1460,sackOK,TS val 146021264 ecr 1785985442,nop,wscale 4], length 0
09:47:49.871762 IP 10.10.178.7.35007 > 10.10.180.50.1502: Flags [.], ack 1, win 502, options [nop,nop,TS val 1785985443 ecr 146021264], length 0
09:47:49.871845 IP 10.10.178.7.35007 > 10.10.180.50.1502: Flags [P.], seq 1:13, ack 1, win 502, options [nop,nop,TS val 1785985443 ecr 146021264], length 12
09:47:49.872169 IP 10.10.180.50.1502 > 10.10.178.7.35007: Flags [.], ack 13, win 1810, options [nop,nop,TS val 146021264 ecr 1785985443], length 0
09:47:49.899171 IP 10.10.180.50.1502 > 10.10.178.7.35007: Flags [P.], seq 1:148, ack 13, win 1810, options [nop,nop,TS val 146021294 ecr 1785985443], length 147
09:47:49.899663 IP 10.10.178.7.35007 > 10.10.180.50.1502: Flags [.], ack 148, win 501, options [nop,nop,TS val 1785985471 ecr 146021294], length 0
09:47:49.900306 IP 10.10.178.7.35007 > 10.10.180.50.1502: Flags [F.], seq 13, ack 148, win 501, options [nop,nop,TS val 1785985471 ecr 146021294], length 0
09:47:49.900391 IP 10.10.178.7.40655 > 10.10.180.50.1502: Flags [S], seq 1860378655, win 64240, options [mss 1460,sackOK,TS val 1785985471 ecr 0,nop,wscale 7], length 0
09:47:49.900777 IP 10.10.180.50.1502 > 10.10.178.7.40655: Flags [R.], seq 0, ack 1860378656, win 0, length 0
09:47:49.906846 IP 10.10.180.50.1502 > 10.10.178.7.35007: Flags [F.], seq 148, ack 14, win 1810, options [nop,nop,TS val 146021304 ecr 1785985471], length 0
09:47:49.907309 IP 10.10.178.7.35007 > 10.10.180.50.1502: Flags [.], ack 149, win 501, options [nop,nop,TS val 1785985479 ecr 146021304], length 0
#!/usr/bin/python3
import struct
from struct import pack, unpack
from pymodbus.client.sync import ModbusTcpClient
from collections import namedtuple
from pprint import pprint
import logging
import json
from time import sleep
formatter = logging.Formatter('%(asctime)s [%(name)-12s] %(levelname)-8s %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logging.getLogger('pymodbus').addHandler(handler)
solaredge = {
"ip": "10.10.180.50", # SolarEdge
"port": 1502
}
SUNSPEC_I_COMMON_BLOCK_START = 40000
SUNSPEC_I_MODEL_BLOCK_START = 40069
client = ModbusTcpClient(solaredge['ip'], solaredge['port'])
ans = client.read_holding_registers(address=SUNSPEC_I_COMMON_BLOCK_START, count=69, unit=1)
assert(not ans.isError())
blob = pack(">69H", *ans.registers)
logger.debug(blob)
ans = client.read_holding_registers(address=SUNSPEC_I_MODEL_BLOCK_START, count=52, unit=1)
assert(not ans.isError())
blob = pack(">52H", *ans.registers)
logger.debug(blob)
client.close()