jm322 - 2022-04-07

I have a script that opens a project, gets the project's top level device and tries to set its gateway and the soft-PLC's IP address.
To get the gateway and set the address I tried both of the following code snippets:

gateway = list(online.gateways)[0]
top_device.set_gateway_and_ip_address(gateway, PLC_IP, int(PLC_PORT))
print("Set Gateway: {} | PLC: {}:{}".format(gateway.name, PLC_IP, PLC_PORT))
gateway = top_device.get_gateway()
top_device.set_gateway_and_ip_address(gateway, PLC_IP, int(PLC_PORT))
print("Set Gateway: {} | PLC: {}:{}".format(gateway.name, PLC_IP, PLC_PORT))

Both ways produce the expected behavior and allow me to connect to the PLC.
However when I execute the same scripts from CODESYS' CLI with no UI I get:
1. "Index out of range error" for the first snippet because "online.gateways" is empty
2. "ValueError: Gateway f8f15fb8-30c5-4671-9931-5a37ded55386 not found" for the second snippet

Why is that gateway only available when executing the script from the CODESYS UI?

 

Last edit: jm322 2022-04-07