I am trying to connect a Windows PC to a Beckhoff PLC using pyads library. I installed Twincat ADS 3.1 on my Windows PC and created routes both on the PC and the PLC. When testing the connection with TcAdsTest (in the Twincat folder), everything works fine. But with my python script, I get an error message : "Failed to open port on AMS router".
My python code is as follows :
import pyads
plc = pyads.Connection('5.134.132.47.1.1', 851, '10.10.13.200')
plc.open()
I also converted my python script into an executable file. When I launch the .exe, the connection is successfull. It seems that only the .py leads to an error.
Is there some issue with my admin rights on the python script ? I tried running my .py with VSCode as Administrator but I still get the same error message.
I managed to solve the issue by reinstalling python ! My python.exe was originally downloaded from the Microsoft Store. Its path was ~AppData\Local\Microsoft\WindowsApps\python3.11.exe. I uninstalled it and downloaled Python3.11.7 from python.org. The new path is ~AppData\Local\Programs\Python\Python311\python.exe
Everything seems to work now.