0

I am encountering this error on the output : _recv MBAP error

My code is like this

from pyModbusTCP.client import ModbusClient


c = ModbusClient('192.168.0.7', port=502, debug=True, auto_open=True, auto_close=False)

if c.is_open == False:
            print('not connected')
else:
            print('connected')

print(c.unit_id())

c.write_single_coil(0,True)

and the output is this:

connected
1
Tx
[4A 62 00 00 00 06 01] 05 00 00 FF 00 
timeout error
_recv MBAP error

I tried to ping the IP address of the PLC and it returns a reply. Also i tried to replace the cable. The issue is still the same.

Brits
  • 14,829
  • 2
  • 18
  • 31
Jun
  • 49
  • 6
  • I'm a little confused by the output (would expect `c.is_open` to always be false because your code does nothing that would initiate a connection) - what version of `pyModbusTCP` are you using?. It looks like the connection is timing out. Please confirm you can query the device with a known good application (e.g. [mbpoll](https://github.com/epsilonrt/mbpoll)or [modpoll](https://www.modbusdriver.com/modpoll.html)) and post the results. – Brits Jul 23 '22 at 21:20
  • Hello, ty for your reply. The c.is_open would be always true & "connected" because I defined the auto_open = True. The version of pyModbusTCP is 0.2.0 something like that. I will try modpoll. – Jun Jul 25 '22 at 02:04
  • `auto_open = True` means PyModbusTCP automatically opens the connection [when you send a request](https://github.com/sourceperl/pyModbusTCP/blob/master/pyModbusTCP/client.py#L637) it's not opened by the call to `ModbusClient` (tested this myself). "something like that" - details matter (`0.2.0` is a major release); please see [how to ask](https://stackoverflow.com/help/how-to-ask). – Brits Jul 25 '22 at 02:45

0 Answers0