pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.17k stars 891 forks source link

WinError 10054 An existing connection was forcibly closed by the remote host #2015

Closed dkhawajafaithtechinc closed 4 months ago

dkhawajafaithtechinc commented 4 months ago

Versions

Pymodbus Specific

Description

My team and I have been attempting to read modbus data from a device using PyModbus. We are able to read from this device from 6-7 different modbus technologies, but pymodbus is the only one that is giving us this error: WinError 10054 An existing connection was forcibly closed by the remote host. Seems that the modbus server is shutting down the connection whenever we are trying to read data from it.

Code and Logs

# code and logs here.

from pymodbus.client import ModbusTcpClient

client = ModbusTcpClient('10.10.10.101', port=502)   # Create client object
client.connect()                           # connect to device, reconnect automatically
result = client.read_holding_registers(53236)  # get information from device
print(result)                      # use information
client.close()

Please see the image attached for the logs

logs

janiversen commented 4 months ago

your device do not respond.

A couple of potential problems:

In any case your device do not like the request....if it works with other technologies, then do a trace and check the difference in the package.

dkhawajafaithtechinc commented 4 months ago

Yes we already tried specifying those as well like this: rr = client.read_holding_registers(53236, 1, 1)

janiversen commented 4 months ago

That is not according to our examples, please read the documentation or at least follow the examples, slave is NOT a positional parameter.

Did you look in the debug log and control that the slave changed to 1 ?

dkhawajafaithtechinc commented 4 months ago

I apologize, seems that we got it worked out. We were initially using this: rr = client.read_holding_registers(address=53236, count=1, unit=1)

But the parameters were incorrect so when using this, it worked: rr = client.read_holding_registers(53236, 1, 1) I believe we can close this issue now

dkhawajafaithtechinc commented 4 months ago

Just a quick question, what exactly does the slave parameter do?