Controller IP address change in runtime with script

Discussion of configuring and troubleshooting communication to PLC's or other devices using iX Developer.
Post Reply
ric
Posts: 17
Joined: Wed Nov 16, 2011 4:35 am

Controller IP address change in runtime with script

Post by ric »

Hi,

I noticed that changing the Controller IP address could be done with the Change Active Controllers Action.

Is there a script module that perform this kind of feature automatically?

lenius
Posts: 1
Joined: Mon Dec 14, 2015 11:03 am

Re: Controller IP address change in runtime with script

Post by lenius »

using System.IO;
using System.Linq;
using System.Xml.Linq;


try
{
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

ControllerRunTimeSettingsFile = System.IO.Path.Combine(baseDirectory, "ControllerRunTimeSettings.xml");


if (!File.Exists(ControllerRunTimeSettingsFile)) return;

XDocument doc = XDocument.Load(ControllerRunTimeSettingsFile);
var xElemAgent = doc.Descendants("Controller").Single(arg => arg.Attribute("Name").Value == controller);
xElemAgent.SetAttributeValue("IsActive", active);
doc.Save(ControllerRunTimeSettingsFile);

//reload your application

}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}

Post Reply