Exemplo n.º 1
0
        private void btn_copy_Click(object sender, EventArgs e)
        {
            PlcSoftware plc = null;

            if (!find_plc(projectTreeView.Nodes, ref plc))
            {
                MessageBox.Show("More than one PLC is selected");
                return;
            }

            HmiTarget hmi = null;

            if (!find_hmi(projectTreeView.Nodes, ref hmi))
            {
                MessageBox.Show("More than one HMI device is selected");
                return;
            }

            if (hmi == null && plc == null)
            {
                MessageBox.Show("No devices are selected");
                return;
            }
            CopySelection copy = new CopySelection(tiaPortal, plc, hmi);

            copy.ShowDialog();
        }
Exemplo n.º 2
0
        private void find_hmis(TreeNodeCollection nodes, ref List <HmiTarget> hmis)
        {
            foreach (TreeNode n in nodes)
            {
                find_hmis(n.Nodes, ref hmis);
                if (!n.Checked)
                {
                    continue;
                }
                if (!(n.Tag is DeviceItem))
                {
                    continue;
                }
                SoftwareContainer sw_cont = ((DeviceItem)n.Tag).GetService <SoftwareContainer>();

                if (sw_cont != null)
                {
                    HmiTarget hmi_target = sw_cont.Software as HmiTarget;
                    if (hmi_target != null)
                    {
                        hmis.Add(hmi_target);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void HMITagsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tiaPortal != null)
            {
                if (hmi_dialog == null)
                {
                    hmi_dialog = new SelectHMI(tiaPortal);
                }
                if (hmi_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string filename = HMIAlarmTags.buildFile(defs, "sDB_LarmDefs", "HMI_Connection");
                    Console.WriteLine("HMI tags file: " + filename);
                    HmiTarget hmi = hmi_dialog.SelectedHMI;
                    Console.WriteLine("HMI name: " + hmi.Name);

                    if (hmi.Connections.Count != 1)
                    {
                        MessageBox.Show(this, "Can only handle exacltly one HMI connection. This device has " + hmi.Connections.Count);
                        System.IO.File.Delete(filename);
                        return;
                    }
                    Connection c = hmi.Connections.First();
                    c.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                }
            }
        }
Exemplo n.º 4
0
        private bool find_hmi(TreeNodeCollection nodes, ref HmiTarget hmi)
        {
            foreach (TreeNode n in nodes)
            {
                if (!find_hmi(n.Nodes, ref hmi))
                {
                    return(false);
                }
                if (!n.Checked)
                {
                    continue;
                }
                if (!(n.Tag is DeviceItem))
                {
                    continue;
                }
                SoftwareContainer sw_cont = ((DeviceItem)n.Tag).GetService <SoftwareContainer>();

                if (sw_cont != null)
                {
                    HmiTarget hmi_target = sw_cont.Software as HmiTarget;
                    if (hmi_target != null)
                    {
                        if (hmi != null)
                        {
                            return(false);
                        }
                        hmi = hmi_target;
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
0
 public HMItagBuilder(TiaPortal portal, PlcSoftware plc, HmiTarget hmi, ConstantLookup constants)
 {
     this.portal     = portal;
     this.plc        = plc;
     this.hmi        = hmi;
     this.constants  = constants;
     btn_run.Enabled = false;
     FindDB();
 }
Exemplo n.º 6
0
        public static string CompileHmiTarget(HmiTarget hmiTarget)
        {
            string         message    = null;
            ICompilable    compileHMI = hmiTarget.GetService <ICompilable>();
            CompilerResult result     = compileHMI.Compile();

            message = WriteCompilerResults(result);
            return(message);
        }
Exemplo n.º 7
0
        //Exports all tag tables from an HMI device
        private static void ExportAllTagTablesFromHMITarget(HmiTarget hmitarget)
        {
            TagSystemFolder sysFolder = hmitarget.TagFolder;

            //First export the tables in underlying user folder
            foreach (TagUserFolder userFolder in sysFolder.Folders)
            {
                ExportUserFolderDeep(userFolder);
            }
            //then, export all tables in the system folder
            ExportTablesInSystemFolder(sysFolder);
        }
Exemplo n.º 8
0
        private void btn_AddHW_Click(object sender, EventArgs e)
        {
            btn_AddHW.Enabled = false;
            string MLFB = "OrderNumber:" + txt_OrderNo.Text + "/" + txt_Version.Text;

            string name    = txt_AddDevice.Text;
            string devname = "station" + txt_AddDevice.Text;
            bool   found   = false;

            foreach (Device device in MyProject.Devices)
            {
                DeviceItemComposition deviceItemAggregation = device.DeviceItems;
                foreach (DeviceItem deviceItem in deviceItemAggregation)
                {
                    if (deviceItem.Name == devname || device.Name == devname)
                    {
                        SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>();
                        if (softwareContainer != null)
                        {
                            if (softwareContainer.Software is PlcSoftware)
                            {
                                PlcSoftware controllerTarget = softwareContainer.Software as PlcSoftware;
                                if (controllerTarget != null)
                                {
                                    found = true;
                                }
                            }
                            if (softwareContainer.Software is HmiTarget)
                            {
                                HmiTarget hmitarget = softwareContainer.Software as HmiTarget;
                                if (hmitarget != null)
                                {
                                    found = true;
                                }
                            }
                        }
                    }
                }
            }
            if (found == true)
            {
                txt_Status.Text = "Device " + txt_Device.Text + " already exists";
            }
            else
            {
                Device deviceName = MyProject.Devices.CreateWithItem(MLFB, name, devname);

                txt_Status.Text = "Add Device Name: " + name + " with Order Number: " + txt_OrderNo.Text + " and Firmware Version: " + txt_Version.Text;
            }

            btn_AddHW.Enabled = true;
        }
Exemplo n.º 9
0
        /// <summary>Returns IEnumerable Collection of all TagTables in hmiTarget</summary>
        /// <param name="hmiTarget">The hmi target.</param>
        /// <returns>IEnumerable&lt;TagTable&gt;</returns>
        /// <exception cref="System.ArgumentNullException">Parameter is null;hmiTarget</exception>
        public static IEnumerable <TagTable> GetAllTagTables(HmiTarget hmiTarget)
        {
            if (hmiTarget == null)
            {
                throw new ArgumentNullException(nameof(hmiTarget), "Parameter is null");
            }

            var collection = new Collection <object>();

            RecursiveGetAllElements(hmiTarget.TagFolder, ref collection);

            return(collection.Cast <TagTable>());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a reference to the HmiTagTable with given name if found, otherwise null.
        /// </summary>
        /// <param name="hmiTarget">The hmi target.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">Parameter is null;hmiTarget</exception>
        /// <exception cref="System.ArgumentException">Parameter is null or empty;name</exception>
        public static TagTable FindTagTableByName(HmiTarget hmiTarget, string name)
        {
            if (hmiTarget == null)
            {
                throw new ArgumentNullException(nameof(hmiTarget), "Parameter is null");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Parameter is null or empty", nameof(name));
            }

            return(RecursiveFindElementByName(hmiTarget.TagFolder, name) as TagTable);
        }
Exemplo n.º 11
0
        /// <summary>Returns TreeViewItem of all ScreenSlideIns in hmiTarget</summary>
        /// <param name="hmiTarget">The hmi target.</param>
        /// <returns>TreeViewItem</returns>
        /// <exception cref="System.ArgumentNullException">Parameter is null;hmiTarget</exception>
        public static TreeViewItem GetScreenSlideInTreeView(HmiTarget hmiTarget)
        {
            if (hmiTarget == null)
            {
                throw new ArgumentNullException(nameof(hmiTarget), "Parameter is null");
            }

            var collection = new TreeViewItem();

            RecursiveGetTreeView(hmiTarget.ScreenSlideinFolder, ref collection);

            return(collection);
        }
Exemplo n.º 12
0
        private void Compile(object sender, EventArgs e)
        {
            btn_CompileHW.Enabled = false;

            string devname = txt_Device.Text;
            bool   found   = false;

            foreach (Device device in MyProject.Devices)
            {
                DeviceItemComposition deviceItemAggregation = device.DeviceItems;
                foreach (DeviceItem deviceItem in deviceItemAggregation)
                {
                    if (deviceItem.Name == devname || device.Name == devname)
                    {
                        SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>();
                        if (softwareContainer != null)
                        {
                            if (softwareContainer.Software is PlcSoftware)
                            {
                                PlcSoftware controllerTarget = softwareContainer.Software as PlcSoftware;
                                if (controllerTarget != null)
                                {
                                    found = true;
                                    ICompilable compiler = controllerTarget.GetService <ICompilable>();

                                    CompilerResult result = compiler.Compile();
                                    txt_Status.Text = "Compiling of " + controllerTarget.Name + ": State: " + result.State + " / Warning Count: " + result.WarningCount + " / Error Count: " + result.ErrorCount;
                                }
                            }
                            if (softwareContainer.Software is HmiTarget)
                            {
                                HmiTarget hmitarget = softwareContainer.Software as HmiTarget;
                                if (hmitarget != null)
                                {
                                    found = true;
                                    ICompilable    compiler = hmitarget.GetService <ICompilable>();
                                    CompilerResult result   = compiler.Compile();
                                    txt_Status.Text = "Compiling of " + hmitarget.Name + ": State: " + result.State + " / Warning Count: " + result.WarningCount + " / Error Count: " + result.ErrorCount;
                                }
                            }
                        }
                    }
                }
            }
            if (found == false)
            {
                txt_Status.Text = "Found no device with name " + txt_Device.Text;
            }

            btn_CompileHW.Enabled = true;
        }
Exemplo n.º 13
0
        private static void InsertHmiPages(HmiTarget hmiTarget)
        {
            Console.WriteLine("Insert screens from file...");

            string   screenFile = @"\\Mac\Home\Documents\GitHub\ibKastl.ApiShowcase\data\Siemens\Screen.xml";
            FileInfo fileInfo   = new FileInfo(screenFile);

            // Export first time
            if (!fileInfo.Exists)
            {
                hmiTarget.ScreenFolder.Screens.Last().Export(fileInfo, ExportOptions.WithDefaults);
            }

            hmiTarget.ScreenFolder.Screens.Import(fileInfo, ImportOptions.Override);
        }
Exemplo n.º 14
0
 private void buildDeviceItemTree(TreeNodeCollection nodes, IDeviceItemAggregation items)
 {
     foreach (IDeviceItem item in items)
     {
         HmiTarget hmi = item as HmiTarget;
         if (hmi != null)
         {
             TreeNode itemNode = new HmiTargetNode(item.Name, hmi);
             nodes.Add(itemNode);
         }
         else
         {
             buildDeviceItemTree(nodes, item.DeviceItems);
         }
     }
 }
Exemplo n.º 15
0
        public static HmiTarget GetHmiTarget(Device device) //gets HMI target of device
        {
            var allDeviceItems = device.DeviceItems;

            foreach (DeviceItem deviceItem in allDeviceItems)
            {
                SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>();

                if (softwareContainer != null)
                {
                    Software  software  = softwareContainer.Software;
                    HmiTarget hmiTarget = software as HmiTarget;
                    return(hmiTarget);
                }
            }
            return(null);
        }
Exemplo n.º 16
0
        private void btn_hmi_tags_Click(object sender, EventArgs e)
        {
            PlcSoftware plc = null;

            if (!find_plc(projectTreeView.Nodes, ref plc))
            {
                MessageBox.Show("More than one PLC is selected");
                return;
            }

            if (plc == null)
            {
                MessageBox.Show("No PLC is selected");
                return;
            }

            HmiTarget hmi = null;

            if (!find_hmi(projectTreeView.Nodes, ref hmi))
            {
                MessageBox.Show("More than one HMI device is selected");
                return;
            }

            if (hmi == null)
            {
                MessageBox.Show("No HMI device is selected");
                return;
            }
            ConstantLookup constants = new ConstantLookup();

            try
            {
                constants.Populate(tiaPortal, plc);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to build lookup table for user constants: " + ex.Message);
                return;
            }

            HMItagBuilder hmi_tags = new HMItagBuilder(tiaPortal, plc, hmi, constants);

            hmi_tags.ShowDialog();
        }
Exemplo n.º 17
0
        public CopySelection(TiaPortal portal, PlcSoftware plc, HmiTarget hmi)
        {
            this.portal = portal;
            this.plc    = plc;
            this.hmi    = hmi;
            InitializeComponent();
            btn_copy.Enabled         = false;
            fromTreeView.AfterCheck += node_AfterCheck;
            toTreeView.AfterCheck   += node_AfterCheck;
            worker = new BackgroundWorker();
            worker.WorkerSupportsCancellation = true;
            worker.WorkerReportsProgress      = true;
            worker.RunWorkerCompleted        += Worker_RunWorkerCompleted;
            worker.DoWork          += Worker_DoWork;
            worker.ProgressChanged += Worker_ProgressChanged;

            worker.RunWorkerAsync();
        }
Exemplo n.º 18
0
        private static void GetDeviceObjects(DeviceItem deviceItem)
        {
            // Get software
            SoftwareContainer softwareContainer =
                ((IEngineeringServiceProvider)deviceItem).GetService <SoftwareContainer>();

            if (softwareContainer != null)
            {
                switch (softwareContainer.Software)
                {
                case HmiTarget hmiTarget:
                    Console.WriteLine("Get HmiTarget...");
                    _hmiTarget = hmiTarget;
                    break;

                case PlcSoftware plcSoftware:
                    Console.WriteLine("Get PlcSoftware...");
                    _plcSoftware = plcSoftware;
                    break;
                }
            }

            // Get network interface
            var networkInterface = deviceItem.GetService <NetworkInterface>();

            if (networkInterface != null)
            {
                foreach (var node in networkInterface.Nodes)
                {
                    Nodes.Add(node);
                }
            }

            foreach (var subDeviceItem in deviceItem.DeviceItems)
            {
                GetDeviceObjects(subDeviceItem);
            }
        }
Exemplo n.º 19
0
        //Export TextLists
        private static void ExportTextLists(HmiTarget hmitarget)
        {
            TextListComposition text = hmitarget.TextLists;

            foreach (TextList textList in text)
            {
                string extension = ".xml";
                var    fileInfo  = new FileInfo(exportLocation + @"\hmi_text_lists\xml\" + textList.Name + extension);
                try
                {
                    if (File.Exists(fileInfo.FullName))
                    {
                        File.Delete(fileInfo.FullName);
                    }
                    Console.WriteLine(textList.Name + " to " + fileInfo.FullName);
                    textList.Export(fileInfo, ExportOptions.WithDefaults);
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.ToString());
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Returns a TreeViewItem of all hardware objects in the HmiTarget
        /// </summary>
        /// <param name="hmiTarget">HmiTarget to be searched</param>
        /// <returns>TreeViewItem of hardware objects</returns>
        /// <exception cref="System.ArgumentNullException">Parameter is null;hmiTarget</exception>
        public static TreeViewItem GetHardwareTreeView(HmiTarget hmiTarget)
        {
            if (hmiTarget == null)
            {
                throw new ArgumentNullException(nameof(hmiTarget), "Parameter is null");
            }

            var station = hmiTarget.Parent as Device;

            if (station == null)
            {
                throw new ArgumentNullException(nameof(station));
            }

            var item = new TreeViewItem();

            item.Header = station.Name;
            item.Tag    = station;
            foreach (var subItem in station.DeviceItems)
            {
                item.Items.Add(RecursiveGetDevicesTreeView(subItem));
            }
            return(item);
        }
Exemplo n.º 21
0
 public HmiTargetNode(string name, HmiTarget hmi)
     : base(name)
 {
     this.hmi = hmi;
 }
Exemplo n.º 22
0
 public HmiTargetNode(string name, HmiTarget hmi)
     : base(name)
 {
     this.hmi = hmi;
 }
Exemplo n.º 23
0
        // Device items
        private static void handleDeviceItem(NodeHandler handler, DeviceItem item)
        {
            NodeHandler child_handler = handler.Enter(item, item.Name);

            if (child_handler != null)
            {
                SoftwareContainer sw_cont = item.GetService <SoftwareContainer>();
                if (sw_cont != null)
                {
                    PlcSoftware controller = sw_cont.Software as PlcSoftware;
                    if (controller != null)
                    {
                        NodeHandler block_handler = child_handler.Enter(controller.BlockGroup, "Blocks");
                        if (block_handler != null)
                        {
                            iterDataBlock(block_handler, controller.BlockGroup.Blocks);
                            iterBlockFolder(block_handler, controller.BlockGroup.Groups);
                        }
                        child_handler.Exit(controller.BlockGroup);
                        NodeHandler type_handler = child_handler.Enter(controller.TypeGroup, "Types");
                        if (type_handler != null)
                        {
                            iterType(type_handler, controller.TypeGroup.Types);
                            iterTypeFolder(block_handler, controller.TypeGroup.Groups);
                        }
                        child_handler.Exit(controller.TypeGroup);
                    }


                    HmiTarget hmi_target = sw_cont.Software as HmiTarget;
                    if (hmi_target != null)
                    {
                        //Console.WriteLine("HMI target");
                        NodeHandler screen_handler = child_handler.Enter(hmi_target.ScreenFolder, "Screens");
                        if (screen_handler != null)
                        {
                            //Console.WriteLine("Iterating screens");
                            iterScreen(screen_handler, hmi_target.ScreenFolder.Screens);
                            iterScreenFolder(screen_handler, hmi_target.ScreenFolder.Folders);
                        }
                        child_handler.Exit(hmi_target.ScreenFolder);

                        NodeHandler template_handler = child_handler.Enter(hmi_target.ScreenTemplateFolder, "Templates");
                        if (template_handler != null)
                        {
                            //Console.WriteLine("Iterating templates");
                            iterScreenTemplate(template_handler, hmi_target.ScreenTemplateFolder.ScreenTemplates);
                            iterScreenTemplateFolder(template_handler, hmi_target.ScreenTemplateFolder.Folders);
                        }
                        child_handler.Exit(hmi_target.ScreenTemplateFolder);


                        NodeHandler popup_handler = child_handler.Enter(hmi_target.ScreenPopupFolder, "Popups");
                        if (popup_handler != null)
                        {
                            //Console.WriteLine("Iterating popups");
                            iterScreenPopup(template_handler, hmi_target.ScreenPopupFolder.ScreenPopups);
                            iterScreenPopupFolder(template_handler, hmi_target.ScreenPopupFolder.Folders);
                        }
                        child_handler.Exit(hmi_target.ScreenPopupFolder);

                        NodeHandler connection_handler = child_handler.Enter(hmi_target.Connections, "Connections");
                        if (connection_handler != null)
                        {
                            foreach (Connection connection in hmi_target.Connections)
                            {
                                connection_handler.Enter(connection, connection.Name);

                                connection_handler.Exit(connection);
                            }
                        }
                        child_handler.Exit(hmi_target.Connections);
                    }
                }

                NetworkInterface netif = item.GetService <NetworkInterface>();
                if (netif != null)
                {
                    NodeHandler netif_handler = child_handler.Enter(netif, "Nodes");
                    if (netif_handler != null)
                    {
                        IterNetNodes(netif_handler, netif.Nodes);
                    }
                    child_handler.Exit(netif);
                }
            }
            handler.Exit(item);
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            if (args == null || args.Length == 0 || args.Length > 1)
            {
                Console.WriteLine("No arguments provided");
                Console.WriteLine(@"Usage TiaExportBlocks.exe C:\Test");
                Console.ReadLine();
            }
            else
            {
                exportLocation = args[0];
                Console.WriteLine("Export location is " + exportLocation);
                CheckDirectory(exportLocation);
                CheckDirectory(exportLocation + @"\scl");
                CheckDirectory(exportLocation + @"\db");
                CheckDirectory(exportLocation + @"\udt");
                CheckDirectory(exportLocation + @"\tag_tables\xml");
                CheckDirectory(exportLocation + @"\hmi_tag_tables\xml");
                CheckDirectory(exportLocation + @"\hmi_text_lists\xml");
                var watch = new System.Diagnostics.Stopwatch();
                watch.Start();
                Console.WriteLine("Enumerating TIA processes..");
                foreach (TiaPortalProcess tiaPortalProcess in TiaPortal.GetProcesses())
                {
                    Console.WriteLine("Process ID " + tiaPortalProcess.Id);
                    Console.WriteLine("Project PATH " + tiaPortalProcess.ProjectPath);
                    TiaPortal tiaPortal = tiaPortalProcess.Attach();
                    foreach (Project project in tiaPortal.Projects)
                    {
                        Console.WriteLine("Handling project " + project.Name);
                        foreach (Siemens.Engineering.HW.Device device in project.Devices)
                        {
                            Console.WriteLine("Handling device " + device.Name + " of type [" + device.TypeIdentifier + "]");

                            if (device.TypeIdentifier == "System:Device.S71500")
                            {
                                foreach (Siemens.Engineering.HW.DeviceItem deviceItem in device.DeviceItems)
                                {
                                    Console.WriteLine("Handling device item " + deviceItem.Name + " of type " + deviceItem.TypeIdentifier);
                                    if (deviceItem.Name.Contains("PLC"))
                                    {
                                        Console.WriteLine("Handling PLC device item");
                                        Siemens.Engineering.HW.Features.SoftwareContainer softwareContainer = ((IEngineeringServiceProvider)deviceItem).GetService <SoftwareContainer>();
                                        if (softwareContainer != null)
                                        {
                                            PlcSoftware software = softwareContainer.Software as PlcSoftware;
                                            ExportBlocks(software);
                                            ExportTypes(software);
                                            ExportAllTagTables(software);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (Siemens.Engineering.HW.DeviceItem deviceItem in device.DeviceItems)
                                {
                                    Console.WriteLine("Handling device item [" + deviceItem.Name + "] of type [" + deviceItem.TypeIdentifier + "]");
                                    if (device.Name.Contains("APS"))
                                    {
                                        Console.WriteLine("Handling HMI device item");
                                        DeviceItem        deviceItemToGetService = deviceItem as DeviceItem;
                                        SoftwareContainer softwareContainer      = deviceItemToGetService.GetService <SoftwareContainer>();
                                        if (softwareContainer != null)
                                        {
                                            HmiTarget software = softwareContainer.Software as HmiTarget;
                                            ExportAllTagTablesFromHMITarget(software);
                                            ExportTextLists(software);
                                        }
                                        else
                                        {
                                            Console.WriteLine("SW Container is null");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                watch.Stop();
                Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");
                Console.WriteLine("Done");
                //Console.ReadLine();
                return;
            }
        }
Exemplo n.º 25
0
 private void itemTree_AfterSelect(object sender, TreeViewEventArgs e)
 {
     TreeNode node = itemTree.SelectedNode;
     if (node is HmiTargetNode)
     {
         selectBtn.Enabled = true;
         SelectedHMI = (node as HmiTargetNode).hmi;
     }
     else
     {
         selectBtn.Enabled = false;
     }
 }