示例#1
0
        public void ParseDatablockWithComplexInitialValues()
        {
            byte[]      block = File.ReadAllBytes(dir + "DB3003.bin");
            S7DataBlock DB    = (S7DataBlock)DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.MC7Converter.GetAWLBlock(block, MnemonicLanguage.German);

            //General Structure must be the same
            string Test = DB.ToString().Trim().Replace("\r\n", "\n");
            string AWL  = File.ReadAllText(dir + "DB3003.awl").Trim().Replace("\r\n", "\n");

            Assert.AreEqual(AWL, DB.ToString().Trim().Replace("\r\n", "\n"));
        }
        public void ParseDataBlocks()
        {
            byte[] block;

            //_____________________________________________________________________________
            //Read Data-block with lots of Structs and Structs in Arrays
            //This db has an complex combination of Structures, arrays and Structures in Arrays
            block = File.ReadAllBytes(dir + "DB121.bin");
            S7DataBlock DB = (S7DataBlock)DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.MC7Converter.GetAWLBlock(block, MnemonicLanguage.German);

            Assert.AreEqual(PLCBlockType.DB, DB.BlockType);
            Assert.AreEqual(121, DB.BlockNumber);
            Assert.AreEqual(21418, DB.Length);             //Load memory Size
            Assert.AreEqual(20824, DB.CodeSize);           //Data size, this is the relevant data length
            Assert.AreEqual(File.ReadAllText(dir + "DB121.awl").Trim().Replace("\r\n", "\n"), DB.ToString().Trim().Replace("\r\n", "\n"));

            //_____________________________________________________________________________
            //Read Data-block With long Array of Structs
            //This is an really long data-block with an really long Array of structures
            block = File.ReadAllBytes(dir + "DB13.bin");
            DB    = (S7DataBlock)DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.MC7Converter.GetAWLBlock(block, MnemonicLanguage.German);

            Assert.AreEqual(PLCBlockType.DB, DB.BlockType);
            Assert.AreEqual(13, DB.BlockNumber);
            Assert.AreEqual(64214, DB.Length);             //Load memory Size
            Assert.AreEqual(64040, DB.CodeSize);           //Data size, this is the relevant data length
            Assert.AreEqual(File.ReadAllText(dir + "DB13.awl").Trim().Replace("\r\n", "\n"), DB.ToString().Trim().Replace("\r\n", "\n"));

            //_____________________________________________________________________________
            //Read Data-block With array and single Static Reals
            //An relatively simple block, with an Array and some simple reals at the end
            block = File.ReadAllBytes(dir + "DB4.bin");
            DB    = (S7DataBlock)DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.MC7Converter.GetAWLBlock(block, MnemonicLanguage.German);

            Assert.AreEqual(PLCBlockType.DB, DB.BlockType);
            Assert.AreEqual(4, DB.BlockNumber);
            Assert.AreEqual(8094, DB.Length);             //Load memory Size
            Assert.AreEqual(6000, DB.CodeSize);           //Data size, this is the relevant data length
            Assert.AreEqual(File.ReadAllText(dir + "DB4.awl").Trim().Replace("\r\n", "\n"), DB.Structure.ToString().Trim().Replace("\r\n", "\n"));
        }