예제 #1
0
        // Menu Item
        private void addInstanceAttributToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = devicesTreeView.SelectedNode;

            // look the node or upper
            for (; ;)
            {
                if (tn == null)
                {
                    return;
                }
                if (tn.Tag is EnIPInstance)
                {
                    break;
                }
                tn = tn.Parent;
            }

            int Numbase = 1;

            foreach (TreeNode t in tn.Nodes)
            {
                int num = (t.Tag as EnIPAttribut).Id;
                Numbase = Math.Max(num + 1, Numbase);
            }

            var Input =
                new GenericInputBoxExtended <NumericUpDown>("Add Attribute", "Attribute Id :",
                                                            (o) =>
            {
                o.Minimum     = 1; o.Maximum = 65535; o.Value = Numbase;
                o.Hexadecimal = Properties.Settings.Default.IdHexDisplay;
            },
                                                            (o) =>
            {
                ushort Id        = (ushort)o.Value;
                EnIPInstance ist = (EnIPInstance)tn.Tag;
                EnIPAttribut att = new EnIPAttribut(ist, Id);
                TreeNode tnI     = new TreeNode("Attribute #" + IdStr(Id), 10, 10);
                tnI.Tag          = att;
                tnI.ToolTipText  = "Node " + IdStr((tn.Parent.Tag as EnIPClass).Id) + "." + IdStr(ist.Id) + "." + IdStr(Id);
                tn.Nodes.Add(tnI);
                tn.Expand();
                if (o.Value != o.Maximum)
                {
                    o.Value++;
                }
            });

            DialogResult res = Input.ShowDialog();
        }
예제 #2
0
        // Menu Item
        private void openInterfaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (client == null)
            {
                var Input =
                    new GenericInputBoxExtended <ComboBox>("Local Interface", "IP address",
                                                           (o) =>
                {
                    string[] local_endpoints = GetAvailableIps();
                    o.Items.AddRange(local_endpoints);
                    o.Text = Properties.Settings.Default.DefaultIPInterface;
                });

                DialogResult res = Input.ShowDialog();

                if (res != DialogResult.OK)
                {
                    return;
                }
                String userinput = Input.genericInput.Text;
                Properties.Settings.Default.DefaultIPInterface = userinput;

                try
                {
                    client = new EnIPClient(userinput, Properties.Settings.Default.TCP_LAN_Timeout);
                    client.DeviceArrival += new DeviceArrivalHandler(On_DeviceArrival);

                    client.DiscoverServers();

                    openInterfaceToolStripMenuItem.Enabled = false;
                }
                catch
                {
                    MessageBox.Show("Local address unavailable", "Error in Open Interface", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                devicesTreeView.SelectedNode = null;
                devicesTreeView.CollapseAll();
            }
        }
예제 #3
0
        // Menu Item
        private void renameCurrentNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = devicesTreeView.SelectedNode;

            if ((devicesTreeView.SelectedNode == null) || (!(tn.Tag is EnIPCIPObject)))
            {
                return;
            }

            var Input =
                new GenericInputBoxExtended <TextBox>("Rename", "New name",
                                                      (o) =>
            {
                o.Text = tn.Text;
                o.SelectAll();
            });
            DialogResult res = Input.ShowDialog();

            if (res == DialogResult.OK)
            {
                tn.Text = Input.genericInput.Text;
            }
        }
예제 #4
0
        // Menu Item
        // Add a new device not discovery using the broadcast technic : outside the local net
        private void addRemoteDeviceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (client == null)
            {
                return;
            }

            var Input =
                new GenericInputBoxExtended <TextBox>("Remote device", "IP address",
                                                      (o) =>
            {
                o.Text = Properties.Settings.Default.DefaultRemoteDevice;
            });

            DialogResult res = Input.ShowDialog();

            if (res != DialogResult.OK)
            {
                return;
            }

            try
            {
                EnIPRemoteDevice remotedevice = new EnIPRemoteDevice(new System.Net.IPEndPoint(IPAddress.Parse(Input.genericInput.Text), 0xAF12), Properties.Settings.Default.TCP_WAN_TimeOut);
                remotedevice.ProductName = "EnIPExplorer temporary ProductName";
                AddRemoteDevice(remotedevice);

                remotedevice.DeviceArrival += new DeviceArrivalHandler(On_DeviceArrival);
                remotedevice.DiscoverServer();

                Properties.Settings.Default.DefaultRemoteDevice = Input.genericInput.Text;
            }
            catch
            {
                Trace.WriteLine("Error with IP : " + Input.genericInput.Text);
            }
        }
