/// <summary>
 /// Reads an Block from the Project and returns the block data that is stored in the S7 Project
 /// </summary>
 /// <param name="blkInfo">The Block info object that identifies the block to read from Disk</param>
 /// <returns></returns>
 public Block GetBlock(ProjectBlockInfo blkInfo)
 {
     return(GetBlock(blkInfo, new S7ConvertingOptions(Project.ProjectLanguage)
     {
         GenerateCallsfromUCs = false
     }));
 }
        public static S5CommentBlock GetCommentBlock(ProjectBlockInfo blkInfo, byte[] commentBlock)
        {
            S5CommentBlock retVal = new S5CommentBlock();

            if (commentBlock != null)
            {
                int nr    = 28;
                int hdlen = 0x7f & commentBlock[nr];

                retVal.Name = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(commentBlock, nr + 1, hdlen);

                nr += hdlen + 1;
                int last = 0;
                retVal.CommentLines = "";
                while (nr + 3 < commentBlock.Length)
                {
                    int    zeile = commentBlock[nr];
                    int    len   = 0x7f & commentBlock[nr + 2];
                    string cmt   = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(commentBlock, nr + 3, len);

                    retVal.CommentLines += "".PadLeft((zeile - last), '\n').Replace("\n", "\r\n");
                    retVal.CommentLines += cmt;
                    nr += len + 3;
                }
            }
            return(retVal);
        }
示例#3
0
        internal static Block ParseTiaDbUdtXml(string xml, ProjectBlockInfo projectBlockInfo, TIAOpennessControllerFolder controllerFolder, ParseType parseType)
        {
            XElement xelement  = XElement.Parse(xml);
            var      structure = xelement.Elements().FirstOrDefault(x => x.Name.LocalName.StartsWith("SW."));

            var sections = structure.Element("AttributeList").Element("Interface").Elements().First();

            var block = new TIADataBlock();

            block.Name = projectBlockInfo.Name;

            if (projectBlockInfo is TIAOpennessProjectBlockInfo)
            {
                block.BlockNumber = ((TIAOpennessProjectBlockInfo)projectBlockInfo).BlockNumber;
            }

            if (parseType == ParseType.DataType)
            {
                block.BlockType = DataTypes.PLCBlockType.UDT;
            }
            else if (parseType == ParseType.Programm)
            {
                block.BlockType = DataTypes.PLCBlockType.DB;
            }

            var parameterRoot = ParseTiaDbUdtSections(sections, block, controllerFolder);

            block.BlockType = DataTypes.PLCBlockType.DB;
            block.Structure = parameterRoot;

            return(block);
        }
        /// <summary>
        /// With this Function you get the AWL Source of a Block, so that it can be imported into Step7
        /// </summary>
        /// <param name="blkInfo">The BlockInfo from the Block you wish to get the Source of!</param>
        /// <returns></returns>
        public string GetSourceBlock(ProjectBlockInfo blkInfo, bool useSymbols = false)
        {
            StringBuilder retVal = new StringBuilder();
            Block         blk    = GetBlock(blkInfo, new S7ConvertingOptions(Project.ProjectLanguage)
            {
                CombineDBOpenAndDBAccess = true, GenerateCallsfromUCs = true, ReplaceDBAccessesWithSymbolNames = useSymbols, ReplaceLokalDataAddressesWithSymbolNames = true, UseComments = true
            });
            S7Block fblk = (S7Block)blk;

            return(fblk.GetSourceBlock(useSymbols));
        }
示例#5
0
            public Block GetBlock(ProjectBlockInfo blkInfo)
            {
                if (blkInfo == null)
                {
                    return(null);
                }

                var iv   = blkInfo as ITiaProjectBlockInfo;
                var text = iv.ExportToString();

                return(ParseTiaDbUdtXml(text, blkInfo, ControllerFolder, ParseType.Programm));
            }
示例#6
0
            public Block GetBlock(ProjectBlockInfo blkInfo)
            {
                if (blkInfo == null)
                {
                    return(null);
                }

                var iv   = blkInfo as TIAOpennessProjectBlockInfo;
                var text = iv.Export(ExportFormat.Xml);

                return(ParseTiaDbUdtXml(text, blkInfo, ControllerFolder, ParseType.Programm));
            }
        public Block GetBlock(ProjectBlockInfo blkInfo)
        {
            S7ProjectSourceInfo srcInfo = (S7ProjectSourceInfo)blkInfo;

            S7SourceBlock retVal = new S7SourceBlock();

            retVal.Text = GetSource(srcInfo);

            retVal.Name         = srcInfo.Name;
            retVal.ParentFolder = srcInfo.ParentFolder;
            retVal.Filename     = srcInfo.Filename;

            return(retVal);
        }
示例#8
0
        public Block GetBlock(ProjectBlockInfo blkInfo)
        {
            S7ProjectSourceInfo srcInfo = (S7ProjectSourceInfo)blkInfo;

            S7SourceBlock retVal = new S7SourceBlock();

            retVal.Name          = srcInfo.Name;
            retVal.BlockNumber   = blkInfo.id;
            retVal.ParentFolder  = srcInfo.ParentFolder;
            retVal.Filename      = srcInfo.Filename;
            retVal.BlockType     = srcInfo.BlockType;
            retVal.BlockLanguage = PLCLanguage.SRC;


            // Read header
            if (((Step7ProjectV5)Project)._ziphelper.FileExists(Folder + "S7CONTAI.DBF"))
            {
                var       dbfTbl  = DBF.ParseDBF.ReadDBF(Folder + "S7CONTAI.DBF", ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator);
                DataRow[] bstRows = dbfTbl.Select("ID = " + blkInfo.id);

                // Should get only one record
                if (bstRows.Length == 1)
                {
                    DataRow bstRow = bstRows[0];
                    retVal.Author      = (string)bstRow["CREATOR"];
                    retVal.Description = (string)bstRow["COMMENT"];
                    // TODO: Parse CRDATE1/2 fields in the DBF
                    int ver = ((int)bstRow["VERSION"]);
                    retVal.Version = (ver / 15).ToString() + "." + (ver % 15).ToString();
                }
            }


            // Read source file
            if (((Step7ProjectV5)Project)._ziphelper.FileExists(srcInfo.Filename))
            {
                // Get a file timestamp for now
                retVal.LastCodeChange = ((Step7ProjectV5)Project)._ziphelper.FileModDateTime(srcInfo.Filename);
                Stream strm = ((Step7ProjectV5)Project)._ziphelper.GetReadStream(srcInfo.Filename);

                retVal.Text = new System.IO.StreamReader(strm, Encoding.UTF7).ReadToEnd();
                //ReadToEnd();
            }

            // Block size
            retVal.CodeSize = retVal.Text.Length;

            return(retVal);
        }
示例#9
0
        void LoadPrjB(object dta)
        {
            DataObject       tmp    = (DataObject)dta;
            ProjectBlockInfo blkInf = (ProjectBlockInfo)tmp.GetData("ProjectBlockInfo");

            Block  myBlock         = blkInf.GetBlock();
            string highlighterFile = "";

            if (myBlock is S7FunctionBlock)
            {
                highlighterFile = "WPFToolboxForSiemensPLCs.AvalonEdit.AWL_Step7_Highlighting.xshd";

                if (((S7FunctionBlock)myBlock).Parameter != null)
                {
                    myTreeB.DataContext = ((S7FunctionBlock)myBlock).Parameter.Children;
                }

                textEditorB.Text = ((S7FunctionBlock)myBlock).ToString(false);
            }
            else
            {
                mainGridB.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
                //toppanel.Visibility = System.Windows.Visibility.Collapsed;
                highlighterFile  = "WPFToolboxForSiemensPLCs.AvalonEdit.AWL_Step5_Highlighting.xshd";
                textEditorB.Text = myBlock.ToString();
            }

            IHighlightingDefinition customHighlighting;

            using (Stream s = typeof(MainWindow).Assembly.GetManifestResourceStream(highlighterFile))
            {
                if (s == null)
                {
                    throw new InvalidOperationException("Could not find embedded resource");
                }
                using (XmlReader reader = new XmlTextReader(s))
                {
                    customHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.
                                         HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
            }

            HighlightingManager.Instance.RegisterHighlighting("Custom Highlighting", new string[] { ".cool" }, customHighlighting);

            textEditorB.SyntaxHighlighting = customHighlighting;
        }
        private void ListBox_Drop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent("ProjectBlockInfo"))
            {
                return;
            }

            ProjectBlockInfo blkInf = (ProjectBlockInfo)e.Data.GetData("ProjectBlockInfo");

            if (blkInf.BlockType == PLCBlockType.DB)
            {
                ConvertBlocks.Add(blkInf);
            }
            else
            {
                App.clientForm.lblStatus.Text = "Only DB's can be converted to Tags or Errors!";
            }
        }
