Open AndyEverything opened 2 weeks ago
Many thanks for the detailed instructions. I have a Linux PC (Ubuntu) and would like to connect to a Beckhoff. The firewalls are off on both devices and the PLC is in run mode. I have created the route from the PLC to the PC manually according to the instructions.
I run my Python script on the Linux PC:
import pyads
TARGET_AMS_ID = "5.97.120.143.1.1"
TARGET_PC_ID = "192.168.0.1"
plc = pyads.Connection(TARGET_AMS_ID, pyads.PORT_TC3PLC1, TARGET_PC_ID)
plc.open()
device_name, version = plc.read_device_info()
print(str(device_name) + ' ' + str(version))
print(f"Connected?: {plc.is_open}")
print(f"Local Address? : {plc.get_local_address()}")
print(plc.read_state())
plc.read_by_name("MAIN.test", pyads.PLCTYPE_INT)
exit()
I receive the following feedback:
~$ python3 pyads_test.py
2024-06-19T07:44:04+0000 Info: Connected to 192.168.0.1
Plc30 App <pyads.structs.AdsVersion object at 0x7f67198859d0>
Connected?: True
Local Address? : <AmsAddress 192.168.0.253.1.1:30000>
(5, 0)
2024-06-19T07:44:04+0000 Info: connection closed by remote
For me, it looks like I can make a connection. Otherwise I wouldn't be able to read out the status. I could also create the route via add_route_to_plc. In this case, I have done it manually again. Nevertheless, the connection is closed by romete. Do you have a clue as to what the problem could be?
Yes, it looks like you are creating a connection ok as you can ready the running state of the PLC (5 is PLC run). I am not sure what is now causing this to disconnect. What versions of python, twincat, ubuntu and pyads are you using? Are there any firewalls set up?
I have an Ubuntu 18.04.6 LTS with
The PLC has TwinCAT 3.1.4024.29. I have deactivated the firewall on the Beckhoff and I have not set any special rules on the Linux.
I started a Testserver on the Linux PC according to the documentation and was able to connect to it without any problems.
I can't see anything wrong with that setup, you could try using an older version of pyads, we have recently changed how we are doing the build on Linux, so that may have untoward issues.
I have installed pyads on the Linux via pip. Since the installation and import works, I left it like this for a start. I should install it from source as recommended in the documentation.
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:
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.
Originally posted by @CreaM129129 in https://github.com/stlehmann/pyads/issues/281#issuecomment-956370290