Exemple #1
0
        internal void ExportKepwareAsync()
        {
            if (!(CurrentBlock.Value.Name.ToLower().StartsWith("db")))
            {
                return;
            }

            S7DataBlock blk = (S7DataBlock)CurrentBlock.Value.BlockContents;
            ExportTable.KepwareExportTableDataTable exportTable = new ExportTable.KepwareExportTableDataTable();

            AddChildrenToKepwareExportTable(exportTable, blk.Structure.Children, CurrentBlock.Value.SymbolicName, CurrentBlock.Value);
            CreateKepwareCSVFromDataTable(exportTable);

            if (!Properties.Settings.Default.RecentlyUsedBlocks.Contains(CurrentBlock.Key))
            {
                Properties.Settings.Default.RecentlyUsedBlocks.Insert(0, CurrentBlock.Key);
                while (Properties.Settings.Default.RecentlyUsedBlocks.Count > 150)
                {
                    Properties.Settings.Default.RecentlyUsedBlocks.RemoveAt(150);
                }
                Properties.Settings.Default.Save();
            }
        }
Exemple #2
0
        internal void GetAllTagsAsync()
        {
            if (CurrentBlock.Value.Name.Equals("Symbols"))
            {
                AllTags = Symbols;
                return;
            }
            else if (!(CurrentBlock.Value.Name.ToLower().StartsWith("db")))
            {
                return;
            }

            S7DataBlock blk = (S7DataBlock)CurrentBlock.Value.BlockContents;
            ExportTable.KepwareExportTableDataTable exportTable = new ExportTable.KepwareExportTableDataTable();

            AddChildrenToKepwareExportTable(exportTable, blk.Structure.Children, CurrentBlock.Value.SymbolicName, CurrentBlock.Value);
            Dictionary<String, Tag> myTags = new Dictionary<string,Tag>();
            foreach (ExportTable.KepwareExportTableRow Row in exportTable)
            {
                Regex LastNumberInString = new Regex("(\\d+)(?!.*\\d)");
                Tag NewTag = new Tag() { Name = Row.Tag_Name, AreaTypeParameter = Trending.AREA_TYPE.DB};

                String[] SplitAddress = Row.Address.Split('.');
                if (SplitAddress.Length == 2)
                    NewTag.BitOffset = 0;
                else
                    NewTag.BitOffset = int.Parse(LastNumberInString.Match(Row.Address).Value);

                NewTag.ByteOffset = int.Parse(LastNumberInString.Match(Row.Address.Split('.')[1]).Value);
                NewTag.DbNumber = int.Parse(LastNumberInString.Match(Row.Address.Split('.')[0]).Value);

                NewTag.Address = Row.Address;
                myTags.Add(Row.Tag_Name, NewTag);

            }
            AllTags = myTags;
        }
Exemple #3
0
        internal void ExportKepwareAllBlocksAsync()
        {
            //this function is where the actual code is to export 1 block. Need to replace with exporting all global blocks to one CSV.
              ExportTable.KepwareExportTableDataTable exportTable = new ExportTable.KepwareExportTableDataTable(); //this is a table that holds every data block.
              foreach(KeyValuePair<string,Block> db in AllBlocks) //so this is not looking for everything with "db" in it, but it's making a new array of blocks from a
              //all it is doing is indexing a collection. in this case AllBlocks is a collection of KeyValuePairs. So it is not filtering anything by DB or FB or FC or anything. I ti is just indexing AllB
              //indexing AllBlcoks and putting the contents one at a time into the variable "db"
               {
                if (!(db.Value.Name.ToLower().StartsWith("db"))) //check to make sure a data block is selected
                    //Then here, we are checking the block to see if its ia DB or FB or FC. ok  If tit's not a DB, go to the next block. Sorry it's hard to type over remote haha ok and that's why you changed return to the continue. yes.
                {
                    continue; //this will skip the block in the for loop if it is not a datablock
                }

                S7DataBlock blk = (S7DataBlock)db.Value.BlockContents; //grab block contents
                if (blk.IsInstanceDB)
                {
                    continue;
                }
                ExportTable.KepwareExportTableDataTable singleBlockTable = new ExportTable.KepwareExportTableDataTable(); //create new CSV table

                AddChildrenToKepwareExportTable(singleBlockTable, blk.Structure.Children, db.Value.SymbolicName, db.Value); //get addresses for all items in data block

                foreach (ExportTable.KepwareExportTableRow row in singleBlockTable.Rows) //add every row from this data block to our global table
                {
                    exportTable.Rows.Add(row.ItemArray);//.AddKepwareExportTableRow(row);
                }
            }
              AddSymbolsToKepwareExportTable(exportTable);
              CreateKepwareCSVFromDataTable(exportTable); //Export to CSV file  from our global table

            //so it kinda looks like you could loop through all the blocks and add them all to exportTable, and then call the CreateKepwareCSVFromDataTable.
            //I set up the basics so you now have a new button on the application that will link to whatever you put in this function.

            //This code is just to create aa "list" of recently exported blocks for easier use next time. Is not relevent to our task of exporting all blocks:
            //if (!Properties.Settings.Default.RecentlyUsedBlocks.Contains(CurrentBlock.Key))
            //{
            //    Properties.Settings.Default.RecentlyUsedBlocks.Insert(0, CurrentBlock.Key);
            //    while (Properties.Settings.Default.RecentlyUsedBlocks.Count > 150)
            //    {
            //        Properties.Settings.Default.RecentlyUsedBlocks.RemoveAt(150);
            //    }
            //    Properties.Settings.Default.Save();
            //}
        }