stlehmann / pyads

Python wrapper for TwinCAT ADS
MIT License
254 stars 94 forks source link

Docs: Improve description on how to connect and create routes from Linux #281

Open CreaM129129 opened 2 years ago

CreaM129129 commented 2 years ago

Hello, I appreciate your work on this module. It is very handy.

Unfortunately, I really struggle with connecting from Ubuntu. (On windows everything works fine) It seems I am not the only one. There are many git-issues covering this topic. I have unsuccessfully gone through several of them, only to find more, without actually solving the problem.

Please consider making a clear to follow cookbook on how to set routes and connect from Ubuntu. Thank you.

EDIT: I have finally managed to get this working and added a simple "guide" below.

chrisbeardy commented 2 years ago

https://pyads.readthedocs.io/en/latest/documentation/routing.html

This is the routing section which contains an adding routes to a target section.

This has been rewriten a few times and clearly is still not quite right.

To aid us, could you please give some specific feedback about what you struggled with and what would have aided you.

I have plans to do a video showing how to connect from Windows and Linux. Would this be a good idea?

CreaM129129 commented 2 years ago

https://pyads.readthedocs.io/en/latest/documentation/routing.html This is the routing section which contains an adding routes to a target section.

Yes, this is the page of documentation I struggle with.

This has been rewriten a few times and clearly is still not quite right.

To aid us, could you please give some specific feedback about what you struggled with and what would have aided you.

  • I am confused by owerall order of chapters (Creating routes on Linux and below). There are two notes and one warning. This makes me jump up and down in the text, quickly losing myself, even though text is very short. I think a less general example, but with clear order of instructions would help me more.

Yes, video is a brilliant idea.

CreaM129129 commented 2 years ago

I finally managed to get the connection working. I decided to make this little "guide" on how to setup the routes.

Lets assume two computers on the same lan (I have disabled firewalls on both of them):

Target PC

Client PC

Goal is to read and change variables of PLC (running on Target PC) from Python script (Client PC)

1. SET ROUTE ON TARGET PC, USING TWINCAT:

2. Obtain TARGET_AMS_ID from Target PC:

3. Finnaly our python script on Client PC:

import pyads

pyads.open_port()
# CLIENT PC IP with .1.1 at the end (we added this when creating route via TwinCat):
CLIENT_AMS_NET_ID = "172.18.10.178.1.1"
pyads.set_local_address(CLIENT_AMS_NET_ID)
pyads.close_port()
# pass
# connect to plc and open connection
# route is added automatically to client on Linux, on Windows use the TwinCAT router
# we obtained TARGET_AMS_ID in step 2:
TARGET_AMS_ID = "192.168.0.31.1.1"
# regular ip address of target pc:
TARGET_PC_ID = "172.18.10.112"
plc = pyads.Connection(TARGET_AMS_ID, 851, TARGET_PC_ID)
plc.open()
# in MAIN in my PLC i have bool variable bRunOnlyOnce
b = plc.read_by_name("MAIN.bRunOnlyOnce")
print(b)
plc.write_by_name("MAIN.bRunOnlyOnce", False)
exit()

Don't forget to run your PLC. As I discovered both TwinCAT and pyads very recently feel free to edit/correct this. This issue helped me to make everything working and create this post.

chrisbeardy commented 2 years ago

We can look at adding a more step by step guide to create a route and possibly add a video too. Thanks for this.

kryskool commented 2 years ago

Hi @CreaM129129

In Windows, Twincat -> About Twincat, give you the AmsId

Regards,

mtroback commented 2 years ago

I've tried to fix the documentation in this pull request: https://github.com/stlehmann/pyads/pull/278

kryskool commented 1 year ago

@stlehmann can you activate Discussion feature on this repository, this ticket can be move on discussion( eg: Tutorial category)

And Discussion can be a better for people ask for question

Regards,