Ejemplo n.º 1
0
 private static void ExportTagTables(PlcTagTableComposition tagTables)
 {
     foreach (PlcTagTable table in tagTables)
     {
         string filePath = exportLocation + @"\tag_tables\xml\" + table.Name + ".xml";
         var    fileInfo = new FileInfo(filePath);
         Console.WriteLine(table.Name + " to " + fileInfo.FullName);
         if (File.Exists(fileInfo.FullName))
         {
             File.Delete(fileInfo.FullName);
         }
         table.Export(fileInfo, ExportOptions.WithDefaults);
     }
 }
Ejemplo n.º 2
0
 private static void ExportTagTables(PlcTagTableComposition tagTables)
 {
     try
     {
         foreach (PlcTagTable table in tagTables)
         {
             table.Export(new FileInfo(string.Format(@"C:\testTables\" + table.Name + ".xml", table.Name)), ExportOptions.WithDefaults);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Chyba: " + ex.Message);
     }
 }
Ejemplo n.º 3
0
        //Imports tag tables to the tag system group
        private static void ImportTagTable(PlcSoftware plcSoftware)
        {
            try
            {
                PlcTagTableSystemGroup plcTagTableSystemGroup = plcSoftware.TagTableGroup;
                PlcTagTableComposition tagTables = plcTagTableSystemGroup.TagTables;
                string[] files = Directory.GetFiles(@"C:\testTables\", "*", SearchOption.AllDirectories);

                foreach (var file in files)
                {
                    tagTables.Import(new FileInfo(file), ImportOptions.Override);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Chyba: " + ex.Message);
            }
        }
        /// <summary>
        /// Creates new Robot
        /// </summary>
        /// <param name="startAddress"></param>
        /// <param name="name"></param>
        /// <param name="robSafe"></param>
        /// <param name="tecnologies"></param>
        /// <param name="type"></param>
        /// <param name="importToTia"></param>
        public void NewRobot(int startAddress, string name, string robSafe, List <string> tecnologies, string type, bool importToTia)
        {
            this.name = name;

            ChangeAddresses(startAddress);

            if (isChangeSymbolic)
            {
                robInfo.StartAddress = startAddress;
            }

            if (robSafe.Equals("Range Monitoring"))
            {
                foreach (var item in robSafeRangeMonitoring[0]) //Outputs
                {
                    robBase[0].Add(item);
                }
                foreach (var item in robSafeRangeMonitoring[1]) //Inputs
                {
                    robBase[1].Add(item);
                }
            }
            else
            {
                foreach (var item in robSafeOperations[0]) //Outputs
                {
                    robBase[0].Add(item);
                }
                foreach (var item in robSafeOperations[1]) //Inputs
                {
                    robBase[1].Add(item);
                }
            }

            int outputIndexRob = -1;
            int inputIndexRob  = -1;

            foreach (string tec in tecnologies)
            {
                foreach (var item in robTecnologies[0].Where(t => t.Name.Equals(tec)).ToList())
                {
                    outputIndexRob = robBase[0].FindIndex(a => a.Address.Equals(item.Address));

                    if (outputIndexRob != -1)
                    {
                        robBase[0][outputIndexRob] = new RobotBase(item.Symbolic, item.DataType, item.Address, item.Comment);
                    }
                }

                foreach (var item in robTecnologies[1].Where(t => t.Name.Equals(tec)).ToList()) //Inputs
                {
                    inputIndexRob = robBase[1].FindIndex(a => a.Address.Equals(item.Address));

                    if (inputIndexRob != -1)
                    {
                        robBase[1][inputIndexRob] = new RobotBase(item.Symbolic, item.DataType, item.Address, item.Comment);
                    }
                }
            }

            AddPlcDbTags(name);

            if (!Directory.Exists(Path.Combine(SavePath, "To Import Manually")))
            {
                Directory.CreateDirectory(Path.Combine(SavePath, "To Import Manually"));
            }
            string      path = Path.Combine(SavePath, "To Import Manually", name + ".xml");
            XmlDocument doc  = GenerateTagsXmlDoc();

            XmlParser.IDRenumbering(doc.SelectNodes("/Document/SW.Tags.PlcTagTable//*"));
            doc.Save(path); // Creates file temporarily just to import to Tia Portal automatically

            if (Current != null & importToTia)
            {
                PlcTagTableComposition tagTables = (Current as PlcTagTableSystemGroup).TagTables;

                var tag = tagTables.Find(name);

                if (tag == null)
                {
                    tagTables.Create(name);
                }
                else
                {
                    try
                    {
                        tag.Delete();
                        tagTables.Create(name);
                    }
                    catch (Exception)
                    {
                        //Continue
                    }
                }

                try
                {
                    tagTables.Import(new FileInfo(path), ImportOptions.Override);
                }
                catch (Exception)
                {
                    MessageBox.Show("There was an error importing tags.\nPlease, import manually\n\nPath: " + path, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            // When process finish, deletes the file and creates a new one
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            doc = GenerateManualImportXML();
            doc.Save(path);

            SavePath = Path.Combine(SavePath, name + ".xml");
            GenerateSaveFile(name, startAddress.ToString(), robSafe, type, tecnologies);
        }