示例#11
0
        public Block GetBlock(ProjectBlockInfo blkInfo)
        {
            S7ProjectSourceInfo srcInfo = (S7ProjectSourceInfo)blkInfo;

            S7SourceBlock retVal = new S7SourceBlock();

            if (((Step7ProjectV5)Project)._ziphelper.FileExists(srcInfo.Filename))
            {
                Stream strm = ((Step7ProjectV5)Project)._ziphelper.GetReadStream(srcInfo.Filename);

                retVal.Text = new System.IO.StreamReader(strm, Encoding.UTF7).ReadToEnd();
                //ReadToEnd();
            }

            retVal.Name         = srcInfo.Name;
            retVal.ParentFolder = srcInfo.ParentFolder;
            retVal.Filename     = srcInfo.Filename;

            return(retVal);
        }
        private void menuCreateAwl_Click(object sender, RoutedEventArgs e)
        {
            if (sender is DependencyObject)
            {
                DependencyObject depObj      = (DependencyObject)e.OriginalSource;
                ContextMenu      contextMenu = depObj.TryFindParent <ContextMenu>();
                DataGridCell     dataCell    = (DataGridCell)contextMenu.PlacementTarget;
                DataGridRow      dataRow     = dataCell.TryFindParent <DataGridRow>();
                DataGrid         dataGrid    = dataCell.TryFindParent <DataGrid>();
                ProjectBlockInfo prjBlkInfo  = (ProjectBlockInfo)dataGrid.ItemContainerGenerator.ItemFromContainer(dataRow);

                Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                dlg.DefaultExt = ".AWL";
                dlg.Filter     = "AWL-Code (.AWL)|*.AWL";
                if (dlg.ShowDialog() == true)
                {
                    string       filename = dlg.FileName;
                    StreamWriter wrt      = new StreamWriter(filename, false, Encoding.GetEncoding("ISO-8859-1"));

                    wrt.Write(prjBlkInfo.GetSourceBlock());
                    wrt.Close();
                }
            }
        }
示例#13
0
        public Block GetBlock(ProjectBlockInfo blkInfo)
        {
            if (blkInfo == null)
            {
                return(null);
            }

            switch (blkInfo.BlockType)
            {
            case PLCBlockType.DB:
                return(new TIADataBlock(TiaProject, ((TIAProjectBlockInfo)blkInfo).Node)
                {
                    BlockType = blkInfo.BlockType
                });

            case PLCBlockType.FB:
            case PLCBlockType.FC:
                return(new TIAFunctionBlock(TiaProject, ((TIAProjectBlockInfo)blkInfo).Node)
                {
                    BlockType = blkInfo.BlockType
                });
            }
            return(null);
        }
示例#14
0
        private tmpBlock GetBlockBytes(ProjectBlockInfo blkInfo)
        {
            if (subblkDBF != null) //ZipHelper.FileExists(((Step7ProjectV5)Project)._zipfile, Folder + "SUBBLK.DBF"))
            {
                tmpBlock myTmpBlk = new tmpBlock();

                var       bstTbl  = bausteinDBF;
                DataRow[] bstRows = bstTbl.Select("ID = " + blkInfo.id);
                if (bstRows != null && bstRows.Length > 0 && !(bstRows[0]["UDA"] is DBNull))
                {
                    myTmpBlk.uda = (byte[])bstRows[0]["UDA"];
                }

                var dbfTbl = subblkDBF; // DBF.ParseDBF.ReadDBF(Folder + "SUBBLK.DBF", ((Step7ProjectV5)Project)._zipfile, ((Step7ProjectV5) Project)._DirSeperator);

                DataRow[] rows = dbfTbl.Select("OBJECTID = " + blkInfo.id);
                //bausteinDBF



                foreach (DataRow row in rows)// dbfTbl.Rows)
                {
                    int subblktype = Convert.ToInt32(row["SUBBLKTYP"]);
                    int objid      = (int)row["OBJECTID"];

                    if (objid == blkInfo.id)
                    {
                        byte[] mc5code = null;
                        byte[] ssbpart = null;
                        byte[] addinfo = null;

                        if (row["MC5CODE"] != DBNull.Value)
                        {
                            mc5code = (byte[])row["MC5CODE"];
                        }
                        if (row["SSBPART"] != DBNull.Value)
                        {
                            ssbpart = (byte[])row["SSBPART"];
                        }
                        if (row["ADDINFO"] != DBNull.Value)
                        {
                            addinfo = (byte[])row["ADDINFO"];
                        }
                        int mc5codelen = (int)row["MC5LEN"];
                        int ssbpartlen = (int)row["SSBLEN"];
                        int addinfolen = (int)row["ADDLEN"];

                        if (mc5code != null && mc5code.Length > mc5codelen)
                        {
                            Array.Resize <byte>(ref mc5code, mc5codelen);
                        }
                        if (ssbpart != null && ssbpart.Length > ssbpartlen)
                        {
                            Array.Resize <byte>(ref ssbpart, ssbpartlen);
                        }
                        if (addinfo != null && addinfo.Length > addinfolen)
                        {
                            Array.Resize <byte>(ref addinfo, addinfolen);
                        }

                        // Parse block language
                        int.TryParse(row["BLKLANG"].ToString(), out myTmpBlk.Language);

                        if ((subblktype == 19) || subblktype == 12 || subblktype == 8 || subblktype == 14 || subblktype == 13 || subblktype == 15) //FC, OB, FB, SFC, SFB
                        {
                            if (row["PASSWORD"] != DBNull.Value && (int)row["PASSWORD"] == 3)
                            {
                                myTmpBlk.knowHowProtection = true;
                            }
                            //MC7 Code in mc5code
                            myTmpBlk.mc7code  = mc5code;
                            myTmpBlk.username = ((string)row["USERNAME"]).Replace("\0", "").Trim();

                            int ver = ((int)row["VERSION"]);
                            myTmpBlk.version = (ver / 15).ToString() + "." + (ver % 15).ToString();

                            //Network Information in addinfo
                            myTmpBlk.nwinfo = addinfo;
                            //This line contains Network Information, and after it the Position of the JumpMarks

                            //if (xutilsDBF != null)
                            //{
                            //    var XUTILS = xutilsDBF.Select("NOT DELETED_FLAG AND BLOCKTYPE = " + (int)blkInfo.BlockType + " AND BLOCKNB = " + ((S7ProjectBlockInfo)blkInfo).BlockNumber);
                            //   if (XUTILS.Length > 0)
                            //    {
                            //        var ts1 = (string)XUTILS[0]["TIMESTAMP"];
                            //        if (ts1.Length == 5)
                            //        {
                            //            myTmpBlk.LastCodeChange = Helper.GetDTFromListenTable((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            //        }
                            //        else
                            //        {
                            //            myTmpBlk.LastCodeChange = Helper.GetDTFromListenTable((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            //        }
                            //    }
                            //}
                            //else
                            //{
                            var ts1 = (string)row["TIMESTAMP1"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }
                            //   }
                            var ts2 = (string)row["TIMESTAMP2"];
                            if (ts2.Length == 5)
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts2[0], (byte)ts2[1], (byte)ts2[2], (byte)ts2[3], (byte)ts2[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts2[0], (byte)ts2[1], (byte)ts2[2], (byte)ts2[3], (byte)ts2[4], (byte)ts2[5]);
                            }
                        }
                        else if (subblktype == 5 || subblktype == 3 || subblktype == 4 || subblktype == 7 || subblktype == 9) //FC, OB, FB, SFC, SFB
                        {
                            //Interface in mc5code
                            if (mc5code != null)
                            {
                                myTmpBlk.blkinterface =
                                    Project.ProjectEncoding.GetString(mc5code);
                            }
                        }
                        else if (subblktype == 19 || subblktype == 17 || subblktype == 18 || subblktype == 22 ||
                                 subblktype == 21)               //FC, OB, FB, SFC, SFB
                        {
                            myTmpBlk.comments         = mc5code; //Comments of the Block
                            myTmpBlk.blockdescription = ssbpart; //Description of the Block
                            myTmpBlk.jumpmarks        = addinfo;
                            //The Text of the Jump Marks, Before the Jumpmarks there is some Network Information, but don't know what!
                        }

                        else if (subblktype == 6 || subblktype == 1) //DB, UDT
                        {
                            //DB Structure in Plain Text (Structure and StartValues!)
                            if (mc5code != null)
                            {
                                myTmpBlk.blkinterface =
                                    Project.ProjectEncoding.GetString(mc5code);
                            }
                            //Maybe compiled DB Structure?
                            myTmpBlk.addinfo = addinfo;

                            var ts1 = (string)row["TIMESTAMP1"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }

                            ts1 = (string)row["TIMESTAMP2"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }
                        }
                        else if (subblktype == 10) //DB
                        {
                            //Need to check wich Information is stored here
                            myTmpBlk.mc7code           = mc5code;
                            myTmpBlk.blkinterfaceInMC5 = ssbpart;

                            if (ssbpart != null && ssbpartlen > 2 && (ssbpart[0] == 0x0a || ssbpart[0] == 0x0b))
                            {
                                // if ssbpart[0] == 5 this DB is normal
                                // if ssbpart[0] == 10 this DB is instance for FB,
                                // I do not know what value for SFB
                                myTmpBlk.IsInstanceDB = true;
                            }
                            myTmpBlk.FBNumber = (int)ssbpart[1] + 256 * (int)ssbpart[2];
                            var ts1 = (string)row["TIMESTAMP1"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }

                            ts1 = (string)row["TIMESTAMP2"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }
                        }
                        else if (subblktype == 0x14) //DB
                        {
                            //Need to check wich Information is stored here
                            var ts1 = (string)row["TIMESTAMP1"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }

                            ts1 = (string)row["TIMESTAMP2"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }
                        }
                        else if (subblktype == 0x42) //DB
                        {
                            //Need to check wich Information is stored here
                            var ts1 = (string)row["TIMESTAMP1"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }

                            ts1 = (string)row["TIMESTAMP2"];
                            if (ts1.Length == 5)
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)0);
                            }
                            else
                            {
                                myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);
                            }
                        }
                        else if (subblktype == 27) //VAT
                        {
                            var ts1 = (string)row["TIMESTAMP1"];
                            myTmpBlk.LastCodeChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);

                            ts1 = (string)row["TIMESTAMP2"];
                            myTmpBlk.LastInterfaceChange = Helper.GetDT((byte)ts1[0], (byte)ts1[1], (byte)ts1[2], (byte)ts1[3], (byte)ts1[4], (byte)ts1[5]);


                            //VAT in MC5Code (Absolut adressed)
                            myTmpBlk.mc7code = mc5code;
                            //VAT in ADDINFO (Symbolic adressed)
                            myTmpBlk.nwinfo = addinfo;
                        }
                        else if (subblktype == 38) //VAT
                        {
                            //VAT Comments in MC5Code
                            myTmpBlk.comments = mc5code;
                        }
                    }
                }
                return(myTmpBlk);
            }
            return(null);
        }
