<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Setting gateway and device ip by script not possible when executed from cli</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/69876287f1/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/69876287f1/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/69876287f1/</id><updated>2022-04-07T09:23:36.984000Z</updated><subtitle>Recent posts to Setting gateway and device ip by script not possible when executed from cli</subtitle><entry><title>Setting gateway and device ip by script not possible when executed from cli</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/69876287f1/?limit=25#2c8f" rel="alternate"/><published>2022-04-07T09:23:36.984000Z</published><updated>2022-04-07T09:23:36.984000Z</updated><author><name>jm322</name><uri>https://forge.codesys.com/u/jm322/</uri></author><id>https://forge.codesys.comaa8005ea4907f9d5f5f81c15a925f0b390ccd9ab</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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. &lt;br/&gt;
To get the gateway and set the address I tried both of the following code snippets:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;gateway = list(online.gateways)[0]&lt;/span&gt;
&lt;span class="err"&gt;top_device.set_gateway_and_ip_address(gateway, PLC_IP, int(PLC_PORT))&lt;/span&gt;
&lt;span class="err"&gt;print("Set Gateway: {} | PLC: {}:{}".format(gateway.name, PLC_IP, PLC_PORT))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;gateway = top_device.get_gateway()&lt;/span&gt;
&lt;span class="err"&gt;top_device.set_gateway_and_ip_address(gateway, PLC_IP, int(PLC_PORT))&lt;/span&gt;
&lt;span class="err"&gt;print("Set Gateway: {} | PLC: {}:{}".format(gateway.name, PLC_IP, PLC_PORT))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Both ways produce the expected behavior and allow me to connect to the PLC.&lt;br/&gt;
However when I execute the same scripts from CODESYS' CLI with no UI I get:&lt;br/&gt;
&lt;em&gt; "Index out of range error" for the first snippet because "online.gateways" is empty&lt;br/&gt;
&lt;/em&gt; "ValueError: Gateway f8f15fb8-30c5-4671-9931-5a37ded55386 not found" for the second snippet&lt;/p&gt;
&lt;p&gt;Why is that gateway only available when executing the script from the CODESYS UI?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>