private void cmdConnectionDelete_Click(object sender, EventArgs e)
        {
            if (lstConnectionList.SelectedItem != null)
            {
                cmdSave.Visible = false;
                cmdUndo.Visible = false;

                System.Windows.Forms.DialogResult res = MessageBox.Show("Are you sure that you want to delete the Connection : " + lstConnectionList.SelectedItem.ToString(), "Delete realy?", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    LockControls();

                    if (InternalConnectionList != null)
                    {
                        PLCConnectionConfiguration akConfig = null;
                        foreach (var plcConnectionConfiguration in InternalConnectionList)
                        {
                            if (plcConnectionConfiguration.ConnectionName == lstConnectionList.SelectedItem.ToString())
                            {
                                akConfig = plcConnectionConfiguration;
                            }
                        }
                        if (akConfig != null)
                        {
                            InternalConnectionList.Remove(akConfig);
                        }
                        lstConnectionList.Items.Clear();
                        foreach (var plcConnectionConfiguration in InternalConnectionList)
                        {
                            lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName);
                        }
                        if (lstConnectionList.Items.Count > 0)
                        {
                            lstConnectionList.SelectedItem = lstConnectionList.Items[0];
                            lstLIBNODAVEConnectionType_SelectedIndexChanged(sender, e);
                        }
                        else
                        {
                            lstLIBNODAVEConnectionType.Enabled = false;
                        }
                    }
                    else
                    {
                        PLCConnectionConfiguration.DeleteConfiguration(lstConnectionList.SelectedItem.ToString());
                        lstConnectionList.Items.Clear();
                        lstConnectionList.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames());
                        if (lstConnectionList.Items.Count > 0)
                        {
                            lstConnectionList.SelectedItem = lstConnectionList.Items[0];
                            lstLIBNODAVEConnectionType_SelectedIndexChanged(sender, e);
                        }
                        else
                        {
                            lstLIBNODAVEConnectionType.Enabled = false;
                        }
                    }
                }
            }
        }
        private void ConnectionEditor_Load(object sender, EventArgs e)
        {
            LockControls();

            foreach (string myType in Enum.GetNames(typeof(LibNodaveConnectionTypes)))
            {
                lstLIBNODAVEConnectionType.Items.Add(new EnumListItem(myType, (int)Enum.Parse(typeof(LibNodaveConnectionTypes), myType)));
            }

            foreach (string myType in Enum.GetNames(typeof(LibNodaveConnectionBusSpeed)))
            {
                lstLIBNODAVEBusSpeed.Items.Add(new EnumListItem(myType, (int)Enum.Parse(typeof(LibNodaveConnectionBusSpeed), myType)));
            }

            lstLIBNODAVELokalCOMPort.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());

            FillEntryPointsList();

            if (InternalConnectionList != null)
            {
                foreach (var plcConnectionConfiguration in InternalConnectionList)
                {
                    lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName);
                }
            }
            else
            {
                string[] Connections = PLCConnectionConfiguration.GetConfigurationNames();
                if (Connections != null)
                {
                    lstConnectionList.Items.AddRange(Connections);
                }
            }

            lblConnectionName.Text = DefaultConnectionName;
            lstConnectionList.Text = DefaultConnectionName;

            if (!ConnectionNameFixed && lstConnectionList.Items.Count <= 0)
            {
                lstLIBNODAVEConnectionType.Enabled = false;
            }
            else if (lstConnectionList.Items.Count > 0)
            {
                lstConnectionList.SelectedIndex = 0;
            }

            if (ConnectionNameFixed)
            {
                lstConnectionList.Visible   = false;
                cmdConnectionAdd.Visible    = false;
                cmdConnectionDelete.Visible = false;
                lblConnectionName.Visible   = true;

                LoadSettings();
            }
        }
        public static PLCConnectionConfiguration ShowConfiguration(PLCConnectionConfiguration myConfig)
        {
            if (myConfig == null)
                myConfig = new PLCConnectionConfiguration("PLC-Connection", LibNodaveConnectionConfigurationType.ObjectSavedConfiguration);

            var myConnectionEditor = new ConnectionEditor { ConnectionNameFixed = true, DefaultConnectionName = myConfig.ConnectionName, ObjectSavedConfiguration = true };
            myConnectionEditor.myConfig = myConfig;
            myConnectionEditor.ShowDialog();
            return myConfig;
        }
        public static PLCConnectionConfiguration ShowConfiguration(PLCConnectionConfiguration myConfig)
        {
            if (myConfig == null)
            {
                myConfig = new PLCConnectionConfiguration("PLC-Connection", LibNodaveConnectionConfigurationType.ObjectSavedConfiguration);
            }

            var myConnectionEditor = new ConnectionEditor {
                ConnectionNameFixed = true, DefaultConnectionName = myConfig.ConnectionName, ObjectSavedConfiguration = true
            };

            myConnectionEditor.myConfig = myConfig;
            myConnectionEditor.ShowDialog();
            return(myConfig);
        }
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            var cfg = new PLCConnectionConfiguration("myConnection", LibNodaveConnectionConfigurationType.ObjectSavedConfiguration);
            cfg.ConnectionType = (int) LibNodaveConnectionTypes.ISO_over_TCP;
            cfg.CpuIP = "192.168.1.185";
            cfg.CpuSlot = 2;

            myConn = new PLCConnection(cfg);
            myConn.Connect();
            
            threadShouldRun = true;

            myThread = new Thread(new ThreadStart(this.ThreadProc));
            myThread.Start();                                
        }
        private void cmdConnectionAdd_Click(object sender, EventArgs e)
        {
            string       cfgName = "";
            DialogResult ret     = InputBox.Show("Enter Name...", "Enter the Name of the new Connection:", ref cfgName);

            if (ret == DialogResult.OK)
            {
                if (cfgName != "")
                {
                    if (InternalConnectionList != null)
                    {
                        var akConfig = new PLCConnectionConfiguration();
                        akConfig.ConnectionName    = cfgName;
                        akConfig.ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration;
                        InternalConnectionList.Add(akConfig);

                        lstConnectionList.Items.Clear();
                        foreach (var plcConnectionConfiguration in InternalConnectionList)
                        {
                            lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName);
                        }
                        lstConnectionList.SelectedItem     = cfgName;
                        lstLIBNODAVEConnectionType.Enabled = true;
                    }
                    else
                    {
                        PLCConnectionConfiguration tmp = new PLCConnectionConfiguration(cfgName);
                        tmp.SaveConfiguration();

                        lstConnectionList.Items.Clear();
                        lstConnectionList.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames());
                        lstConnectionList.SelectedItem     = cfgName;
                        lstLIBNODAVEConnectionType.Enabled = true;
                    }
                }
            }
        }
 private void cmdAddConnection_Click(object sender, RoutedEventArgs e)
 {
     string val = "Connection_" + (grdConnections.Items.Count + 1);
     if (DotNetSiemensPLCToolBoxLibrary.General.InputBox.Show("Connectionname", "Name of the PLC Connection", ref val) == DialogResult.OK)
     {
         foreach (ConnectionConfig plcConnectionConfiguration in ProtokollerConfiguration.ActualConfigInstance.Connections)
         {
             if (plcConnectionConfiguration.Name.ToLower().Trim() == val.ToLower().Trim())
             {
                 MessageBox.Show("A Connection with this Name already Exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
         }
         PLCConnectionConfiguration myIntConfig = new PLCConnectionConfiguration(val.Trim(), LibNodaveConnectionConfigurationType.ObjectSavedConfiguration);
         myIntConfig = DotNetSiemensPLCToolBoxLibrary.Communication.Configuration.ShowConfiguration(myIntConfig);
         if (myIntConfig != null)
         {
             LibNoDaveConfig myConfig = new LibNoDaveConfig();
             myConfig.Configuration = myIntConfig;
             ProtokollerConfiguration.ActualConfigInstance.Connections.Add(myConfig);
         }
         //grdConnections.Items.Add(myConfig);
     }
 }
        private void updateConfig()
        {
            String name;

            if (lblConnectionName.Visible)
            {
                name = lblConnectionName.Text;
            }
            else
            {
                name = lstConnectionList.Text;
            }

            //var myConfig = new LibNoDaveConnectionConfiguration(name);
            if (myConfig == null)
            {
                myConfig = new PLCConnectionConfiguration(name);
            }

            if (lstListEntryPoints.SelectedItem != null)
            {
                myConfig.EntryPoint = lstListEntryPoints.SelectedItem.ToString();
            }
            myConfig.CpuRack   = Convert.ToInt32(txtLIBNODAVECPURack.Text);
            myConfig.CpuSlot   = Convert.ToInt32(txtLIBNODAVECPUSlot.Text);
            myConfig.CpuMpi    = Convert.ToInt32(txtLIBNODAVECPUMPI.Text);
            myConfig.CpuIP     = txtLIBNODAVECPUIP.Text;
            myConfig.Port      = Convert.ToInt32(txtLIBNODAVECPUPort.Text);
            myConfig.WritePort = Convert.ToInt32(txtWritePort.Text);
            myConfig.LokalMpi  = Convert.ToInt32(txtLIBNODAVELokalMPI.Text);
            myConfig.ComPort   = lstLIBNODAVELokalCOMPort.SelectedItem != null?lstLIBNODAVELokalCOMPort.SelectedItem.ToString() : "";

            if (lstLIBNODAVELokalComSpeed.SelectedItem != null)
            {
                myConfig.ComPortSpeed = lstLIBNODAVELokalComSpeed.SelectedItem.ToString();
            }

            if (lstLIBNODAVELokalComParity.SelectedItem.ToString() == "even")
            {
                myConfig.ComPortParity = LibNodaveConnectionBusParity.even;
            }
            else if (lstLIBNODAVELokalComParity.SelectedItem.ToString() == "odd")
            {
                myConfig.ComPortParity = LibNodaveConnectionBusParity.odd;
            }
            else
            {
                myConfig.ComPortParity = LibNodaveConnectionBusParity.none;
            }

            myConfig.ConnectionType = (LibNodaveConnectionTypes)(lstLIBNODAVEConnectionType.SelectedItem != null ? ((EnumListItem)lstLIBNODAVEConnectionType.SelectedItem).Value : 0);

            myConfig.BusSpeed = (LibNodaveConnectionBusSpeed)(lstLIBNODAVEBusSpeed.SelectedItem != null ? ((EnumListItem)lstLIBNODAVEBusSpeed.SelectedItem).Value : 0);

            myConfig.NetLinkReset = chkNetlinkReset.Checked;

            myConfig.UseShortDataBlockRequest = chkUseShortRequest.Checked;

            myConfig.RoutingDestination     = txtRoutingDestination.Text;
            myConfig.RoutingDestinationRack = Convert.ToInt32(txtRoutingRack.Text);
            myConfig.RoutingDestinationSlot = Convert.ToInt32(txtRoutingSlot.Text);
            myConfig.Routing        = chkRouting.Checked;
            myConfig.RoutingSubnet1 = Convert.ToInt32(txtRoutingSubnetFirst.Text, 16);
            myConfig.RoutingSubnet2 = Convert.ToInt32(txtRoutingSubnetSecond.Text, 16);

            myConfig.Timeout          = TimeSpan.FromMilliseconds(Convert.ToInt32(txtTimeout.Text));
            myConfig.TimeoutIPConnect = TimeSpan.FromMilliseconds(Convert.ToInt32(txtTimeoutIPConnect.Text));

            myConfig.PLCConnectionType        = (LibNodaveConnectionResource)lstConnType.SelectedIndex;
            myConfig.RoutingPLCConnectionType = (LibNodaveConnectionResource)lstConnTypeRouting.SelectedIndex;
        }
        private void LoadSettings()
        {
            String name;

            if (lblConnectionName.Visible)
            {
                name = lblConnectionName.Text;
            }
            else
            {
                name = lstConnectionList.Text;
            }

            if (InternalConnectionList != null)
            {
                PLCConnectionConfiguration akConfig = null;
                foreach (var plcConnectionConfiguration in InternalConnectionList)
                {
                    if (plcConnectionConfiguration.ConnectionName == name)
                    {
                        akConfig = plcConnectionConfiguration;
                        break;
                    }
                }
                if (akConfig == null)
                {
                    akConfig = new PLCConnectionConfiguration();
                }
                akConfig.ConnectionName    = name;
                akConfig.ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration;
                myConfig = akConfig;
            }
            else if (!ObjectSavedConfiguration)
            {
                myConfig = new PLCConnectionConfiguration(name);
            }

            lstListEntryPoints.SelectedItem = myConfig.EntryPoint;

            txtLIBNODAVECPURack.Text              = myConfig.CpuRack.ToString();
            txtLIBNODAVECPUSlot.Text              = myConfig.CpuSlot.ToString();
            txtLIBNODAVECPUMPI.Text               = myConfig.CpuMpi.ToString();
            txtLIBNODAVECPUIP.Text                = myConfig.CpuIP;
            txtLIBNODAVECPUPort.Text              = myConfig.Port.ToString();
            txtWritePort.Text                     = myConfig.WritePort.ToString();
            txtLIBNODAVELokalMPI.Text             = myConfig.LokalMpi.ToString();
            lstLIBNODAVELokalCOMPort.SelectedItem = myConfig.ComPort;
            if (myConfig.ComPortParity == LibNodaveConnectionBusParity.even)
            {
                lstLIBNODAVELokalComParity.SelectedItem = "even";
            }
            else if (myConfig.ComPortParity == LibNodaveConnectionBusParity.odd)
            {
                lstLIBNODAVELokalComParity.SelectedItem = "odd";
            }
            else
            {
                lstLIBNODAVELokalComParity.SelectedItem = "none";
            }
            lstLIBNODAVELokalComSpeed.SelectedItem = myConfig.ComPortSpeed;

            EnumListBoxExtensions.SelectEnumListItem(lstLIBNODAVEConnectionType, (int)myConfig.ConnectionType);
            EnumListBoxExtensions.SelectEnumListItem(lstLIBNODAVEBusSpeed, (int)myConfig.BusSpeed);

            txtRoutingDestination.Text  = myConfig.RoutingDestination;
            txtRoutingRack.Text         = myConfig.RoutingDestinationRack.ToString();
            txtRoutingSlot.Text         = myConfig.RoutingDestinationSlot.ToString();
            chkRouting.Checked          = myConfig.Routing;
            txtRoutingSubnetFirst.Text  = myConfig.RoutingSubnet1.ToString("X");
            txtRoutingSubnetSecond.Text = myConfig.RoutingSubnet2.ToString("X");

            txtTimeout.Text          = myConfig.Timeout.TotalMilliseconds.ToString();
            txtTimeoutIPConnect.Text = myConfig.TimeoutIPConnect.TotalMilliseconds.ToString();

            chkNetlinkReset.Checked = myConfig.NetLinkReset;

            chkUseShortRequest.Checked = myConfig.UseShortDataBlockRequest;

            lstConnType.SelectedIndex        = (int)myConfig.PLCConnectionType;
            lstConnTypeRouting.SelectedIndex = (int)myConfig.RoutingPLCConnectionType;

            cmdUndo.Visible = false;
            cmdSave.Visible = false;
        }
        public void ReloadConfiguration()
        {
            if (ConfigurationType == LibNodaveConnectionConfigurationType.RegistrySavedConfiguration)
            {
#if !IPHONE
                if (File.Exists(ConfigurationPathAndFilename))
                {
                    DictionarySerializer <String, PLCConnectionConfiguration> ConnectionsDicSer = new DictionarySerializer <string, PLCConnectionConfiguration>();

                    Dictionary <String, PLCConnectionConfiguration> Connections = null;
                    StreamReader strm = new StreamReader(ConfigurationPathAndFilename);
                    Connections = ConnectionsDicSer.Deserialize(strm);
                    //string txt = strm.ReadToEnd();
                    strm.Close();
                    //Connections = General.SerializeToString<Dictionary<String, PLCConnectionConfiguration>>.DeSerialize(txt);
                    if (Connections != null && Connections.ContainsKey(ConnectionName))
                    {
                        PLCConnectionConfiguration akConf = Connections[ConnectionName];
                        this.EntryPoint             = akConf.EntryPoint;
                        this.CpuRack                = akConf.CpuRack;
                        this.CpuSlot                = akConf.CpuSlot;
                        this.CpuMpi                 = akConf.CpuMpi;
                        this.CpuIP                  = akConf.CpuIP;
                        this.LokalMpi               = akConf.LokalMpi;
                        this.ComPort                = akConf.ComPort;
                        this.ConnectionType         = akConf.ConnectionType;
                        this.BusSpeed               = akConf.BusSpeed;
                        this.NetLinkReset           = akConf.NetLinkReset;
                        this.ComPortSpeed           = akConf.ComPortSpeed;
                        this.ComPortParity          = akConf.ComPortParity;
                        this.Routing                = akConf.Routing;
                        this.RoutingDestinationRack = akConf.RoutingDestinationRack;
                        this.RoutingDestinationSlot = akConf.RoutingDestinationSlot;
                        this.RoutingSubnet1         = akConf.RoutingSubnet1;
                        this.RoutingSubnet2         = akConf.RoutingSubnet2;
                        this.RoutingDestination     = akConf.RoutingDestination;
                        this.Port      = akConf.Port;
                        this.WritePort = akConf.WritePort;
                        this.UseShortDataBlockRequest = akConf.UseShortDataBlockRequest;

                        this.PLCConnectionType        = akConf.PLCConnectionType;
                        this.RoutingPLCConnectionType = akConf.RoutingPLCConnectionType;

                        this.Timeout          = akConf.Timeout;
                        this.TimeoutIPConnect = akConf.TimeoutIPConnect;
                    }
                }
                return;


                RegistryKey myConnectionKey =
                    Registry.CurrentUser.CreateSubKey(
                        "Software\\JFKSolutions\\WPFToolboxForSiemensPLCs\\Connections\\" + ConnectionName);
                if (myConnectionKey != null)
                {
                    this.EntryPoint             = (String)myConnectionKey.GetValue("EntryPoint", "S7ONLINE");
                    this.CpuRack                = Convert.ToInt32(myConnectionKey.GetValue("CpuRack", "0"));
                    this.CpuSlot                = Convert.ToInt32(myConnectionKey.GetValue("CpuSlot", "2"));
                    this.CpuMpi                 = Convert.ToInt32(myConnectionKey.GetValue("CpuMpi", "2"));
                    this.CpuIP                  = (String)myConnectionKey.GetValue("CpuIP", "192.168.1.1");
                    this.LokalMpi               = Convert.ToInt32(myConnectionKey.GetValue("LokalMpi", "0"));
                    this.ComPort                = (String)myConnectionKey.GetValue("ComPort", "");
                    this.ConnectionType         = Convert.ToInt32(myConnectionKey.GetValue("ConnectionType", "1"));
                    this.BusSpeed               = Convert.ToInt32(myConnectionKey.GetValue("BusSpeed", "2"));
                    this.NetLinkReset           = Convert.ToBoolean(myConnectionKey.GetValue("NetLinkReset", "false"));
                    this.ComPortSpeed           = (String)myConnectionKey.GetValue("ComPortSpeed", "38400");
                    this.ComPortParity          = Convert.ToInt32(myConnectionKey.GetValue("ComPortParity", "1"));
                    this.Routing                = Convert.ToBoolean(myConnectionKey.GetValue("Routing", "false"));
                    this.RoutingDestinationRack =
                        Convert.ToInt32(myConnectionKey.GetValue("RoutingDestinationRack", "0"));
                    this.RoutingDestinationSlot =
                        Convert.ToInt32(myConnectionKey.GetValue("RoutingDestinationSlot", "2"));
                    this.RoutingSubnet1     = Convert.ToInt32(myConnectionKey.GetValue("RoutingSubnet1", "0"));
                    this.RoutingSubnet2     = Convert.ToInt32(myConnectionKey.GetValue("RoutingSubnet2", "0"));
                    this.RoutingDestination = Convert.ToString(myConnectionKey.GetValue("RoutingDestination", "2"));
                    this.Port      = Convert.ToInt32(myConnectionKey.GetValue("Port", "102"));
                    this.WritePort = Convert.ToInt32(myConnectionKey.GetValue("WritePort", "30501"));

                    this.PLCConnectionType        = Convert.ToInt32(myConnectionKey.GetValue("PLCConnectionType", "1"));
                    this.RoutingPLCConnectionType = Convert.ToInt32(myConnectionKey.GetValue("RoutingPLCConnectionType", "1"));

                    this.Timeout          = Convert.ToInt32(myConnectionKey.GetValue("Timeout", "5000000"));
                    this.TimeoutIPConnect = Convert.ToInt32(myConnectionKey.GetValue("TimeoutIPConnect", "5000"));
                }
#endif
            }
            else
            {
                if (!_initDone)
                {
                    this.ConnectionType   = 122;
                    this.CpuMpi           = 2;
                    this.EntryPoint       = "S7ONLINE";
                    this.CpuIP            = "192.168.1.1";
                    this.CpuRack          = 0;
                    this.CpuSlot          = 2;
                    this.Port             = 102;
                    this.TimeoutIPConnect = 5000;
                    this.Timeout          = 5000000;
                    _initDone             = true;
                }
            }
        }
 private void button5_Click(object sender, EventArgs e)
 {
     var cfg = new PLCConnectionConfiguration() {ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration, ConnectionName = "MyPrivateConnection"};
     Configuration.ShowConfiguration(cfg);
     myConn = new PLCConnection(cfg);
 }
 private void cmdAddPLCStorage_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show("Be carefull, writing to the PLC as a Storrage is BETA and not much tested yet!");
     string val = "Storage_" + (grdStorages.Items.Count + 1);
     if (DotNetSiemensPLCToolBoxLibrary.General.InputBox.Show("Storage-Name", "Name of the Storage", ref val) == DialogResult.OK)
     {
         foreach (var tmp in ProtokollerConfiguration.ActualConfigInstance.Storages)
         {
             if (tmp.Name.ToLower().Trim() == val.ToLower().Trim())
             {
                 MessageBox.Show("A Storage with this Name already Exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
         }
         PLCConnectionConfiguration myIntConfig = new PLCConnectionConfiguration(val.Trim(), LibNodaveConnectionConfigurationType.ObjectSavedConfiguration);
         myIntConfig = DotNetSiemensPLCToolBoxLibrary.Communication.Configuration.ShowConfiguration(myIntConfig);
         if (myIntConfig != null)
         {
             var storage = new PLCConfig() {Name = val};
             storage.Configuration = myIntConfig;
             ProtokollerConfiguration.ActualConfigInstance.Storages.Add(storage);
         }
     }
 }
        private void cmdConnectionAdd_Click(object sender, EventArgs e)
        {
            string cfgName = "";
            DialogResult ret = InputBox.Show("Enter Name...", "Enter the Name of the new Connection:", ref cfgName);

            if (ret == DialogResult.OK)
            {
                if (cfgName != "")
                {
                    if (InternalConnectionList != null)
                    {
                        var akConfig = new PLCConnectionConfiguration();
                        akConfig.ConnectionName = cfgName;
                        akConfig.ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration;
                        InternalConnectionList.Add(akConfig);

                        lstConnectionList.Items.Clear();
                        foreach (var plcConnectionConfiguration in InternalConnectionList)
                        {
                            lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName);
                        }
                        lstConnectionList.SelectedItem = cfgName;
                        lstLIBNODAVEConnectionType.Enabled = true;
                    }
                    else
                    {
                        PLCConnectionConfiguration tmp = new PLCConnectionConfiguration(cfgName);
                        tmp.SaveConfiguration();

                        lstConnectionList.Items.Clear();
                        lstConnectionList.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames());
                        lstConnectionList.SelectedItem = cfgName;
                        lstLIBNODAVEConnectionType.Enabled = true;
                    }

                }
            }
        }
        private void updateConfig()
        {
            String name;
            if (lblConnectionName.Visible)
                name = lblConnectionName.Text;
            else
                name = lstConnectionList.Text;

            //var myConfig = new LibNoDaveConnectionConfiguration(name);
            if (myConfig == null)
                myConfig = new PLCConnectionConfiguration(name);

            if (lstListEntryPoints.SelectedItem != null)
                myConfig.EntryPoint = lstListEntryPoints.SelectedItem.ToString();
            myConfig.CpuRack = Convert.ToInt32(txtLIBNODAVECPURack.Text);
            myConfig.CpuSlot = Convert.ToInt32(txtLIBNODAVECPUSlot.Text);
            myConfig.CpuMpi = Convert.ToInt32(txtLIBNODAVECPUMPI.Text);
            myConfig.CpuIP = txtLIBNODAVECPUIP.Text;
            myConfig.Port = Convert.ToInt32(txtLIBNODAVECPUPort.Text);
            myConfig.WritePort = Convert.ToInt32(txtWritePort.Text);
            myConfig.LokalMpi = Convert.ToInt32(txtLIBNODAVELokalMPI.Text);
            myConfig.ComPort = lstLIBNODAVELokalCOMPort.SelectedItem != null ? lstLIBNODAVELokalCOMPort.SelectedItem.ToString() : "";

            if (lstLIBNODAVELokalComSpeed.SelectedItem != null)
                myConfig.ComPortSpeed = lstLIBNODAVELokalComSpeed.SelectedItem.ToString();

            if (lstLIBNODAVELokalComParity.SelectedItem.ToString() == "even")
                myConfig.ComPortParity = 'e';
            else if (lstLIBNODAVELokalComParity.SelectedItem.ToString() == "odd")
                myConfig.ComPortParity = 'o';
            else
                myConfig.ComPortParity = 'n';

            myConfig.ConnectionType = lstLIBNODAVEConnectionType.SelectedItem != null ? ((EnumListItem)lstLIBNODAVEConnectionType.SelectedItem).Value : 0;

            myConfig.BusSpeed = lstLIBNODAVEBusSpeed.SelectedItem != null ? ((EnumListItem)lstLIBNODAVEBusSpeed.SelectedItem).Value : 0;

            myConfig.NetLinkReset = chkNetlinkReset.Checked;

            myConfig.UseShortDataBlockRequest = chkUseShortRequest.Checked;

            myConfig.RoutingDestination = txtRoutingDestination.Text;
            myConfig.RoutingDestinationRack = Convert.ToInt32(txtRoutingRack.Text);
            myConfig.RoutingDestinationSlot = Convert.ToInt32(txtRoutingSlot.Text);
            myConfig.Routing = chkRouting.Checked;
            myConfig.RoutingSubnet1 = Convert.ToInt32(txtRoutingSubnetFirst.Text, 16);
            myConfig.RoutingSubnet2 = Convert.ToInt32(txtRoutingSubnetSecond.Text, 16);

            myConfig.Timeout = Convert.ToInt32(txtTimeout.Text);
            myConfig.TimeoutIPConnect = Convert.ToInt32(txtTimeoutIPConnect.Text);

            myConfig.PLCConnectionType = lstConnType.SelectedIndex;
            myConfig.RoutingPLCConnectionType = lstConnTypeRouting.SelectedIndex;
        }
        private void LoadSettings()
        {
            String name;
            if (lblConnectionName.Visible)
                name = lblConnectionName.Text;
            else
                name = lstConnectionList.Text;

            if (InternalConnectionList!=null)
            {
                PLCConnectionConfiguration akConfig = null;
                foreach (var plcConnectionConfiguration in InternalConnectionList)
                {
                    if (plcConnectionConfiguration.ConnectionName==name)
                    {
                        akConfig = plcConnectionConfiguration;
                        break;
                    }
                }
                if (akConfig == null)
                    akConfig = new PLCConnectionConfiguration();
                akConfig.ConnectionName = name;
                akConfig.ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration;
                myConfig = akConfig;
            }
            else if (!ObjectSavedConfiguration)
            {
                myConfig = new PLCConnectionConfiguration(name);
            }

            lstListEntryPoints.SelectedItem = myConfig.EntryPoint;

            txtLIBNODAVECPURack.Text = myConfig.CpuRack.ToString();
            txtLIBNODAVECPUSlot.Text = myConfig.CpuSlot.ToString();
            txtLIBNODAVECPUMPI.Text = myConfig.CpuMpi.ToString();
            txtLIBNODAVECPUIP.Text = myConfig.CpuIP;
            txtLIBNODAVECPUPort.Text = myConfig.Port.ToString();
            txtWritePort.Text = myConfig.WritePort.ToString();
            txtLIBNODAVELokalMPI.Text = myConfig.LokalMpi.ToString();
            lstLIBNODAVELokalCOMPort.SelectedItem = myConfig.ComPort;
            if (myConfig.ComPortParity == 'e')
                lstLIBNODAVELokalComParity.SelectedItem = "even";
            else if (myConfig.ComPortParity == 'o')
                lstLIBNODAVELokalComParity.SelectedItem = "odd";
            else
                lstLIBNODAVELokalComParity.SelectedItem = "none";
            lstLIBNODAVELokalComSpeed.SelectedItem = myConfig.ComPortSpeed;

            EnumListBoxExtensions.SelectEnumListItem(lstLIBNODAVEConnectionType, myConfig.ConnectionType);
            EnumListBoxExtensions.SelectEnumListItem(lstLIBNODAVEBusSpeed, myConfig.BusSpeed);

            txtRoutingDestination.Text = myConfig.RoutingDestination;
            txtRoutingRack.Text = myConfig.RoutingDestinationRack.ToString();
            txtRoutingSlot.Text = myConfig.RoutingDestinationSlot.ToString();
            chkRouting.Checked = myConfig.Routing;
            txtRoutingSubnetFirst.Text = myConfig.RoutingSubnet1.ToString("X");
            txtRoutingSubnetSecond.Text = myConfig.RoutingSubnet2.ToString("X");

            txtTimeout.Text = myConfig.Timeout.ToString();
            txtTimeoutIPConnect.Text = myConfig.TimeoutIPConnect.ToString();

            chkNetlinkReset.Checked = myConfig.NetLinkReset;

            chkUseShortRequest.Checked = myConfig.UseShortDataBlockRequest;

            lstConnType.SelectedIndex = myConfig.PLCConnectionType;
            lstConnTypeRouting.SelectedIndex = myConfig.RoutingPLCConnectionType;

            cmdUndo.Visible = false;
            cmdSave.Visible = false;
        }
Exemplo n.º 16
0
        private void updateConfig()
        {
            String name;

            if (lblConnectionName.Visible)
            {
                name = lblConnectionName.Text;
            }
            else
            {
                name = lstConnectionList.Text;
            }

            //var myConfig = new LibNoDaveConnectionConfiguration(name);
            if (myConfig == null)
            {
                myConfig = new PLCConnectionConfiguration(name);
            }

            if (lstListEntryPoints.SelectedItem != null)
            {
                myConfig.EntryPoint = lstListEntryPoints.SelectedItem.ToString();
            }
            myConfig.CpuRack  = Convert.ToInt32(txtLIBNODAVECPURack.Text);
            myConfig.CpuSlot  = Convert.ToInt32(txtLIBNODAVECPUSlot.Text);
            myConfig.CpuMpi   = Convert.ToInt32(txtLIBNODAVECPUMPI.Text);
            myConfig.CpuIP    = txtLIBNODAVECPUIP.Text;
            myConfig.Port     = Convert.ToInt32(txtLIBNODAVECPUPort.Text);
            myConfig.LokalMpi = Convert.ToInt32(txtLIBNODAVELokalMPI.Text);
            myConfig.ComPort  = lstLIBNODAVELokalCOMPort.SelectedItem != null?lstLIBNODAVELokalCOMPort.SelectedItem.ToString() : "";

            if (lstLIBNODAVELokalComSpeed.SelectedItem != null)
            {
                myConfig.ComPortSpeed = lstLIBNODAVELokalComSpeed.SelectedItem.ToString();
            }

            if (lstLIBNODAVELokalComParity.SelectedItem.ToString() == "even")
            {
                myConfig.ComPortParity = 'e';
            }
            else if (lstLIBNODAVELokalComParity.SelectedItem.ToString() == "odd")
            {
                myConfig.ComPortParity = 'o';
            }
            else
            {
                myConfig.ComPortParity = 'n';
            }

            myConfig.ConnectionType = lstLIBNODAVEConnectionType.SelectedItem != null ? ((EnumListItem)lstLIBNODAVEConnectionType.SelectedItem).Value : 0;

            myConfig.BusSpeed = lstLIBNODAVEBusSpeed.SelectedItem != null ? ((EnumListItem)lstLIBNODAVEBusSpeed.SelectedItem).Value : 0;

            myConfig.NetLinkReset = chkNetlinkReset.Checked;

            myConfig.RoutingDestination     = txtRoutingDestination.Text;
            myConfig.RoutingDestinationRack = Convert.ToInt32(txtRoutingRack.Text);
            myConfig.RoutingDestinationSlot = Convert.ToInt32(txtRoutingSlot.Text);
            myConfig.Routing        = chkRouting.Checked;
            myConfig.RoutingSubnet1 = Convert.ToInt32(txtRoutingSubnetFirst.Text, 16);
            myConfig.RoutingSubnet2 = Convert.ToInt32(txtRoutingSubnetSecond.Text, 16);

            myConfig.Timeout          = Convert.ToInt32(txtTimeout.Text);
            myConfig.TimeoutIPConnect = Convert.ToInt32(txtTimeoutIPConnect.Text);
        }