示例#15
0
        /// <summary>
        /// With this Function you get the AWL Source of a Block, so that it can be imported into Step7
        /// </summary>
        /// <param name="blkInfo">The BlockInfo from the Block you wish to get the Source of!</param>
        /// <returns></returns>
        public string GetSourceBlock(ProjectBlockInfo blkInfo)
        {
            StringBuilder retVal = new StringBuilder();
            Block         blk    = GetBlock(blkInfo, new S7ConvertingOptions(Project.ProjectLanguage)
            {
                CombineDBOpenAndDBAccess = true, GenerateCallsfromUCs = true, ReplaceDBAccessesWithSymbolNames = false, ReplaceLokalDataAddressesWithSymbolNames = true, UseComments = true
            });


            S7Block         fblk  = (S7Block)blk;
            S7FunctionBlock fcblk = null;

            if (blk is S7FunctionBlock)
            {
                fcblk = (S7FunctionBlock)blk;
                if (fcblk.BlockType == PLCBlockType.FC)
                {
                    retVal.Append("FUNCTION " + blk.BlockName + " : VOID" + Environment.NewLine);
                }
                else
                {
                    retVal.Append("FUNCTION_BLOCK " + blk.BlockName + Environment.NewLine);
                }
            }
            else
            {
                retVal.Append("DATA_BLOCK " + blk.BlockName + Environment.NewLine);
            }
            retVal.Append("TITLE =" + fblk.Title + Environment.NewLine);
            if (blk is S7FunctionBlock)
            {
                if (!String.IsNullOrEmpty(fcblk.Description))
                {
                    retVal.Append("//" + fcblk.Description.Replace(Environment.NewLine, Environment.NewLine + "//") + Environment.NewLine);
                }
            }
            if (!string.IsNullOrEmpty(fblk.Author))
            {
                retVal.Append("AUTHOR : " + fblk.Author + Environment.NewLine);
            }
            if (!string.IsNullOrEmpty(fblk.Name))
            {
                retVal.Append("NAME : " + fblk.Name + Environment.NewLine);
            }
            if (!string.IsNullOrEmpty(fblk.Version))
            {
                retVal.Append("VERSION : " + fblk.Version + Environment.NewLine);
            }
            retVal.Append(Environment.NewLine);
            retVal.Append(Environment.NewLine);

            if (blk is S7DataBlock)
            {
                S7DataBlock dtaBlk = (S7DataBlock)fblk;
                if (dtaBlk.Structure.Children != null && !dtaBlk.IsInstanceDB)
                {
                    retVal.Append("  STRUCT" + Environment.NewLine);
                    retVal.Append(GetSubParas(dtaBlk.Structure, "    "));
                    retVal.Append("  END_STRUCT ;" + Environment.NewLine);
                }
                else if (dtaBlk.IsInstanceDB)
                {
                    retVal.Append(" FB " + dtaBlk.FBNumber + Environment.NewLine);
                }
                retVal.Append("BEGIN" + Environment.NewLine);
                retVal.Append("END_DATA_BLOCK" + Environment.NewLine);
            }
            else if (blk is S7FunctionBlock)
            {
                if (fcblk.Parameter.Children != null)
                {
                    foreach (S7DataRow s7DataRow in fcblk.Parameter.Children)
                    {
                        string parnm = s7DataRow.Name;
                        string ber   = "VAR_" + parnm;
                        if (parnm == "IN")
                        {
                            ber = "VAR_INPUT";
                        }
                        else if (parnm == "OUT")
                        {
                            ber = "VAR_OUTPUT";
                        }
                        else if (parnm == "STATIC")
                        {
                            ber = "VAR";
                        }
                        retVal.Append(ber + Environment.NewLine);
                        retVal.Append(GetSubParas(s7DataRow, "  "));
                        retVal.Append("END_VAR" + Environment.NewLine);
                    }
                }
                retVal.Append("BEGIN" + Environment.NewLine);
                foreach (Network network in fcblk.Networks)
                {
                    retVal.Append("NETWORK" + Environment.NewLine);
                    retVal.Append("TITLE = " + network.Name + Environment.NewLine);
                    if (!String.IsNullOrEmpty(network.Comment))
                    {
                        retVal.Append("//" + network.Comment.Replace(Environment.NewLine, Environment.NewLine + "//") + Environment.NewLine);
                    }
                    else
                    {
                        retVal.Append(Environment.NewLine);
                    }
                    foreach (S7FunctionBlockRow functionBlockRow in network.AWLCode)
                    {
                        if (functionBlockRow.ToString(false, false) == "")
                        {
                            retVal.Append(Environment.NewLine);
                        }
                        else
                        {
                            retVal.Append(functionBlockRow.ToString(false, true) + Environment.NewLine);
                        }
                    }
                }
                retVal.Append("END_FUNCTION");
            }

            return(retVal.ToString());
        }
        /// <summary>
        /// Reads an Block from the Project and returns the block data that is stored in the S7 Project
        /// </summary>
        /// <param name="blkInfo">The Block info object that identifies the block to read from Disk</param>
        /// <param name="myConvOpt">Defines options that determine how the Block will be converted</param>
        /// <returns></returns>
        public Block GetBlock(ProjectBlockInfo blkInfo, S7ConvertingOptions myConvOpt)
        {
            if (blkInfo._Block != null && ((blkInfo._Block) as S7Block).usedS7ConvertingOptions.Equals(myConvOpt))
            {
                return(blkInfo._Block);
            }


            ProjectPlcBlockInfo plcblkifo = (ProjectPlcBlockInfo)blkInfo;
            tmpBlock            myTmpBlk  = GetBlockBytes(blkInfo);

            List <Step7Attribute> step7Attributes = null;

            if (myTmpBlk != null)
            {
                if (myTmpBlk.uda != null)
                {
                    int uPos = 2;
                    if (myTmpBlk.uda != null && myTmpBlk.uda.Length > 0 && myTmpBlk.uda[0] > 0)
                    {
                        step7Attributes = new List <Step7Attribute>();
                        for (int j = 0; j < myTmpBlk.uda[0]; j++)
                        {
                            string t1 = Project.ProjectEncoding.GetString(myTmpBlk.uda, uPos + 1, myTmpBlk.uda[uPos]);
                            uPos += myTmpBlk.uda[uPos] + 1;
                            string t2 = Project.ProjectEncoding.GetString(myTmpBlk.uda, uPos + 1, myTmpBlk.uda[uPos]);
                            uPos += myTmpBlk.uda[uPos] + 1;
                            step7Attributes.Add(new Step7Attribute(t1, t2));
                        }
                    }
                }

                //Begin with the Block Reading...
                if (blkInfo.BlockType == PLCBlockType.VAT)
                {
                    S7VATBlock retValBlock = new S7VATBlock(myTmpBlk.mc7code, myTmpBlk.comments, plcblkifo.BlockNumber, Project.ProjectEncoding);
                    retValBlock.Attributes = step7Attributes;

                    retValBlock.LastCodeChange      = myTmpBlk.LastCodeChange;
                    retValBlock.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retValBlock.ParentFolder            = this;
                    retValBlock.usedS7ConvertingOptions = myConvOpt;
                    blkInfo._Block = retValBlock;

                    return(retValBlock);
                }
                else if (blkInfo.BlockType == PLCBlockType.DB || blkInfo.BlockType == PLCBlockType.UDT)
                {
                    List <string> tmpList = new List <string>();
                    S7DataBlock   retVal  = new S7DataBlock();
                    retVal.IsInstanceDB = myTmpBlk.IsInstanceDB;
                    retVal.FBNumber     = myTmpBlk.FBNumber;

                    //if this is an interface DB, then rather take the Interface declaration from the instance FB,
                    //instead of the data sotred in the project.
                    //The reason is that if you change the comment in an FB, the DB data is not actualized and my contain outdated
                    //Declarations. When you change the interface, Step7 tells you to "regenerate" the instance DB which only then would
                    //Actualize the comments. Simple Commentary changes do not change the Datablocks row.
                    if (retVal.IsInstanceDB && myConvOpt.UseFBDeclarationForInstanceDB)
                    {
                        //load the FB data from the Project
                        tmpBlock InstFB = GetBlockBytes((myTmpBlk.IsSFB ? "SFB" : "FB") + myTmpBlk.FBNumber);

                        //Resolve both interfaces
                        List <string> tmpPar = new List <string>();
                        if (InstFB != null)
                        {
                            S7DataRow InterfaceFB =
                                Parameter.GetInterfaceOrDBFromStep7ProjectString(InstFB.blkinterface, ref tmpPar,
                                                                                 PLCBlockType.FB, false, this, null);
                            S7DataRow InterfaceDB =
                                Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref tmpPar,
                                                                                 PLCBlockType.DB, false, this, null);

                            //Only use the FB interface Declaration if they are compatible
                            if (Parameter.IsInterfaceCompatible(InterfaceFB, InterfaceDB))
                            {
                                myTmpBlk.blkinterface = InstFB.blkinterface;
                            }
                        }
                    }

                    if (myTmpBlk.mc7code != null)
                    {
                        retVal.CodeSize = myTmpBlk.mc7code.Length;
                    }

                    retVal.StructureFromString = Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref tmpList, blkInfo.BlockType, false, this, retVal, myTmpBlk.mc7code);
                    if (myTmpBlk.blkinterfaceInMC5 != null)
                    {
                        //List<string> tmp = new List<string>();
                        //retVal.StructureFromMC7 = Parameter.GetInterface(myTmpBlk.blkinterfaceInMC5, myTmpBlk.mc7code, ref tmp, blkInfo.BlockType, myTmpBlk.IsInstanceDB, retVal);
                    }
                    retVal.BlockNumber = plcblkifo.BlockNumber;
                    retVal.BlockType   = blkInfo.BlockType;
                    retVal.Attributes  = step7Attributes;

                    retVal.LastCodeChange      = myTmpBlk.LastCodeChange;
                    retVal.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retVal.ParentFolder            = this;
                    retVal.usedS7ConvertingOptions = myConvOpt;
                    retVal.CheckSum = myTmpBlk.CheckSum;
                    blkInfo._Block  = retVal;

                    return(retVal);
                }
                else if (blkInfo.BlockType == PLCBlockType.FC || blkInfo.BlockType == PLCBlockType.FB || blkInfo.BlockType == PLCBlockType.OB || blkInfo.BlockType == PLCBlockType.SFB || blkInfo.BlockType == PLCBlockType.SFC)
                {
                    List <string> ParaList = new List <string>();

                    S7FunctionBlock retVal = new S7FunctionBlock();

                    retVal.LastCodeChange      = myTmpBlk.LastCodeChange;
                    retVal.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retVal.BlockNumber       = plcblkifo.BlockNumber;
                    retVal.BlockType         = blkInfo.BlockType;
                    retVal.Attributes        = step7Attributes;
                    retVal.KnowHowProtection = myTmpBlk.knowHowProtection;
                    retVal.MnemonicLanguage  = Project.ProjectLanguage;

                    retVal.Author  = myTmpBlk.username;
                    retVal.Version = myTmpBlk.version;

                    retVal.Parameter = Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref ParaList, blkInfo.BlockType, false, this, retVal);

                    if (myTmpBlk.blockdescription != null)
                    {
                        retVal.Title       = Project.ProjectEncoding.GetString(myTmpBlk.blockdescription, 3, myTmpBlk.blockdescription[1] - 4);
                        retVal.Description = Project.ProjectEncoding.GetString(myTmpBlk.blockdescription, myTmpBlk.blockdescription[1], myTmpBlk.blockdescription.Length - myTmpBlk.blockdescription[1] - 1).Replace("\n", Environment.NewLine);
                    }

                    if (blkInfo.BlockType == PLCBlockType.FC || blkInfo.BlockType == PLCBlockType.FB || blkInfo.BlockType == PLCBlockType.OB)
                    {
                        retVal.CodeSize = myTmpBlk.mc7code.Length;

                        int[] Networks;
                        Networks = NetWork.GetNetworks(0, myTmpBlk.nwinfo);

                        S7ProgrammFolder prgFld = null;
                        if (this.Parent is S7ProgrammFolder)
                        {
                            prgFld = (S7ProgrammFolder)this.Parent;
                        }

                        retVal.AWLCode = MC7toAWL.GetAWL(0, myTmpBlk.mc7code.Length - 2, (int)myConvOpt.Mnemonic, myTmpBlk.mc7code, Networks, ParaList, prgFld, retVal, retVal.Parameter);

                        retVal.AWLCode = JumpMarks.AddJumpmarks(retVal.AWLCode, myTmpBlk.jumpmarks, myTmpBlk.nwinfo, myConvOpt);

                        LocalDataConverter.ConvertLocaldataToSymbols(retVal, myConvOpt);

                        CallConverter.ConvertUCToCall(retVal, prgFld, this, myConvOpt, null);

                        FBStaticAccessConverter.ReplaceStaticAccess(retVal, prgFld, myConvOpt);

                        #region UseComments from Block
                        if (myConvOpt.UseComments)
                        {
                            List <FunctionBlockRow> newAwlCode = new List <FunctionBlockRow>();

                            int n = 0;
                            int akRowInAwlCode   = 0;
                            int lineNumberInCall = 0; //Counter wich line in Command (for Calls and UCs)

                            if (myTmpBlk.comments != null)
                            {
                                byte[] cmt = myTmpBlk.comments;

                                //string aa = System.Text.Encoding.GetEncoding("Windows-1251").GetString(cmt);
                                //string testaa = "";

                                while (n < myTmpBlk.comments.Length)
                                {
                                    int kommLen            = cmt[n + 0];
                                    int startNWKomm        = cmt[n + 1];
                                    int anzUebsprungZeilen = cmt[n + 2] + cmt[n + 3] * 0x100;
                                    int lenNWKommZeile     = cmt[n + 3] + cmt[n + 4] * 0x100;
                                    //Console.WriteLine(cmt[n + 5].ToString("X"));
                                    if (cmt[n + 5] == 0x06)
                                    {
                                        //NWKomentar:
                                        string tx1 = Project.ProjectEncoding.GetString(cmt, n + 6, startNWKomm - 7);
                                        string tx2 = Project.ProjectEncoding.GetString(cmt, n + startNWKomm, lenNWKommZeile - startNWKomm - 1).Replace("\n", Environment.NewLine);
                                        n += lenNWKommZeile;

                                        if (retVal.AWLCode.Count > akRowInAwlCode)
                                        {
                                            while (retVal.AWLCode.Count - 1 > akRowInAwlCode && retVal.AWLCode[akRowInAwlCode].Command != "NETWORK")
                                            {
                                                if (!newAwlCode.Contains(retVal.AWLCode[akRowInAwlCode]))
                                                {
                                                    //newAwlCode.Add(retVal.AWLCode[akRowInAwlCode]);
                                                    S7FunctionBlockRow akRw = (S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode];

                                                    if (akRw.CombineDBAccess)
                                                    {
                                                        S7FunctionBlockRow nRw = (S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode + 1];
                                                        if (!nRw.Parameter.Contains("["))
                                                        {
                                                            nRw.Parameter = akRw.Parameter + "." + nRw.Parameter;
                                                            nRw.MC7       = Helper.CombineByteArray(akRw.MC7, nRw.MC7);
                                                            nRw.Label     = akRw.Label ?? nRw.Label;
                                                            akRw          = nRw;
                                                            retVal.AWLCode.RemoveAt(akRowInAwlCode + 1);
                                                        }
                                                    }

                                                    if (!newAwlCode.Contains(akRw))
                                                    {
                                                        newAwlCode.Add(akRw);
                                                    }
                                                }
                                                akRowInAwlCode++;
                                            }
                                            ((S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode]).NetworkName = tx1;
                                            ((S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode]).Comment     = tx2;
                                            newAwlCode.Add(retVal.AWLCode[akRowInAwlCode]);
                                        }
                                        akRowInAwlCode++;

                                        lineNumberInCall = 0;
                                    }
                                    else
                                    {
                                        S7FunctionBlockRow lastRow = null;

                                        //Anzahl der Anweisungen vor diesem Kommentar (inklusive aktueller Zeile!)
                                        for (int q = 0; q < (anzUebsprungZeilen); q++)
                                        {
                                            if (retVal.AWLCode.Count > akRowInAwlCode)
                                            {
                                                S7FunctionBlockRow akRw = (S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode];

                                                if (cmt[n + 4] == 0xc0 && q == anzUebsprungZeilen - 1)
                                                {
                                                    akRw.CombineDBAccess = false;
                                                }

                                                //Db Zugriff zusammenfügen...
                                                if (akRw.CombineDBAccess)
                                                {
                                                    S7FunctionBlockRow nRw = (S7FunctionBlockRow)retVal.AWLCode[akRowInAwlCode + 1];
                                                    nRw.Parameter = akRw.Parameter + "." + nRw.Parameter;
                                                    nRw.MC7       = Helper.CombineByteArray(akRw.MC7, nRw.MC7);
                                                    nRw.Label     = akRw.Label ?? nRw.Label;
                                                    akRw          = nRw;
                                                    retVal.AWLCode.RemoveAt(akRowInAwlCode + 1);
                                                }

                                                if (!newAwlCode.Contains(akRw))
                                                {
                                                    newAwlCode.Add(akRw);
                                                }


                                                if (akRw.GetNumberOfLines() == 1)
                                                {
                                                    lineNumberInCall = 0;

                                                    lastRow = akRw;

                                                    //if (!newAwlCode.Contains(akRw))
                                                    //    newAwlCode.Add(akRw);

                                                    akRowInAwlCode++;
                                                }
                                                else
                                                {
                                                    lastRow = akRw;
                                                    if (lineNumberInCall == 0 && !(cmt[n + 4] != 0x80 && cmt[n + 4] != 0xc0))
                                                    {
                                                        //if (!newAwlCode.Contains(akRw))
                                                        //    newAwlCode.Add(akRw);
                                                    }

                                                    if (akRw.GetNumberOfLines() - 1 == lineNumberInCall)
                                                    {
                                                        akRowInAwlCode++;
                                                        lineNumberInCall = 0;
                                                        //subCnt++;    //The set to zero was wrong here, but maybe now comments on calls do not work, need to check!
                                                    }
                                                    else
                                                    {
                                                        lineNumberInCall++;
                                                    }
                                                }
                                            }
                                        }


                                        //if (lastRow == null || cmt[n + 4] != 0x80)
                                        if (lastRow == null || (cmt[n + 4] != 0x80 && cmt[n + 4] != 0xc0))
                                        {
                                            lastRow = new S7FunctionBlockRow()
                                            {
                                                Parent = retVal
                                            };
                                            newAwlCode.Add(lastRow);
                                            lineNumberInCall = 0;
                                        }

                                        string tx1 = Project.ProjectEncoding.GetString(cmt, n + 6, kommLen);
                                        if (lineNumberInCall == 0)
                                        {
                                            lastRow.Comment = tx1;
                                        }
                                        else
                                        if (lastRow.Command == "CALL")
                                        {
                                            if (lineNumberInCall == 1)
                                            {
                                                lastRow.Comment = tx1;
                                            }
                                            else
                                            {
                                                if (lastRow.CallParameter.Count >= lineNumberInCall - 2)
                                                {
                                                    lastRow.CallParameter[lineNumberInCall - 2].Comment = tx1;
                                                }
                                            }
                                        }
                                        n += kommLen + 6;

                                        //subCnt = 0;
                                    }
                                }
                            }
                            while (akRowInAwlCode < retVal.AWLCode.Count)
                            {
                                newAwlCode.Add(retVal.AWLCode[akRowInAwlCode]);
                                akRowInAwlCode++;
                            }
                            retVal.AWLCode = newAwlCode;
                        }
                        #endregion
                    }

                    retVal.Networks = NetWork.GetNetworksList(retVal);

                    retVal.ParentFolder            = this;
                    retVal.usedS7ConvertingOptions = myConvOpt;
                    retVal.CheckSum = myTmpBlk.CheckSum;
                    blkInfo._Block  = retVal;

                    return(retVal);
                }
            }
            return(null);
        }
        /// <summary>
        /// Reads the raw data from the S7 Project files, without parsing the data
        /// </summary>
        /// <param name="blkInfo">The Block info object that identifies the block to read from Disk</param>
        /// <returns></returns>
        private tmpBlock GetBlockBytes(ProjectBlockInfo blkInfo)
        {
            if (subblkDBF != null) //ZipHelper.FileExists(((Step7ProjectV5)Project)._zipfile, Folder + "SUBBLK.DBF"))
            {
                tmpBlock myTmpBlk = new tmpBlock();

                var       bstTbl  = bausteinDBF;
                DataRow[] bstRows = bstTbl.Select("ID = " + blkInfo.id);
                if (bstRows != null && bstRows.Length > 0 && !(bstRows[0]["UDA"] is DBNull))
                {
                    myTmpBlk.uda = (byte[])bstRows[0]["UDA"];
                }

                var dbfTbl = subblkDBF;

                DataRow[] rows = dbfTbl.Select("OBJECTID = " + blkInfo.id);

                foreach (DataRow row in rows)
                {
                    int subblktype = Convert.ToInt32(row["SUBBLKTYP"]);
                    int objid      = (int)row["OBJECTID"];

                    if (objid == blkInfo.id)
                    {
                        byte[] mc5code = null;
                        byte[] ssbpart = null;
                        byte[] addinfo = null;

                        if (row["MC5CODE"] != DBNull.Value)
                        {
                            mc5code = (byte[])row["MC5CODE"];
                        }
                        if (row["SSBPART"] != DBNull.Value)
                        {
                            ssbpart = (byte[])row["SSBPART"];
                        }
                        if (row["ADDINFO"] != DBNull.Value)
                        {
                            addinfo = (byte[])row["ADDINFO"];
                        }
                        int mc5codelen = (int)row["MC5LEN"];
                        int ssbpartlen = (int)row["SSBLEN"];
                        int addinfolen = (int)row["ADDLEN"];

                        if (mc5code != null && mc5code.Length > mc5codelen)
                        {
                            Array.Resize <byte>(ref mc5code, mc5codelen);
                        }
                        if (ssbpart != null && ssbpart.Length > ssbpartlen)
                        {
                            Array.Resize <byte>(ref ssbpart, ssbpartlen);
                        }
                        if (addinfo != null && addinfo.Length > addinfolen)
                        {
                            Array.Resize <byte>(ref addinfo, addinfolen);
                        }

                        var tmpCheckSum = (int)row["CHECKSUM"];
                        if (myTmpBlk.CheckSum == 0 && tmpCheckSum != 0)
                        {
                            if (BitConverter.IsLittleEndian)
                            {
                                var tmp = BitConverter.GetBytes(tmpCheckSum);
                                Array.Reverse(tmp);
                                var tmp2 = BitConverter.ToUInt16(tmp, 2);
                                myTmpBlk.CheckSum = Convert.ToInt32(tmp2);
                            }
                            else
                            {
                                myTmpBlk.CheckSum = tmpCheckSum;
                            }
                        }

                        if (subblktype == 12 || subblktype == 8 || subblktype == 14 || subblktype == 13 || subblktype == 15) //FC, OB, FB, SFC, SFB
                        {
                            if (row["PASSWORD"] != DBNull.Value && (int)row["PASSWORD"] == 3)
                            {
                                myTmpBlk.knowHowProtection = true;
                            }
                            //MC7 Code in mc5code
                            myTmpBlk.mc7code  = mc5code;
                            myTmpBlk.username = ((string)row["USERNAME"]).Replace("\0", "").Trim();

                            int ver = ((int)row["VERSION"]);
                            // Calculate Block version
                            // 0 .. 255
                            // 0.0 .. 15.15
                            myTmpBlk.version = (ver / 16).ToString() + "." + (ver % 16).ToString();

                            //Network Information in addinfo
                            myTmpBlk.nwinfo = addinfo;
                            //This line contains Network Information, and after it the Position of the JumpMarks

                            myTmpBlk.LastCodeChange      = GetTimeStamp((string)row["TIMESTAMP1"]);
                            myTmpBlk.LastInterfaceChange = GetTimeStamp((string)row["TIMESTAMP2"]);
                        }
                        else if (subblktype == 5 || subblktype == 3 || subblktype == 4 || subblktype == 7 || subblktype == 9) //FC, OB, FB, SFC, SFB
                        {
                            //Interface in mc5code
                            if (mc5code != null)
                            {
                                myTmpBlk.blkinterface =
                                    Project.ProjectEncoding.GetString(mc5code);
                            }
                        }
                        else if (subblktype == 19 || subblktype == 17 || subblktype == 18 || subblktype == 22 ||
                                 subblktype == 21)               //FC, OB, FB, SFC, SFB
                        {
                            myTmpBlk.comments         = mc5code; //Comments of the Block
                            myTmpBlk.blockdescription = ssbpart; //Description of the Block
                            myTmpBlk.jumpmarks        = addinfo;
                            //The Text of the Jump Marks, Before the Jumpmarks there is some Network Information, but don't know what!
                        }

                        else if (subblktype == 6 || subblktype == 1) //DB, UDT
                        {
                            //DB Structure in Plain Text (Structure and StartValues!)
                            if (mc5code != null)
                            {
                                myTmpBlk.blkinterface =
                                    Project.ProjectEncoding.GetString(mc5code);
                            }
                            //Maybe compiled DB Structure?
                            myTmpBlk.addinfo = addinfo;
                        }
                        else if (subblktype == 10) //DB
                        {
                            //Need to check wich Information is stored here
                            myTmpBlk.mc7code             = mc5code;
                            myTmpBlk.blkinterfaceInMC5   = ssbpart;
                            myTmpBlk.LastCodeChange      = GetTimeStamp((string)row["TIMESTAMP1"]);
                            myTmpBlk.LastInterfaceChange = GetTimeStamp((string)row["TIMESTAMP2"]);

                            if (ssbpart != null && ssbpartlen > 2 && (ssbpart[0] == 0x0a || ssbpart[0] == 0x0b))
                            {
                                // if ssbpart[0] == 5 this DB is normal
                                // if ssbpart[0] == 10 this DB is instance for FB,
                                // if ssbpart[0] == 11 this DB is instance for SFB,
                                myTmpBlk.IsInstanceDB = true;
                                if (ssbpart[0] == 11)
                                {
                                    myTmpBlk.IsSFB = true;
                                }
                                myTmpBlk.FBNumber = (int)ssbpart[1] + 256 * (int)ssbpart[2];
                            }
                        }
                        else if (subblktype == 0x14) //DB
                        {
                            //Need to check wich Information is stored here
                        }
                        else if (subblktype == 0x42) //DB
                        {
                            //Need to check wich Information is stored here
                        }
                        else if (subblktype == 27) //VAT
                        {
                            myTmpBlk.LastCodeChange      = GetTimeStamp((string)row["TIMESTAMP1"]);
                            myTmpBlk.LastInterfaceChange = GetTimeStamp((string)row["TIMESTAMP2"]);

                            //VAT in MC5Code (Absolut adressed)
                            myTmpBlk.mc7code = mc5code;
                            //VAT in ADDINFO (Symbolic adressed)
                            myTmpBlk.nwinfo = addinfo;
                        }
                        else if (subblktype == 38) //VAT
                        {
                            //VAT Comments in MC5Code
                            myTmpBlk.comments = mc5code;
                        }
                    }
                }
                return(myTmpBlk);
            }
            return(null);
        }
