Sviluppare un NetLogic per configurare la rete

Prerequisiti
Impostare l'editor di codici esterni predefinito. Vedere Impostazione dell'editor di codici predefinito.
  1. Nel riquadro della
    vista Progetto
    espandere la
    UI
    cartella.
  2. Fare clic con il pulsante destro del mouse
    MainWindow (type)
    e selezionare
    New
    Runtime NetLogic
    .
  3. Passare con il mouse su NetLogic, selezionare
    Edit
    , quindi immettere
    NetworkConfigurationor
    .
  4. Fare doppio clic su NetLogic.
    Viene visualizzato l'editor di codici esterni.
  5. Nell'editor di codici incollare il codice seguente:
    #region Using directives using UAManagedCore; using FTOptix.Core; using OpcUa = UAManagedCore.OpcUa; using FTOptix.HMIProject; using FTOptix.NetLogic; using FTOptix.System; #endregion public class NetworkConfigurator : BaseNetLogic { public override void Start() { // Insert code to be executed when the user-defined logic is started var model = Project.Current.Get("Model"); systemNode = model.Get<FTOptix.System.System>("System1"); if (systemNode == null) throw new CoreConfigurationException("SystemNode not found"); } public override void Stop() { // Insert code to be executed when the user-defined logic is stopped } [ExportMethod] public void Refresh() { systemNode.Refresh(); } [ExportMethod] public void EnableDHCP(string interfaceName, bool enabled) { foreach (var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == interfaceName) networkInterface.DhcpEnabled = enabled; } } [ExportMethod] public void AddIpAddressToNetworkInterface(string interfaceName, string ipAddress, string mask) { foreach(var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == interfaceName) { networkInterface.DhcpEnabled = false; networkInterface.IPAddress = ipAddress; networkInterface.IPAddressVariable.Mask = mask; } } } [ExportMethod] public void UpdateDNSAddressesToNetworkInterface(string interfaceName, string dns1, string dns2) { foreach (var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == interfaceName) { networkInterface.DhcpEnabled = false; networkInterface.DNS1 = dns1; networkInterface.DNS2 = dns2; } } } [ExportMethod] public void UpdateDefaultGatewayToNetworkInterface(string interfaceName, string defaultGateway) { foreach (var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == interfaceName) { networkInterface.DhcpEnabled = false; networkInterface.DefaultGateway = defaultGateway; } } } [ExportMethod] public void AddAdditionalIp(string interfaceName, string ipAddress, string mask) { foreach (var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == interfaceName) { var additionalIPAddressVariable = InformationModel.MakeVariable<MaskedIPAddress>("MyAdditionalIP", OpcUa::DataTypes.String); additionalIPAddressVariable.SetValue(ipAddress); additionalIPAddressVariable.Mask = mask; networkInterface.AdditionalIPAddresses.Add(additionalIPAddressVariable); } } } private FTOptix.System.System systemNode; }
  6. Salvare il codice.
Sono disponibili le seguenti API:
public PlaceholderChildNodeCollection<NetworkInterface> NetworkInterfaces { get; } public IUAMethod RefreshMethod { get; } public IUAMethod RebootMethod { get; } public void Reboot(); public void Refresh();
NetworkInterfaces
rappresenta l'elenco di tutte le interfacce di rete. La struttura di un'interfaccia di rete è la seguente:
public IUAVariable InterfaceNameVariable { get; } public bool DhcpEnabled { get; set; } public IUAVariable DhcpEnabledVariable { get; } public string IPAddress { get; set; } public MaskedIPAddress IPAddressVariable { get; } public string DNS1 { get; set; } public IUAVariable DNS1Variable { get; } public string DNS2 { get; set; } public IUAVariable DNS2Variable { get; } public string DefaultGateway { get; set; } public IUAVariable DefaultGatewayVariable { get; } public PlaceholderChildNodeCollection<MaskedIPAddress> AdditionalIPAddresses { get; }
Fornire un feedback
Hai domande o feedback su questa documentazione? invia il tuo feedback qui.