I would like to connect my Beckhoff CX5230 (Win10) to a Linux PC via PyADS. A topic that has been discussed here several times, but no solution has worked for me so far.
First, I created a route on the PLC from my Linux:
import pyads
SENDER_AMS = '5.97.120.143.1.1'
PLC_IP = '192.168.0.1'
PLC_USERNAME = 'Administrator'
PLC_PASSWORD = '1'
ROUTE_NAME = 'RouteToPC'
HOSTNAME = '192.168.0.1'
pyads.open_port()
pyads.set_local_address(SENDER_AMS)
pyads.add_route_to_plc(SENDER_AMS, HOSTNAME, PLC_IP, PLC_USERNAME, PLC_PASSWORD, route_name=ROUTE_NAME)
pyads.close_port()
That has worked well enough so far. I connected a monitor to the Beckhoff and saw that a new route had been created.
Next, I try to establish a connection from my PC to the PLC:
import pyads
SENDER_AMS = '5.97.120.143.1.1'
PLC_IP = '192.168.0.1'
plc = pyads.Connection(SENDER_AMS, pyads.PORT_TC3PLC1, PLC_IP)
plc.open()
print(f"Connected?: {plc.is_open}")
print(f"Local Address? : {plc.get_local_address()}")
print(plc.read_state())
When I run the script, the following error occurs:
2024-06-12T17:28:09+0000 Info: Connected to 192.168.0.1
Connected?: True
Local Address? : <AmsAddress 192.168.0.253.1.1:30000>
Traceback (most recent call last):
File "pyads_test.py", line 24, in <module>
print(plc.read_state())
File "/home/builder/.local/lib/python3.7/site-packages/pyads/connection.py", line 237, in read_state
return adsSyncReadStateReqEx(self._port, self._adr)
File "/home/builder/.local/lib/python3.7/site-packages/pyads/pyads_ex.py", line 510, in adsSyncReadStateReqEx
raise ADSError(error_code)
pyads.pyads_ex.ADSError: ADSError: timeout elapsed (1861).
2024-06-12T17:28:14+0000 Info: connection closed by remote
Does anyone have an idea where the problem could be? Is it possible to specify a dedicated port?