Problem to communicate with PLC after setting up connection

See original GitHub issue

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!

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
mtrobackcommented, Mar 19, 2021

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.

1reaction
mtrobackcommented, Oct 25, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

PLC Ethernet Communication Issues - Support
Learn the basics about troubleshooting a PLC Ethernet Communication Issues. We discuss many tools that can be used to get to root cause....
Read more >
Why Can't I Connect to my PLC over Ethernet? - YouTube
Here are some tips for troubleshooting PC to PLC communications over Ethernet.Get the full details of this lesson at ...
Read more >
PLC communication error after being networked for a while
When i keep it locally with a switch and an HMI, everything goes fine but when i try to connect it tomy office...
Read more >
How to resolve the "Cannot open connection to PLC" error on ...
1) The IP address, Subnet Mask, or Default Gateway is setup incorrectly on the HMI or PLC. Ensure the settings are correct for...
Read more >
Connecting to Allen-Bradley PLCs - Ethernet - myPLCtraining
This post is all about connecting to an Allen-Bradley PLC using Ethernet communications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found