예제 #5
0
        // Menu Item
        private void addClassInstanceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = devicesTreeView.SelectedNode;

            // look the node or upper
            for (; ;)
            {
                if (tn == null)
                {
                    return;
                }
                if (tn.Tag is EnIPClass)
                {
                    break;
                }
                tn = tn.Parent;
            }

            int Numbase = 1;

            foreach (TreeNode t in tn.Nodes)
            {
                int num = (t.Tag as EnIPInstance).Id;
                Numbase = Math.Max(num + 1, Numbase);
            }

            var Input =
                new GenericInputBoxExtended <NumericUpDown>("Add Instance", "Instance Id :",
                                                            (o) =>
            {
                o.Minimum     = 1; o.Maximum = 65535; o.Value = Numbase;
                o.Hexadecimal = Properties.Settings.Default.IdHexDisplay;
            },
                                                            (o) =>
            {
                ushort Id             = (ushort)o.Value;
                EnIPClass cl          = (EnIPClass)tn.Tag;
                EnIPInstance instance = new EnIPInstance(cl, Id);
                TreeNode tnI          = new TreeNode("Instance #" + IdStr(Id), 9, 9);
                tnI.Tag         = instance;
                tnI.ToolTipText = "Node " + IdStr(cl.Id) + "." + IdStr(Id);

                // speed me ... automatic add Attribut 3 (Data - Array of Bytes) to all Assembly instances
                if (cl.Id == (ushort)CIPObjectLibrary.Assembly)
                {
                    EnIPAttribut att = new EnIPAttribut(instance, 3);
                    TreeNode tnI2    = new TreeNode("Attribute #" + IdStr(3), 10, 10);
                    tnI2.Tag         = att;
                    tnI2.ToolTipText = "Node " + IdStr(cl.Id) + "." + IdStr(instance.Id) + ".3";
                    tnI.Nodes.Add(tnI2);
                }

                tn.Nodes.Add(tnI);
                tn.Expand();
                tnI.Expand();

                if (o.Value != o.Maximum)
                {
                    o.Value++;
                }
            });

            DialogResult res = Input.ShowDialog();
        }
예제 #6
0
        // Menu Item
        private void addClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = devicesTreeView.SelectedNode;

            // look the node or upper
            for (; ;)
            {
                if (tn == null)
                {
                    return;
                }
                if (tn.Tag is EnIPRemoteDevice)
                {
                    break;
                }
                tn = tn.Parent;
            }

            int Numbase = 1;

            foreach (TreeNode t in tn.Nodes)
            {
                int num = (t.Tag as EnIPClass).Id;
                Numbase = Math.Max(num + 1, Numbase);
            }

            var Input =
                new GenericInputBoxExtended <NumericUpDown>("Add Class", "Class Id :",
                                                            (o) =>
            {
                o.Minimum       = 1; o.Maximum = 65535; o.Value = Numbase;
                o.Hexadecimal   = Properties.Settings.Default.IdHexDisplay;
                ToolTip tt      = new ToolTip();
                tt.AutoPopDelay = 32767;
                // Helper two columns tooltip with the object Id list
                StringBuilder sb = new StringBuilder();
                int i            = 0;
                foreach (CIPObjectLibrary en in Enum.GetValues(typeof(CIPObjectLibrary)))
                {
                    String s = IdStr((int)en) + " : " + en.ToString();
                    if (i == 0)
                    {
                        // 1, 2,3 or 4 tab
                        sb.Append(s + "\t");
                        if (s.Length < 10)
                        {
                            sb.Append('\t');
                        }
                        if (s.Length < 17)
                        {
                            sb.Append('\t');
                        }
                        if (s.Length < 29)
                        {
                            sb.Append('\t');
                        }
                    }
                    else
                    {
                        sb.Append(s + Environment.NewLine);
                    }
                    i = ~i;
                }

                tt.SetToolTip(o, sb.ToString());
            },
                                                            (o) =>
            {
                ushort Id       = (ushort)o.Value;
                EnIPClass Class = new EnIPClass(tn.Tag as EnIPRemoteDevice, Id);
                tn.Nodes.Add(ClassToTreeNode(Class));
                tn.Expand();
                if (o.Value != o.Maximum)
                {
                    o.Value++;
                }
            });

            DialogResult res = Input.ShowDialog();
        }