pylibmodbus icon indicating copy to clipboard operation
pylibmodbus copied to clipboard

problem to connect with modbus_tcp

Open janvincke opened this issue 8 years ago • 2 comments

Hi Stephane,

i wrote some simple code to read the power value from a energy measurement device via modbus tcp. The code worked fine until I used it again today. The device is available and can be polled with other modbus clients. Somehow the connection is refused with Errno 115. Have there been any changes on the library or do you have an idea what might be the problem?

Thanks for your help! Jan

from pylibmodbus import modbus_tcp client = modbus_tcp.ModbusTcp('10.15.2.1', 502) client.connect() client.set_slave(2) ans = client.read_input_registers(19026, 2) num = struct.unpack('>f', struct.pack('>HH', ans[0], ans[1]))[0] client.close()

janvincke avatar Mar 08 '17 11:03 janvincke

I am having the same issue testing against libmodbus/tests/bandwidth-server-many-up


In [2]: import pylibmodbus

In [3]: a = pylibmodbus.modbus_tcp.ModbusTcp("127.0.0.1", 1502)

In [4]: a.connect()

In [5]: ffi.errno
Out[5]: 115

I tested with Python2 and Python3. In both cases I get this same behaviour.

oz123 avatar Mar 08 '17 12:03 oz123

I found the problem ... well, I was barking at the wrong tree. ffi.errno = 115 by itself is not a problem. We where wondering why a.set_slave was not working, and thought 115 was the problem.

The real problem was that we upgraded our python from 3.4 to 3.5 and as such had to create new venvs. We had installed this library from pip, but the pypi version is outdated ... and the pylibmodbus.modbus_tcp.ModbusTcp("127.0.0.1", 1502) doesn't give an object with set_slave method.

It would be great if you could release a new version to PyPI.

oz123 avatar Mar 08 '17 12:03 oz123

New release published on pypi. https://pypi.org/project/pylibmodbus/

stephane avatar Aug 17 '22 05:08 stephane