private void IterateThroughDevices(Project project)
        {
            // no project is open
            if (project == null)
            {
                return;
            }

            // shop a form to indicate work
            frmReadStructure read = new frmReadStructure();

            read.Show();
            read.BringToFront();

            //Console.WriteLine(String.Format("Iterate through {0} device(s)", project.Devices.Count));
            listBox1.Items.Clear();
            listBox2.Items.Clear();

            Application.DoEvents();

            // search through devices
            foreach (Device device in project.Devices)
            {
                if (device.TypeIdentifier != null)
                {
                    // we search only for PLCs
                    if (device.TypeIdentifier == "System:Device.S71500")
                    {
                        //Console.WriteLine(String.Format("Found {0}", device.Name));
                        listBox1.Items.Add(device.Name);

                        // let's get the CPU
                        foreach (DeviceItem item in device.DeviceItems)
                        {
                            if (item.Classification.ToString() == "CPU")
                            {
                                //Console.WriteLine(String.Format("Found {0}", item.Name));
                                listBox2.Items.Add(item.Name);

                                // get the software container
                                SoftwareContainer softwareContainer = ((IEngineeringServiceProvider)item).GetService <SoftwareContainer>();
                                if (softwareContainer != null)
                                {
                                    software = softwareContainer.Software as PlcSoftware;
                                    groups.LoadTreeView(treeView1, software);
                                }
                            }
                        }
                    }
                }
            }

            // close form
            read.Close();
            read.Dispose();

            this.BringToFront();
            Application.DoEvents();
        }
Esempio n. 2
0
        private void IterateThroughDevices(Project project)
        {
            // no project is open
            if (project == null)
            {
                return;
            }

            // shop a form to indicate work
            frmReadStructure read = new frmReadStructure();

            read.Show();

            Application.DoEvents();

            //Console.WriteLine(String.Format("Iterate through {0} device(s)", project.Devices.Count));
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            treeView1.Nodes.Clear();

            // search through devices
            foreach (Device device in project.Devices)
            {
                if (device.TypeIdentifier != null)
                {
                    // we search only for PLCs
                    if (device.TypeIdentifier == "System:Device.S71500")
                    {
                        //Console.WriteLine(String.Format("Found {0}", device.Name));
                        listBox1.Items.Add(device.Name);

                        // let's get the CPU
                        foreach (DeviceItem item in device.DeviceItems)
                        {
                            if (item.Classification.ToString() == "CPU")
                            {
                                //Console.WriteLine(String.Format("Found {0}", item.Name));
                                listBox2.Items.Add(item.Name);

                                // get the software container
                                SoftwareContainer softwareContainer = ((IEngineeringServiceProvider)item).GetService <SoftwareContainer>();
                                if (softwareContainer != null)
                                {
                                    software = softwareContainer.Software as PlcSoftware;
                                    //Console.WriteLine("Found : " + software.Name);

                                    // start update treeview
                                    treeView1.BeginUpdate();

                                    // add root node
                                    TreeNode root = new TreeNode(software.Name);
                                    root.Tag = software.BlockGroup;
                                    treeView1.Nodes.Add(root);

                                    cFunctionGroups func = new cFunctionGroups();
                                    func.AddPlcBlocks(software.BlockGroup, root);
                                    //AddPlcBlocks(software.BlockGroup, root);

                                    // add data types
                                    TreeNode dataTypes = new TreeNode("Data types");
                                    dataTypes.Tag = software.TypeGroup;
                                    treeView1.Nodes.Add(dataTypes);

                                    func.AddPlcTypes(software.TypeGroup, dataTypes);
                                    //AddPlcTypes(software.TypeGroup, dataTypes);
                                    dataTypes.Expand();

                                    // end update
                                    treeView1.EndUpdate();

                                    root.Expand();
                                }
                            }
                        }
                    }
                }
            }

            // close form
            read.Close();
            read.Dispose();
        }