PyAds on Windows 11 <-> CX9020 Connection Issue : RuntimeError("Failed to open port on AMS router."

81 views Asked by At

For the past few days, I have been trying to connect to the cx9020 controller using pyads. Unfortunately, I am unable to resolve the error:RuntimeError(Failed to open port on AMS router)

Traceback (most recent call last): File "E:\3. Projekty\Slawek PyADS\PyAds.py", line 12, in <module> plc.open() File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyads\connection.py", line 195, in open self._port = adsPortOpenEx()
                 ^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyads\pyads_ex.py", line 434, in adsPortOpenEx raise RuntimeError("Failed to open port on AMS router.") RuntimeError: Failed to open port on AMS router.

I have no problems connecting to the controller using TwinCAT, so the routing is working correctly. However, I don't know why Python is not accepting it.

import sys
import pyads

PLC_AMS_ID= '5.55.250.81.1.1'
SENDER_AMS = '192.168.0.5.1.1'
PLC_IP = '192.168.0.8'
HOST_IP = '192.168.0.5'  # or IP
PLC_USERNAME = 'Administrator'
PLC_PASSWORD = '1'
ROUTE_NAME = 'CX-37FA51'

plc = pyads.Connection(PLC_AMS_ID, 801,HOST_IP)
with plc:
    print(f"Connected?: {plc.is_open}") #debugging statement, optional
    print(f"Local Address? : {plc.get_local_address()}") #debugging statement, optional

In TwinCat2 Plc port is 801.

I am calling script from prompt with command :

python PyAds.py

If someone has any ideas or experience on how to fix this, I will be forever grateful.

1

There are 1 answers

0
Dawid Firlej On

The solution was to reinstall python with all permissions, and open script with command: 'py PyAds.py'