Open CreaM129129 opened 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?
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.
For every constant eg. "SENDER_AMS", "PLC_IP"... I would love a note where can one get these values, why are they set and named like this and if there are some defaults values I shoud use (like "Administrator" and "1" for PLC_USERNAME and PLC_PASSWORD)
Adding a section with common errors and their solution woud also be nice. Some common errors I found mutiple times:
-Unexpected response from PLC: b"\x03f\x14q\x00\x00\x00\x00\x06\x00\x00\x80\xc0\xa8\x00\x1f\x01\x01\x10'\x01\x00\x00\x00\x01\x00\x04\x00\x04\x07\x00\x00"
-ADSError: ADSError: target port not found ADS Server not started (6).
-Info: connection closed by remote
Actually im not even sure I shoud/shoud not/have to set the route in Twincat using Edit Routes Window. If So, please add images of how to do so.
I have plans to do a video showing how to connect from Windows and Linux. Would this be a good idea?
Yes, video is a brilliant idea.
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
TARGET_PC_ID = "172.18.10.112"
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.
We can look at adding a more step by step guide to create a route and possibly add a video too. Thanks for this.
Hi @CreaM129129
In Windows, Twincat -> About Twincat, give you the AmsId
Regards,
I've tried to fix the documentation in this pull request: https://github.com/stlehmann/pyads/pull/278
@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,
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.