示例#18
0
        public Block GetBlock(ProjectBlockInfo blkInfo)
        {
            if (blkInfo._Block != null)
            {
                return(blkInfo._Block);
            }

            ProjectPlcBlockInfo plcblkInfo = (ProjectPlcBlockInfo)blkInfo;
            //string aa = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(((Step5ProjectBlockInfo)blkInfo)._blkByte);
            //string bb = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(((Step5ProjectBlockInfo)blkInfo)._blkHeaderByte);
            Block retVal = null;

            if (blkInfo.BlockType == PLCBlockType.S5_DV)
            {
                retVal = MC5toDB.GetDB((ProjectPlcBlockInfo)plcblkInfo, null, ((S5ProjectBlockInfo)blkInfo)._blkByte, null);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_DVX)
            {
                retVal = MC5toDB.GetDB((ProjectPlcBlockInfo)plcblkInfo, null, ((S5ProjectBlockInfo)blkInfo)._blkByte, null);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_DB)
            {
                retVal = MC5toDB.GetDB((ProjectPlcBlockInfo)plcblkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, GetBlockInByte("S5_DV" + plcblkInfo.BlockNumber.ToString()), GetBlockInByte("S5_DK" + plcblkInfo.BlockNumber.ToString()));
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_DX)
            {
                retVal = MC5toDB.GetDB((ProjectPlcBlockInfo)plcblkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, GetBlockInByte("S5_DVX" + plcblkInfo.BlockNumber.ToString()), GetBlockInByte("S5_DKX" + plcblkInfo.BlockNumber.ToString()));
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_DK)
            {
                retVal = MC5toComment.GetCommentBlock(blkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_DKX)
            {
                retVal = MC5toComment.GetCommentBlock(blkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_PB)
            {
                retVal = MC5toAWL.GetFunctionBlock((ProjectPlcBlockInfo)blkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, null, GetBlockInByte("S5_PK" + plcblkInfo.BlockNumber.ToString()), (Step5ProgrammFolder)blkInfo.ParentFolder.Parent);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_FB)
            {
                retVal = MC5toAWL.GetFunctionBlock(plcblkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, GetBlockInByte("S5_FV" + plcblkInfo.BlockNumber.ToString()), GetBlockInByte("S5_FK" + plcblkInfo.BlockNumber.ToString()), (Step5ProgrammFolder)blkInfo.ParentFolder.Parent);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_SB)
            {
                retVal = MC5toAWL.GetFunctionBlock(plcblkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, null, GetBlockInByte("S5_SK" + plcblkInfo.BlockNumber.ToString()), (Step5ProgrammFolder)blkInfo.ParentFolder.Parent);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_FX)
            {
                retVal = MC5toAWL.GetFunctionBlock(plcblkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, GetBlockInByte("S5_FVX" + plcblkInfo.BlockNumber.ToString()), GetBlockInByte("S5_FKX" + plcblkInfo.BlockNumber.ToString()), (Step5ProgrammFolder)blkInfo.ParentFolder.Parent);
            }
            else if (blkInfo.BlockType == PLCBlockType.S5_OB)
            {
                retVal = MC5toAWL.GetFunctionBlock(plcblkInfo, ((S5ProjectBlockInfo)blkInfo)._blkByte, null, GetBlockInByte("S5_OK" + plcblkInfo.BlockNumber.ToString()), (Step5ProgrammFolder)blkInfo.ParentFolder.Parent);
            }

            if (retVal != null)
            {
                retVal.ParentFolder = this;
            }

            blkInfo._Block = retVal;

            return(retVal);
        }
        private void cmdOk_Click(object sender, EventArgs e)
        {
            if (SelectPart == SelectPartType.BlocksOfflineFolder)
            {
                if (treeStep7Project.SelectedNode != null)
                {
                    var tmp = (myTreeNode)treeStep7Project.SelectedNode;
                    if (typeof(IBlocksFolder).IsAssignableFrom(tmp.myObject.GetType()))
                    {
                        retVal = (IBlocksFolder)tmp.myObject;
                    }
                    else
                    {
                        retVal = null;
                    }
                }
            }
            else if (SelectPart == SelectPartType.S7ProgrammFolder)
            {
                if (treeStep7Project.SelectedNode != null)
                {
                    var tmp = (myTreeNode)treeStep7Project.SelectedNode;
                    if (typeof(S7ProgrammFolder).IsAssignableFrom(tmp.myObject.GetType()))
                    {
                        retVal = (S7ProgrammFolder)tmp.myObject;
                    }
                    else
                    {
                        retVal = null;
                    }
                }
            }
            else if (SelectPart == SelectPartType.RootProgrammFolder)
            {
                if (treeStep7Project.SelectedNode != null)
                {
                    var tmp = (myTreeNode)treeStep7Project.SelectedNode;
                    if (typeof(IRootProgrammFolder).IsAssignableFrom(tmp.myObject.GetType()))
                    {
                        retVal = (IRootProgrammFolder)tmp.myObject;
                    }
                    else
                    {
                        retVal = null;
                    }
                }
            }
            else if (SelectPart == SelectPartType.VariableTable)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem;
                    if (tmp.BlockType == PLCBlockType.VAT)
                    {
                        retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp);
                        ((Block)retVal).ParentFolder = tmp.ParentFolder;
                    }
                }
            }
            else if (SelectPart == SelectPartType.VariableTableOrSymbolTable)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem;
                    if (tmp.BlockType == PLCBlockType.VAT)
                    {
                        retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp);
                        ((Block)retVal).ParentFolder = tmp.ParentFolder;
                    }
                }
                else if (treeStep7Project.SelectedNode != null)
                {
                    var tmp = (myTreeNode)treeStep7Project.SelectedNode;
                    if (tmp.myObject is ISymbolTable)
                    {
                        retVal = tmp.myObject as ISymbolTable;
                    }
                }
            }
            else if (SelectPart == SelectPartType.DataBlock)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem;
                    if (tmp.BlockType == PLCBlockType.DB)
                    {
                        retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp);
                        ((Block)retVal).ParentFolder = tmp.ParentFolder;
                    }
                }
            }
            else if (SelectPart == SelectPartType.IDataBlock)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    ProjectBlockInfo tmp = (ProjectBlockInfo)lstProjectFolder.SelectedItem;
                    if (tmp.BlockType == PLCBlockType.DB)
                    {
                        retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp);
                        ((Block)retVal).ParentFolder = tmp.ParentFolder;
                    }
                }
            }
            else if (SelectPart == SelectPartType.DataBlocks)
            {
                if (lstProjectFolder.SelectedItems.Count > 0)
                {
                    this.Hide();

                    var blocks = new List <S7DataBlock>();

                    foreach (S7ProjectBlockInfo s7ProjectBlockInfo in lstProjectFolder.SelectedItems)
                    {
                        if (s7ProjectBlockInfo.BlockType == PLCBlockType.DB)
                        {
                            var block = ((IBlocksFolder)s7ProjectBlockInfo.ParentFolder).GetBlock(s7ProjectBlockInfo);
                            block.ParentFolder = s7ProjectBlockInfo.ParentFolder;

                            blocks.Add((S7DataBlock)block);
                        }
                    }

                    retVal = blocks.Count > 0 ? blocks : null;
                }
            }
            else if (SelectPart == SelectPartType.IDataBlocks)
            {
                if (lstProjectFolder.SelectedItems.Count > 0)
                {
                    this.Hide();

                    var blocks = new List <IDataBlock>();

                    foreach (ProjectBlockInfo s7ProjectBlockInfo in lstProjectFolder.SelectedItems)
                    {
                        if (s7ProjectBlockInfo.BlockType == PLCBlockType.DB)
                        {
                            var block = ((IBlocksFolder)s7ProjectBlockInfo.ParentFolder).GetBlock(s7ProjectBlockInfo);
                            block.ParentFolder = s7ProjectBlockInfo.ParentFolder;

                            blocks.Add((IDataBlock)block);
                        }
                    }

                    retVal = blocks.Count > 0 ? blocks : null;
                }
            }
            else if (SelectPart == SelectPartType.FunctionBlock)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem;
                    if (tmp.BlockType == PLCBlockType.FC || tmp.BlockType == PLCBlockType.FB || tmp.BlockType == PLCBlockType.OB)
                    {
                        retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp);
                        ((Block)retVal).ParentFolder = tmp.ParentFolder;
                    }
                }
            }
            else if (SelectPart == SelectPartType.DataType)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem;
                    if (tmp.BlockType == PLCBlockType.UDT)
                    {
                        retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp);
                        ((Block)retVal).ParentFolder = tmp.ParentFolder;
                    }
                }
            }
            else if (SelectPart == SelectPartType.SymbolTable)
            {
                if (treeStep7Project.SelectedNode != null)
                {
                    var tmp = (myTreeNode)treeStep7Project.SelectedNode;
                    if (tmp.myObject is ISymbolTable)
                    {
                        retVal = tmp.myObject as ISymbolTable;
                    }
                    else
                    {
                        retVal = null;
                    }
                }
            }
            else if (SelectPart == SelectPartType.Tag)
            {
                if (lstProjectFolder.SelectedItem != null)
                {
                    this.Hide();
                    DBRowValue tmp = (DBRowValue)lstProjectFolder.SelectedItem;
                    retVal = tmp.myRow.PlcTag;
                }
            }
            if (retVal != null)
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("Please select the right Project Part, or press cancel to close this window.");
            }
        }
