Issue
I am trying to communicate my Linux pc to Beckhoff CX9020 PLC. When I tried routing commands I am geting some errors. I think the errors are due to the wrong addresses I wrote. How can get this values ? On Windows or Linux is enough ?
pyads.set_local_address ('1.2.3.4.1.1')
pyads.add_route ('5.41.49.218.1.1', '192.168.0.8')
SENDER_AMS = '1.2.3.4.1.1'
PLC_IP = '192.168.0.8'
PLC_USERNAME = 'Administrator'
PLC_PASSWORD = 'x'
ROUTE_NAME = 'RouteToMyPC'
CLIENT_IP = "192.168.1.10"
TARGET_IP = "192.168.1.11"
TARGET_USERNAME = "Administrator"
TARGET_PASSWORD = "1"
HOSTNAME = '192.168.0.8' # or IP
PLC_AMS_ID = '5.41.49.218.1.1'
CLIENT_NETID = "192.168.1.10.1.1"
There is some values using in pyads. Which ones must be equal .How can I find them? Thanks for your help.
Solution
you must create a route from the PLC (CX9020) to the Client (Ubuntu).
I would start by deleting any routes already created if you have been struggling in case these get in the way. I would do this by plugging the CX into a monitor, keyboard and mouse and using the TwinCat route editor by right clicking on TwinCat icon in right hand side of toolbar. Also take note of the AMS net id of the CX by clicking on "Change Net ID".
Then connect the CX and the Ubuntu PC onto your network, take note of the IP addresses of both the CX and Ubuntu PC.
Then follow the instructions here:
https://pyads.readthedocs.io/en/latest/documentation/routing.html#adding-routes-to-a-target
where:
Sender AMS = IP address of Ubuntu PC + ".1.1"
PLC IP = IP address of CX
if you have not changed them the username and password for the CX, it should be "Administrator" and "1".
Route NAme is your choice (you can leave it out, its an optional parameter in the python code)
Host name = IP address of the CX
This should add a route in the routing table of the CX, which you can check using the monitor, keyboard and mouse.
You only need to do this once and not every time you run python code.
Then when you connect you should use the following:
import pyads
with pyads.Connection(remote_ads, pyads.PORT_TC3PLC1) as plc:
...
where remote_ads is the AMS net id of the CX you recorded earlier.
Please try this and post any errors you get.
Note, you should (normally) see a route in the routing table of the CX for whatever windows PC that was used to program it, as before you can connect to any CX using TwinCat Engineering you must also create a route, we are just doing the same thing here but needing to create a route between the CX and the ubuntu PC. If you are struggling with creating a route using Ubuntu, it may be useful to create a route using the add route dialog on a windows pc (in the same way you would need to program the CX) and running pyads on windows so you can get a feel for the what is required.
Answered By - chrisbeardy Answer Checked By - David Marino (WPSolving Volunteer)