pyads: Problem to communicate with PLC after setting up connection

Hi, This is probably not the best way to ask questions, maybe I should turn to stackoverflow instead, but I figure this is the best shot at getting good answers.

I’ve successfully set up pyads on my windows computer and I am able to use the pyads.read_by_name function without problems. It took me a while to figure out stuff, but it’s working.

Now I have moved to my Raspberry Pi trying to communicate with the same PLC. This time it is trickier in the sense that I have to setup my own route. I have tried to follow the example in the Quickstart and I can successfully set up the route, but just for the sake of understanding from my point of view I have a quick question: The Client addresses are supposed to be the computer on which I am running python? So I choose the CLIENT_NETID by using the computer IP and add .1.1? And the CLIENT_IP is the computers IP? The the TARGET_* is all the information of the PLC?

Then I don’t understand why you use a NetId pointing at the computer localhost IP when you set up a connection. This was unsuccessfull for me, but it was successfull using a NetId of the target IP instead (tracebacks omitted for the sake of clarity, 192.168.3.1 is the raspberry pi, 192.168.3.9 is the PLC):

In [3]: pyads.add_route_to_plc('192.168.3.1.1.1', '192.168.3.1', '192.168.3.9', 'Administrator', '1', route_name='route')
Out[3]: True

In [4]: plc = pyads.Connection('127.0.0.1.1.1', 851)

In [5]: plc.open()
2021-03-10T14:35:01+0100 Error: Connect TCP socket failed with: 111
------
ADSError: ADSError: target port not found   ADS Server not started (6).

In [6]: plc = pyads.Connection('192.168.3.9.1.1', 851)

In [7]: plc.open()
2021-03-10T14:35:20+0100 Info: Connected to 192.168.3.9

In [8]: plc.read_device_info()
---------------------------------------------------------------------------
ADSError                                  Traceback (most recent call last)

ADSError: ADSError: target machine not found    Missing ADS routes (7).

In [9]: plc.read_by_name('MAIN.IN_1')
---------------------------------------------------------------------------
ADSError                                  Traceback (most recent call last)

ADSError: ADSError: target machine not found    Missing ADS routes (7).

So it looks like it is connected, but the route is missing? Can you spot what I’m doing wrong here?

I’m writing from my windows computer which has TwinCAT running and route set up in the background from the windows computer to the PLC I assume, could this be a problem? I am not connected from the windows computer.

I understand that you are working on this on the side, and if you don’t have time for this type of questions I’ll try to ask Beckhoff support and see how they can help me. Thanks for a great project!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Wow, I must say that I really appreciate all the work all of you have put into this project, without it I wouldn’t even consider using a Beckhoff PLC in my application.

Could you please give me a hint where exactly this is this written in the docs? Must be a leftover or an older documentation?

It turns out that if I read all of the text, you do need to create a route from the target to the client as well, but I only read up to the example code: To create a new route on Linux you can simply use the Connection class. It connects to the target and creates a route to it on your client.

And I think the documentation is really good, it is simply difficult for me as a beginner whom has never worked with PLC before.

But now I clearly understand that the add_route_to_plc doesn’t add a route from the client to the PLC/target, it adds the “reverse” route which is needed from the PLC/target to the client (so that the target can communicate with the client I assume). Nice work of reverse-engineering there! And I guess this is why the username/password is needed, in order to log in to the PLC/target and make changes.

Thank you so much for all your help and explanations.

I’m back at working with the PLC so I will rebase and get things in a shape where I can create a PR. Some impressive progress in the project during the summer, great work you’ve done!

@chrisbeardy I think I have it all figured out now, thanks! It will probably take a week or two, but I’ll start working on it 😃

I can help you on this. This weekend I shall try to outline it then if you create a fork and new branch for doc changes, (if it is just doc changes do not worry about running black or tox.) I can then help out and when ready you can create a PR which @stlehmann can review and merge.