示例#20
0
        public Block GetBlock(ProjectBlockInfo blkInfo, S7ConvertingOptions myConvOpt)
        {
            //Todo: Enable this, but then myConvOpt is only used the first time!
            //if (blkInfo._Block != null)
            //    return blkInfo._Block;


            ProjectPlcBlockInfo plcblkifo = (ProjectPlcBlockInfo)blkInfo;
            tmpBlock            myTmpBlk  = GetBlockBytes(blkInfo);

            List <Step7Attribute> step7Attributes = null;

            if (myTmpBlk != null)
            {
                if (myTmpBlk.uda != null)
                {
                    int uPos = 2;
                    if (myTmpBlk.uda != null && myTmpBlk.uda.Length > 0 && myTmpBlk.uda[0] > 0)
                    {
                        step7Attributes = new List <Step7Attribute>();
                        for (int j = 0; j < myTmpBlk.uda[0]; j++)
                        {
                            string t1 = Project.ProjectEncoding.GetString(myTmpBlk.uda, uPos + 1, myTmpBlk.uda[uPos]);
                            uPos += myTmpBlk.uda[uPos] + 1;
                            string t2 = Project.ProjectEncoding.GetString(myTmpBlk.uda, uPos + 1, myTmpBlk.uda[uPos]);
                            uPos += myTmpBlk.uda[uPos] + 1;
                            step7Attributes.Add(new Step7Attribute(t1, t2));
                        }
                    }
                }


                //Begin with the Block Reading...
                if (blkInfo.BlockType == PLCBlockType.VAT)
                {
                    S7VATBlock retValBlock = new S7VATBlock(myTmpBlk.mc7code, myTmpBlk.comments, plcblkifo.BlockNumber, Project.ProjectEncoding);
                    retValBlock.Attributes = step7Attributes;

                    retValBlock.LastCodeChange      = myTmpBlk.LastCodeChange;
                    retValBlock.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retValBlock.BlockLanguage = (PLCLanguage)myTmpBlk.Language;

                    return(retValBlock);
                }
                else if (blkInfo.BlockType == PLCBlockType.DB || blkInfo.BlockType == PLCBlockType.UDT)
                {
                    List <string> tmpList = new List <string>();
                    S7DataBlock   retVal  = new S7DataBlock();
                    retVal.IsInstanceDB        = myTmpBlk.IsInstanceDB;
                    retVal.FBNumber            = myTmpBlk.FBNumber;
                    retVal.StructureFromString = Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref tmpList, blkInfo.BlockType, false, this, retVal, myTmpBlk.mc7code);
                    if (myTmpBlk.blkinterfaceInMC5 != null)
                    {
                        //List<string> tmp = new List<string>();
                        //retVal.StructureFromMC7 = Parameter.GetInterface(myTmpBlk.blkinterfaceInMC5, myTmpBlk.mc7code, ref tmp, blkInfo.BlockType, myTmpBlk.IsInstanceDB, retVal);
                    }
                    retVal.BlockNumber = plcblkifo.BlockNumber;
                    retVal.BlockType   = blkInfo.BlockType;
                    retVal.Attributes  = step7Attributes;

                    retVal.LastCodeChange      = myTmpBlk.LastCodeChange;
                    retVal.LastInterfaceChange = myTmpBlk.LastInterfaceChange;
                    if (blkInfo.BlockType != PLCBlockType.UDT)
                    {
                        retVal.CodeSize = myTmpBlk.mc7code.Length + 36;
                    }

                    retVal.BlockLanguage = (PLCLanguage)myTmpBlk.Language;

                    return(retVal);
                }
                else if (blkInfo.BlockType == PLCBlockType.FC || blkInfo.BlockType == PLCBlockType.FB || blkInfo.BlockType == PLCBlockType.OB || blkInfo.BlockType == PLCBlockType.SFB || blkInfo.BlockType == PLCBlockType.SFC)
                {
                    List <string> ParaList = new List <string>();

                    S7FunctionBlock retVal = new S7FunctionBlock();
                    blkInfo._Block = retVal;

                    retVal.LastCodeChange      = myTmpBlk.LastCodeChange;
                    retVal.LastInterfaceChange = myTmpBlk.LastInterfaceChange;

                    retVal.BlockNumber       = plcblkifo.BlockNumber;
                    retVal.BlockType         = blkInfo.BlockType;
                    retVal.Attributes        = step7Attributes;
                    retVal.KnowHowProtection = myTmpBlk.knowHowProtection;
                    retVal.MnemonicLanguage  = Project.ProjectLanguage;
                    retVal.CodeSize          = myTmpBlk.mc7code.Length + 36;

                    retVal.Author  = myTmpBlk.username;
                    retVal.Version = myTmpBlk.version;

                    //  retVal.Parameter = Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref ParaList, blkInfo.BlockType, false, this, retVal);

                    if (myTmpBlk.blockdescription != null)
                    {
                        retVal.Title       = Project.ProjectEncoding.GetString(myTmpBlk.blockdescription, 3, myTmpBlk.blockdescription[1] - 4);
                        retVal.Description = Project.ProjectEncoding.GetString(myTmpBlk.blockdescription, myTmpBlk.blockdescription[1], myTmpBlk.blockdescription.Length - myTmpBlk.blockdescription[1] - 1).Replace("\n", Environment.NewLine);
                    }

                    retVal.BlockLanguage = (PLCLanguage)myTmpBlk.Language;

                    return(retVal);

                    if (blkInfo.BlockType == PLCBlockType.FC || blkInfo.BlockType == PLCBlockType.FB || blkInfo.BlockType == PLCBlockType.OB)
                    {
                        int[] Networks;
                        Networks = NetWork.GetNetworks(0, myTmpBlk.nwinfo);

                        S7ProgrammFolder prgFld = null;
                        if (this.Parent is S7ProgrammFolder)
                        {
                            prgFld = (S7ProgrammFolder)this.Parent;
                        }

                        retVal.AWLCode = MC7toAWL.GetAWL(0, myTmpBlk.mc7code.Length - 2, (int)myConvOpt.Mnemonic, myTmpBlk.mc7code, Networks, ParaList, prgFld);

                        retVal.AWLCode = JumpMarks.AddJumpmarks(retVal.AWLCode, myTmpBlk.jumpmarks, myTmpBlk.nwinfo);

                        LocalDataConverter.ConvertLocaldataToSymbols(retVal, myConvOpt);

                        FBStaticAccessConverter.ReplaceStaticAccess(retVal, prgFld, myConvOpt);

                        CallConverter.ConvertUCToCall(retVal, prgFld, this, myConvOpt, null);

                        #region UseComments from Block
                        if (myConvOpt.UseComments)
                        {
                            List <FunctionBlockRow> newAwlCode = new List <FunctionBlockRow>();

                            int n      = 0;
                            int j      = 0;
                            int subCnt = 0; //Counter wich line in Command (for Calls and UCs)

                            if (myTmpBlk.comments != null)
                            {
                                byte[] cmt = myTmpBlk.comments;

                                //string aa = System.Text.Encoding.GetEncoding("Windows-1251").GetString(cmt);
                                //string testaa = "";

                                while (n < myTmpBlk.comments.Length)
                                {
                                    int kommLen            = cmt[n + 0];
                                    int startNWKomm        = cmt[n + 1];
                                    int anzUebsprungZeilen = cmt[n + 2] + cmt[n + 3] * 0x100;
                                    int lenNWKommZeile     = cmt[n + 3] + cmt[n + 4] * 0x100;
                                    //Console.WriteLine(cmt[n + 5].ToString("X"));
                                    if (cmt[n + 5] == 0x06)
                                    {
                                        //NWKomentar:
                                        string tx1 = Project.ProjectEncoding.GetString(cmt, n + 6, startNWKomm - 7);
                                        string tx2 = Project.ProjectEncoding.GetString(cmt, n + startNWKomm, lenNWKommZeile - startNWKomm - 1).Replace("\n", Environment.NewLine);
                                        n += lenNWKommZeile;

                                        if (retVal.AWLCode.Count > j)
                                        {
                                            while (retVal.AWLCode.Count - 1 > j && retVal.AWLCode[j].Command != "NETWORK")
                                            {
                                                newAwlCode.Add(retVal.AWLCode[j]);
                                                j++;
                                            }
                                            ((S7FunctionBlockRow)retVal.AWLCode[j]).NetworkName = tx1;
                                            ((S7FunctionBlockRow)retVal.AWLCode[j]).Comment     = tx2;
                                            newAwlCode.Add(retVal.AWLCode[j]);
                                        }
                                        j++;

                                        subCnt = 0;
                                    }
                                    else
                                    {
                                        S7FunctionBlockRow lastRow = null;

                                        //Anzahl der Anweisungen vor diesem Kommentar (inklusive aktueller Zeile!)
                                        for (int q = 0; q < (anzUebsprungZeilen); q++)
                                        {
                                            if (retVal.AWLCode.Count > j)
                                            {
                                                S7FunctionBlockRow akRw = (S7FunctionBlockRow)retVal.AWLCode[j];

                                                if (cmt[n + 4] == 0xc0 && q == anzUebsprungZeilen - 1)
                                                {
                                                    akRw.CombineDBAccess = false;
                                                }

                                                //Db Zugriff zusammenfügen...
                                                if (akRw.CombineDBAccess)
                                                {
                                                    S7FunctionBlockRow nRw = (S7FunctionBlockRow)retVal.AWLCode[j + 1];
                                                    nRw.Parameter = akRw.Parameter + "." + nRw.Parameter;
                                                    nRw.MC7       = Helper.CombineByteArray(akRw.MC7, nRw.MC7);

                                                    akRw = nRw;
                                                    retVal.AWLCode.RemoveAt(j + 1);
                                                }


                                                if (akRw.GetNumberOfLines() == 1)
                                                {
                                                    subCnt = 0;

                                                    lastRow = akRw;

                                                    newAwlCode.Add(akRw);
                                                    j++;
                                                }
                                                else
                                                {
                                                    lastRow = akRw;
                                                    if (subCnt == 0)
                                                    {
                                                        newAwlCode.Add(akRw);
                                                    }

                                                    if (akRw.GetNumberOfLines() - 1 == subCnt)
                                                    {
                                                        j++;
                                                        //subCnt = 0;
                                                        subCnt++;
                                                    }
                                                    else
                                                    {
                                                        subCnt++;
                                                    }
                                                }
                                            }
                                        }


                                        //if (lastRow == null || cmt[n + 4] != 0x80)
                                        if (lastRow == null || (cmt[n + 4] != 0x80 && cmt[n + 4] != 0xc0))
                                        {
                                            lastRow = new S7FunctionBlockRow();
                                            newAwlCode.Add(lastRow);
                                            subCnt = 0;
                                        }

                                        string tx1 = Project.ProjectEncoding.GetString(cmt, n + 6, kommLen);
                                        if (subCnt == 0)
                                        {
                                            lastRow.Comment = tx1;
                                        }
                                        else
                                        if (lastRow.Command == "CALL")
                                        {
                                            if (subCnt == 1)
                                            {
                                                lastRow.Comment = tx1;
                                            }
                                            else
                                            {
                                                lastRow.CallParameter[subCnt - 2].Comment = tx1;
                                            }
                                        }
                                        n += kommLen + 6;

                                        //subCnt = 0;
                                    }
                                }
                            }
                            while (j < retVal.AWLCode.Count)
                            {
                                newAwlCode.Add(retVal.AWLCode[j]);
                                j++;
                            }
                            retVal.AWLCode = newAwlCode;
                        }
                        #endregion
                    }

                    retVal.Networks = NetWork.GetNetworksList(retVal);

                    retVal.ParentFolder = this;

                    return(retVal);
                }
            }
            return(null);
        }
示例#21
0
 public Block GetBlock(ProjectBlockInfo blkInfo)
 {
     return(GetBlock(((ProjectPlcBlockInfo)blkInfo).BlockName));
 }