stlehmann / pyads

Python wrapper for TwinCAT ADS
MIT License
252 stars 93 forks source link

Connecting to localhost not working on python 3.10 #315

Closed james089 closed 10 months ago

james089 commented 2 years ago

How can I connect to local PLC using PyAds when my Pyads is running on PLC itself???

If we write our code in C#, we don't have to add any route since it is the same PC, we create adsClient and connection using Port 851 only.

But for PyAds running on PLC itself, I tried to do the same thing:

  1. I can't pass Port only(like, plc = pyads.Connection(851)) , it requires a AmsNetID.
  2. When I pass AmsNetID of the PLC, it shows "Failed to open port on AMS router".
james089 commented 2 years ago

Update: python version has to be < 3.10, tried 3.9.x, it works right away, but in 3.10, it doesn't work.

chrisbeardy commented 2 years ago

I always do this:

pyads.open_port()
ams_net_id = pyads.get_local_address().netid
pyads.close_port()
port = 851
plc = pyads.Connection(ams_net_id, port)

not sure why you couldn't connect on python 3.10, we will have to look into this

Can you please close this issue if your problem is solved, many thanks.

summerxiahuang commented 2 years ago

I changed my python version from 3.10 to 3.9 and it works.

chrisbeardy commented 2 years ago

@james089 or @stlehmann can we change the title of this issue to "Connecting to localhost not working on python 3.10" to easily differentiate this

RobertoRoos commented 1 year ago

I have a fairly fresh install of Python 3.10 (running Windows 10) and I can connect to the local PLC without any problems.