private void cmdPrj2_Click(object sender, RoutedEventArgs e) { fld2 = DotNetSiemensPLCToolBoxLibrary.Projectfiles.SelectProjectPart.SelectBlocksOfflineFolder(); if (fld2 != null) { prj2.Text = fld2.ToString(); } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { lstProjectFolder.Items.Clear(); if (treeStep7Project.SelectedNode is myTreeNode) { var tmp = (myTreeNode)treeStep7Project.SelectedNode; if (tmp.myObject.GetType() == typeof(BlocksOfflineFolder)) { BlocksOfflineFolder blkFld = (BlocksOfflineFolder)tmp.myObject; if ((int)SelectPart > 1000) { List <ProjectBlockInfo> blocks = blkFld.readPlcBlocksList(); foreach (ProjectBlockInfo step7ProjectBlockInfo in blocks) { if (step7ProjectBlockInfo.BlockType == PLCBlockType.VAT && SelectPart == SelectPartType.VariableTable) { lstProjectFolder.Items.Add(step7ProjectBlockInfo); } if (step7ProjectBlockInfo.BlockType == PLCBlockType.DB && SelectPart == SelectPartType.DataBlock) { lstProjectFolder.Items.Add(step7ProjectBlockInfo); } if (step7ProjectBlockInfo.BlockType == PLCBlockType.UDT && SelectPart == SelectPartType.DataType) { lstProjectFolder.Items.Add(step7ProjectBlockInfo); } if ((step7ProjectBlockInfo.BlockType == PLCBlockType.FB || step7ProjectBlockInfo.BlockType == PLCBlockType.FC) && SelectPart == SelectPartType.FunctionBlock) { lstProjectFolder.Items.Add(step7ProjectBlockInfo); } } } } } else if (treeStep7Project.SelectedNode is DBValueTreeNode) { //Maybe a DBTreeNode is not yet Expanded, then it need to be filled after select! if (treeStep7Project.SelectedNode is DBTreeNode) { AddDBValueNodes((DBTreeNode)treeStep7Project.SelectedNode); } DBValueTreeNode tmp = (DBValueTreeNode)treeStep7Project.SelectedNode; foreach (S7DataRow s7DataRow in tmp.s7datarow.Children) { if (s7DataRow.DataType != S7DataRowType.STRUCT && s7DataRow.DataType != S7DataRowType.UDT) { lstProjectFolder.Items.Add(new DBRowValue() { myRow = s7DataRow }); } } } }
public virtual string GetSourceBlock(bool useSymbols = false) { if (ParentFolder is BlocksOfflineFolder) { BlocksOfflineFolder blkFld = (BlocksOfflineFolder)ParentFolder; return(blkFld.GetSourceBlock(this, useSymbols)); } if (ParentFolder is SourceFolder) { SourceFolder blkFld = (SourceFolder)ParentFolder; return(blkFld.GetSource((S7ProjectSourceInfo)this)); } return(null); }
public void TestDB4() { var txt = "\r\n STRUCT \t\r\n X_KOORDINATE : ARRAY [0 .. 67, 0 .. 16, 1 .. 2 ] OF //X, Y, Z (Z1 = links, Z2 = rechts)\r\n INT ;\t\r\n END_STRUCT ;\t"; var par1 = new List <string>(); var fld = new BlocksOfflineFolder(); var blk = new S7Block(); var test = DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.Parameter.GetInterfaceOrDBFromStep7ProjectString(txt, ref par1, PLCBlockType .DB, false, fld, blk); var rw = test.Children[0] as S7DataRow; var callStr = rw.GetCallingString(); }
public void TestDB2() { var txt = "\r\n STRUCT \t\r\n Fachkoordinate : ARRAY [0 .. 67, 1 .. 2 ] OF //X, Z (1 = links, 2 = rechts)\r\n STRUCT \t\r\n X : DINT ;\t\r\n END_STRUCT ;\t\r\n END_STRUCT ;\t"; var par1 = new List <string>(); var fld = new BlocksOfflineFolder(); var blk = new S7Block(); var test = DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.Parameter.GetInterfaceOrDBFromStep7ProjectString(txt, ref par1, PLCBlockType .DB, false, fld, blk); Assert.AreEqual(test.Children[0].Name, "Fachkoordinate"); Assert.AreEqual(((S7DataRow)test.Children[0]).ArrayStart[0], 0); Assert.AreEqual(((S7DataRow)test.Children[0]).ArrayStart[1], 1); Assert.AreEqual(((S7DataRow)test.Children[0]).ArrayStop[0], 67); Assert.AreEqual(((S7DataRow)test.Children[0]).ArrayStop[1], 2); Assert.AreEqual(((S7DataRow)test.Children[0]).ByteLength, 544); }
public void TestDB3() { var txt = "\r\n STRUCT \t\r\n X_KOORDINATE : ARRAY [0 .. 67, 0 .. 16, 1 .. 2 ] OF //X, Y, Z (Z1 = links, Z2 = rechts)\r\n INT ;\t\r\n END_STRUCT ;\t"; var par1 = new List <string>(); var fld = new BlocksOfflineFolder(); var blk = new S7Block(); var test = DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.Parameter.GetInterfaceOrDBFromStep7ProjectString(txt, ref par1, PLCBlockType .DB, false, fld, blk); Assert.AreEqual(test.Children[0].Name, "X_KOORDINATE"); Assert.AreEqual(test.Children[0].ArrayStart[0], 0); Assert.AreEqual(test.Children[0].ArrayStart[1], 0); Assert.AreEqual(test.Children[0].ArrayStart[2], 1); Assert.AreEqual(test.Children[0].ArrayStop[0], 67); Assert.AreEqual(test.Children[0].ArrayStop[1], 16); Assert.AreEqual(test.Children[0].ArrayStop[2], 2); Assert.AreEqual(test.Children[0].ByteLength, 4624); }
public void TestDB1() { var txt = "\r\n STRUCT \t\r\n DB_VAR : INT := 1;\t//vorläufige Platzhaltervariable\r\n aa : ARRAY [1 .. 8 ] OF BYTE ;\t\r\n bb : INT ;\t\r\n aa1 : INT ;\t\r\n END_STRUCT ;\t"; var par1 = new List <string>(); var fld = new BlocksOfflineFolder(); var blk = new S7Block(); var test = DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.Parameter.GetInterfaceOrDBFromStep7ProjectString(txt, ref par1, PLCBlockType .DB, false, fld, blk); Assert.AreEqual(test.Children[0].Name, "DB_VAR"); Assert.AreEqual(test.Children[1].Name, "aa"); Assert.AreEqual(test.Children[2].Name, "bb"); Assert.AreEqual(test.Children[3].Name, "aa1"); Assert.AreEqual(((S7DataRow)test.Children[0]).BlockAddress.ByteAddress, 0); Assert.AreEqual(((S7DataRow)test.Children[1]).BlockAddress.ByteAddress, 2); Assert.AreEqual(((S7DataRow)test.Children[2]).BlockAddress.ByteAddress, 10); Assert.AreEqual(((S7DataRow)test.Children[3]).BlockAddress.ByteAddress, 12); }
private void AddNodes(TreeNode nd, List <ProjectFolder> lst) { foreach (var subitem in lst) { myTreeNode tmpNode = new myTreeNode(); tmpNode.Text = subitem.Name; tmpNode.myObject = subitem; tmpNode.ImageIndex = 0; //nd.ImageKey //Set the Image for the Folders... if (subitem.GetType() == typeof(StationConfigurationFolder)) { if (((StationConfigurationFolder)subitem).StationType == PLCType.Simatic300) { tmpNode.ImageIndex = 4; } else if (((StationConfigurationFolder)subitem).StationType == PLCType.Simatic400 || ((StationConfigurationFolder)subitem).StationType == PLCType.Simatic400H) { tmpNode.ImageIndex = 5; } } else if (subitem.GetType() == typeof(CPUFolder)) { if (((CPUFolder)subitem).CpuType == PLCType.Simatic300) { tmpNode.ImageIndex = 2; } else if (((CPUFolder)subitem).CpuType == PLCType.Simatic400 || ((CPUFolder)subitem).CpuType == PLCType.Simatic400H) { tmpNode.ImageIndex = 3; } } nd.Nodes.Add(tmpNode); if (subitem.SubItems != null) { AddNodes(tmpNode, subitem.SubItems); } if (subitem is BlocksOfflineFolder && this.SelectPart == SelectPartType.Tag) { BlocksOfflineFolder blkFld = (BlocksOfflineFolder)subitem; foreach (ProjectPlcBlockInfo projectBlockInfo in blkFld.readPlcBlocksList()) { if (projectBlockInfo.BlockType == PLCBlockType.DB || projectBlockInfo.BlockType == PLCBlockType.S5_DB || projectBlockInfo.BlockType == PLCBlockType.S5_DX) { string nm = projectBlockInfo.BlockName; if (projectBlockInfo.SymbolTabelEntry != null) { nm += " (" + projectBlockInfo.SymbolTabelEntry.Symbol + ")"; } DBTreeNode trnd = new DBTreeNode() { Text = nm, PLCBlockInfo = projectBlockInfo }; trnd.Nodes.Add(new FakeNode()); tmpNode.Nodes.Add(trnd); } } } } }
//In this Class a UC is converted to a Call and also backwards... public static void ConvertUCToCall(S7FunctionBlock myFct, S7ProgrammFolder myFld, BlocksOfflineFolder myblkFld, S7ConvertingOptions myOpt, byte[] addInfoFromBlock) { if (myOpt.GenerateCallsfromUCs) { int inBld = 0; //1=nach BLD 1 S7FunctionBlockRow newRow = null; Dictionary <string, string> Parameters = new Dictionary <string, string>(); List <FunctionBlockRow> retVal = new List <FunctionBlockRow>(); List <FunctionBlockRow> tempList = new List <FunctionBlockRow>(); string registerDi = "DI"; string registerDb = ""; string registerAkku1 = ""; string registerAkku2 = ""; string registerAR1 = ""; string registerAR2 = ""; string diName = ""; string akPar = ""; string db = ""; string label = ""; string akku = ""; bool afterCall = false; bool multiInstance = false; int multiInstanceOffset = 0; Pointer ar2Addr = new Pointer(0, 0); S7FunctionBlockRow callRow = null; for (int n = 0; n < myFct.AWLCode.Count; n++) { S7FunctionBlockRow row = (S7FunctionBlockRow)myFct.AWLCode[n]; if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "1" || row.Parameter == "7" || row.Parameter == "3" || row.Parameter == "16" || row.Parameter == "14") && inBld == 0) { retVal.AddRange(tempList); tempList.Clear(); Parameters.Clear(); db = ""; label = row.Label; inBld = Convert.ToInt32(row.Parameter); newRow = null; afterCall = false; callRow = null; diName = ""; multiInstance = false; multiInstanceOffset = 0; ar2Addr = new Pointer(0, 0); tempList.Add(row); } else if (inBld == 1 || inBld == 7) { #region FC Aufruf tempList.Add(row); if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Mnemonic.opBLD[(int)myOpt.Mnemonic]) { //Do nothing, but this line needs to be there! } else if (row.Command == Mnemonic.opU[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opUN[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opX[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opXN[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opL[(int)myOpt.Mnemonic]) { akPar = row.Parameter; } else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic]) { db = row.Parameter + "."; } else if (row.Command == Mnemonic.opCLR[(int)myOpt.Mnemonic]) { akPar = "FALSE"; } else if (row.Command == Mnemonic.opSET[(int)myOpt.Mnemonic]) { akPar = "TRUE"; } else if (row.Command == Mnemonic.opTAR2[(int)myOpt.Mnemonic]) { //look what we need to do here!!! } else if (row.Command == Mnemonic.opPAR2[(int)myOpt.Mnemonic]) { //look what we need to do here!!! } else if (row.Command == Mnemonic.opLAR2[(int)myOpt.Mnemonic]) { //look what we need to do here!!! } else if (row.Command == Mnemonic.opLAR1[(int)myOpt.Mnemonic]) { //look what we need to do here!!! } else if ((row.Command == "=") && akPar != "") { if (afterCall == false) { string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key, db + akPar); } } else { string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key, db + row.Parameter); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar != "") { if (afterCall == false) { string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); //Fix for replace db accesses with symbols if (myOpt.ReplaceDBAccessesWithSymbolNames && db != "") { string dbnr = db.Substring(0, db.Length - 1); string dbSymbol = Helper.TryGetSymbolFromOperand(myblkFld, dbnr); db = (dbSymbol != null ? "\"" + dbSymbol + "\"" : dbnr) + "."; akPar = Helper.TryGetStructuredName(myblkFld, dbnr, akPar); } //end fix if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key + ".0", db + akPar); } } else { string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey("P#V " + key)) { Parameters.Add("P#V " + key, db + row.Parameter); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar == "") { //look what we need to do here!!! } else if (row.Command == Mnemonic.opUC[(int)myOpt.Mnemonic]) { //Commands after a Call --> Out-Para callRow = row; afterCall = true; } else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "2" || row.Parameter == "8")) { //Block Interface auslesen (von FC oder vom Programm) S7DataRow para = myblkFld.GetInterface(callRow.Parameter); newRow = new S7FunctionBlockRow(); newRow.Command = Mnemonic.opCALL[(int)myOpt.Mnemonic]; newRow.Parent = callRow.Parent; newRow.Parameter = callRow.Parameter; newRow.CallParameter = new List <S7FunctionBlockParameter>(); for (int i = 0; i < callRow.ExtParameter.Count; i++) { string s = callRow.ExtParameter[i]; string parnm = ""; S7DataRow akRow = Parameter.GetFunctionParameterFromNumber(para, i); if (akRow != null) { parnm = akRow.Name + ""; } else { parnm = "$$undef"; } S7FunctionBlockParameter newPar = new S7FunctionBlockParameter(newRow); newPar.Name = parnm; if (akRow != null) { newPar.ParameterDataType = akRow.DataType; if (akRow.Parent.Name == "OUT") { newPar.ParameterType = S7FunctionBlockParameterDirection.OUT; } else if (akRow.Parent.Name == "IN_OUT") { newPar.ParameterType = S7FunctionBlockParameterDirection.IN_OUT; } else { newPar.ParameterType = S7FunctionBlockParameterDirection.IN; } } if (akRow != null) { int posL = s.IndexOf(' '); int ak_address = 0; if (posL >= 0) { ak_address = Convert.ToInt32(s.Substring(posL + 1).Split('.')[0]); } else { ak_address = Convert.ToInt32(s.Substring(2).Split('.')[0]) * 8 + Convert.ToInt32(s.Substring(2).Split('.')[1]); } int lokaldata_address = -1; if (s.Substring(0, 3) == "P#V") { lokaldata_address = Convert.ToInt32(s.Substring(4).Split('.')[0]); } if (akRow.DataType == S7DataRowType.STRING || akRow.DataType == S7DataRowType.DATE_AND_TIME || akRow.DataType == S7DataRowType.STRUCT || akRow.DataType == S7DataRowType.UDT || akRow.DataType == S7DataRowType.POINTER || akRow.IsArray) { string p1 = ""; string p2 = ""; Parameters.TryGetValue("P#V " + (lokaldata_address + 0).ToString() + ".0", out p1); Parameters.TryGetValue("P#V " + (lokaldata_address + 2).ToString() + ".0", out p2); string tmp = ""; if (p1 != "" && p1 != "0") { tmp += "P#DB" + p1 + "." + (p2 == null ? "0" : p2.Substring(2)); } else { tmp += p2; } newPar.Value = tmp; newRow.CallParameter.Add(newPar); } else if (akRow.DataType == S7DataRowType.ANY) { string tmp = s; if (Parameters.ContainsKey("P#V " + (lokaldata_address + 0).ToString() + ".0") && Parameters.ContainsKey("P#V " + (lokaldata_address + 2).ToString() + ".0") && Parameters.ContainsKey("P#V " + (lokaldata_address + 4).ToString() + ".0") && Parameters.ContainsKey("P#V " + (lokaldata_address + 6).ToString() + ".0")) { string p1 = Parameters["P#V " + (lokaldata_address + 0).ToString() + ".0"]; string p2 = Parameters["P#V " + (lokaldata_address + 2).ToString() + ".0"]; string p3 = Parameters["P#V " + (lokaldata_address + 4).ToString() + ".0"]; string p4 = Parameters["P#V " + (lokaldata_address + 6).ToString() + ".0"]; //Fix for wrong construction of any pointers var anyPtr = new S7AnyPointer(p1, p2, p3, p4); if (myOpt.ReplaceDBAccessesWithSymbolNames) { //TODO: make the any pointer symbolic. tmp = "" + anyPtr.ToString(); } else { tmp = anyPtr.ToString(); } //end fix //tmp = "P#"; //if (p3 != "0") // tmp += "DB" + p3 + "."; //tmp += p4.Substring(2); //tmp += " BYTE "; //Todo Parse Byte 1 if the Type is Byte! //tmp += p2; } newPar.Value = tmp; newRow.CallParameter.Add(newPar); } else { if (Parameters.ContainsKey(s)) { string par = Parameters[s]; if (akRow.DataType == S7DataRowType.S5TIME && par[0] >= '0' && par[0] <= '9') { newPar.Value = Helper.GetS5Time( BitConverter.GetBytes(Convert.ToInt32(par))[1], BitConverter.GetBytes(Convert.ToInt32(par))[0]); } else if (akRow.DataType == S7DataRowType.TIME && par[0] >= '0' && par[0] <= '9') { newPar.Value = Helper.GetDTime(BitConverter.GetBytes(Convert.ToInt32(par)), 0); } else if (akRow.DataType == S7DataRowType.CHAR && par[0] == 'B') { newPar.Value = (char)Int32.Parse(par.Substring(5), System.Globalization.NumberStyles.AllowHexSpecifier) + "'"; } else if (akRow.DataType == S7DataRowType.REAL) { var bt = new byte[4]; libnodave.putS32at(bt, 0, Int32.Parse(par.Substring(2))); var real = libnodave.getFloatfrom(bt, 0); newPar.Value = real.ToString("e6", CultureInfo.InvariantCulture); } else { newPar.Value = Parameters[s]; } } else { if (akRow.DataType == S7DataRowType.BOOL) { newPar.Value = s.Substring(2).Replace('V', 'L'); } else if (akRow.DataType == S7DataRowType.BLOCK_DB) { newPar.Value = "DB" + ak_address.ToString(); } else if (akRow.DataType == S7DataRowType.BLOCK_FB) { newPar.Value = "FB" + ak_address.ToString(); } else if (akRow.DataType == S7DataRowType.BLOCK_FC) { newPar.Value = "FC" + ak_address.ToString(); } else if (akRow.DataType == S7DataRowType.BLOCK_SDB) { newPar.Value = "SDB" + ak_address.ToString(); } else if (akRow.DataType == S7DataRowType.TIMER) { newPar.Value = Mnemonic.adT[(int)myOpt.Mnemonic] + ak_address.ToString(); } else if (akRow.DataType == S7DataRowType.COUNTER) { newPar.Value = Mnemonic.adZ[(int)myOpt.Mnemonic] + ak_address.ToString(); } else { string ber = ""; if (s.Substring(0, 5) == "P#DBX") { ber = "DB"; } else if (s.Substring(0, 5) == "P#DIX") { ber = "DI"; } else { ber = s.Substring(2, 1); } if (akRow.ByteLength == 1) { ber += "B"; } else if (akRow.ByteLength == 2) { ber += "W"; } else if (akRow.ByteLength == 4) { ber += "D"; } var access = ber.Replace('V', 'L') + ak_address; //fix for temporary area not replaced with symbolnames if (myOpt.ReplaceLokalDataAddressesWithSymbolNames) { var tempSymbol = S7DataRow.GetDataRowWithAddress(myFct.Parameter, new ByteBitAddress(ak_address, 0)); if (tempSymbol != null) { access = "#" + tempSymbol.StructuredName.Replace("TEMP.", ""); } } newPar.Value = access; } } newRow.CallParameter.Add(newPar); } } } newRow.CombinedCommands = tempList; newRow.Label = label; int sz = 0; foreach (var functionBlockRow in newRow.CombinedCommands) { sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize; } byte[] mcges = new byte[sz]; sz = 0; foreach (var functionBlockRow in newRow.CombinedCommands) { Array.Copy(((S7FunctionBlockRow)functionBlockRow).MC7, 0, mcges, sz, ((S7FunctionBlockRow)functionBlockRow).ByteSize); sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize; } newRow.MC7 = mcges; retVal.Add(newRow); Parameters.Clear(); tempList = new List <FunctionBlockRow>(); inBld = 0; newRow = null; } else { retVal.AddRange(tempList); tempList.Clear(); inBld = 0; } #endregion } else if (inBld == 3 || inBld == 16 || inBld == 14) { #region FB Aufruf tempList.Add(row); if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Mnemonic.opBLD[(int)myOpt.Mnemonic]) { //Do nothing, but this line needs to be there! } else if (row.Command == Mnemonic.opTDB[(int)myOpt.Mnemonic]) { //Do nothing, but this line needs to be there! } else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && row.Parameter == "11") { //whatever this BLD 11 in the FB Calls means... } else if (row.Command == Mnemonic.opTAR2[(int)myOpt.Mnemonic]) { if (ar2Addr.MemoryArea == MemoryArea.None) { akPar = "P#DIX " + ar2Addr.ToString(); } else { akPar = ar2Addr.ToString(myOpt.Mnemonic); } } else if (row.Command == Mnemonic.opLAR2[(int)myOpt.Mnemonic]) { if (row.Parameter.StartsWith("P#")) { ar2Addr = new Pointer(row.Parameter.Substring(2)); } else { ar2Addr.ByteAddress = 0; ar2Addr.BitAddress = 0; } } else if (row.Command == Mnemonic.opPAR2[(int)myOpt.Mnemonic]) { ar2Addr += new Pointer(row.Parameter); } else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic] && (tempList.Count == 4)) { diName = row.Parameter; } else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic] && row.Parameter.Contains("[") && (tempList.Count == 6)) { multiInstance = true; diName = ""; } else if (row.Command == Mnemonic.opU[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opUN[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opX[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opXN[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opL[(int)myOpt.Mnemonic]) { akPar = db + row.Parameter; db = ""; } else if (row.Command == Mnemonic.opAUF[(int)myOpt.Mnemonic]) { db = row.Parameter + "."; } else if (row.Command == "CLR") { akPar = "FALSE"; } else if (row.Command == "SET") { akPar = "TRUE"; } else if ((row.Command == "=") && akPar != "") { if (afterCall == false) { if (!Parameters.ContainsKey(row.Parameter)) { Parameters.Add(row.Parameter, akPar); } } else { if (!Parameters.ContainsKey(akPar)) { Parameters.Add(akPar, row.Parameter); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar != "") { if (afterCall == false) { if (!Parameters.ContainsKey(row.Parameter)) { Parameters.Add(row.Parameter, akPar); } } else { if (!Parameters.ContainsKey(akPar)) { Parameters.Add(akPar, row.Parameter); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic]) { if (afterCall == false) { if (!Parameters.ContainsKey(row.Parameter)) { Parameters.Add(row.Parameter, ""); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opUC[(int)myOpt.Mnemonic]) { multiInstanceOffset = 0; for (int j = tempList.Count - 2; j > -1; j--) { if (tempList[j].Command == Mnemonic.opPAR2[(int)myOpt.Mnemonic]) { multiInstanceOffset += (int)double.Parse((((S7FunctionBlockRow)tempList[j]).Parameter.Substring(2)), CultureInfo.InvariantCulture); } break; } //Commands after a Call --> Out-Para callRow = row; afterCall = true; } else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "4" || row.Parameter == "17" || row.Parameter == "15")) { //Block Interface auslesen (von FC oder vom Programm) S7DataRow para = myblkFld.GetInterface(callRow.Parameter); newRow = new S7FunctionBlockRow(); newRow.Parent = callRow.Parent; newRow.Command = Mnemonic.opCALL[(int)myOpt.Mnemonic]; newRow.Parameter = callRow.Parameter; if (diName.Length > 2 && !diName.StartsWith("#")) { newRow.DiName = "DI" + int.Parse(diName.Substring(2)); } else if (diName.StartsWith("#")) { newRow.DiName = diName; } newRow.CallParameter = new List <S7FunctionBlockParameter>(); if (para != null) { var allPar = para.Children.Where(itm => itm.Name == "IN" || itm.Name == "IN_OUT" || itm.Name == "OUT"); foreach (var s7DataRowMain in allPar) { foreach (var s7DataRow in s7DataRowMain.Children) { S7FunctionBlockParameter newPar = new S7FunctionBlockParameter(newRow); newPar.Name = s7DataRow.Name; string par = null; if (!multiInstance) { Parameters.TryGetValue(((S7DataRow)s7DataRow).BlockAddressInDbFormat.Replace("DB", "DI"), out par); } else if (((S7DataRow)s7DataRow).DataType == S7DataRowType.ANY) { var anySizeAddr = ((S7DataRow)s7DataRow).BlockAddress.ByteAddress + multiInstanceOffset + 2; var anyPosAddr = ((S7DataRow)s7DataRow).BlockAddress.ByteAddress + multiInstanceOffset + 6; string anySize = ""; string anyPos = ""; Parameters.TryGetValue("DIW[AR2,P#" + anySizeAddr + ".0]", out anySize); Parameters.TryGetValue("DID[AR2,P#" + anyPosAddr + ".0]", out anyPos); par = anyPos + " BYTE " + anySize; } else { var addr = ((S7DataRow)s7DataRow).BlockAddressInDbFormat; if (!string.IsNullOrEmpty(addr)) { var addrTp = addr.Substring(0, 3).Replace("DB", "DI"); double bytepos = double.Parse(addr.Substring(3), CultureInfo.InvariantCulture) + multiInstanceOffset; Parameters.TryGetValue(addrTp + "[AR2,P#" + bytepos.ToString("0.0", CultureInfo.InvariantCulture) + "]", out par); } } if (par != null && par.Contains("[AR2")) { newPar.Value = par; var addr = par.Substring(10); addr = addr.Substring(0, addr.Length - 1); var pRow = S7DataRow.GetDataRowWithAddress(myFct.Parameter.Children.Where(itm => itm.Name != "TEMP").Cast <S7DataRow>(), new ByteBitAddress(addr)); if (pRow != null) { newPar.Value = ((S7DataRow)pRow).StructuredName.Substring(((S7DataRow)pRow).StructuredName.IndexOf('.') + 1); } } else { switch (((S7DataRow)s7DataRow).DataType) { case S7DataRowType.BLOCK_DB: newPar.Value = "DB" + par; break; case S7DataRowType.BLOCK_FC: newPar.Value = "FC" + par; break; case S7DataRowType.BLOCK_FB: newPar.Value = "FB" + par; break; case S7DataRowType.TIMER: newPar.Value = Mnemonic.adT[(int)myOpt.Mnemonic] + par.ToString(); break; case S7DataRowType.COUNTER: newPar.Value = Mnemonic.adZ[(int)myOpt.Mnemonic] + par.ToString(); break; case S7DataRowType.TIME: if (par != null && par.StartsWith("L#")) { var arr = BitConverter.GetBytes(Convert.ToInt32(par.Substring(2))); Array.Reverse(arr); newPar.Value = Helper.GetDTime(arr, 0); } else { newPar.Value = par; } break; default: newPar.Value = par; break; } } newRow.CallParameter.Add(newPar); } } } newRow.CombinedCommands = tempList; newRow.Label = label; int sz = 0; foreach (var functionBlockRow in newRow.CombinedCommands) { sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize; } byte[] mcges = new byte[sz]; sz = 0; foreach (var functionBlockRow in newRow.CombinedCommands) { Array.Copy(((S7FunctionBlockRow)functionBlockRow).MC7, 0, mcges, sz, ((S7FunctionBlockRow)functionBlockRow).ByteSize); sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize; } newRow.MC7 = mcges; retVal.Add(newRow); Parameters.Clear(); tempList = new List <FunctionBlockRow>(); inBld = 0; newRow = null; } else { retVal.AddRange(tempList); tempList.Clear(); inBld = 0; } #endregion } else { retVal.Add(row); } } myFct.AWLCode = retVal; } }
public string GetSourceBlock() { BlocksOfflineFolder blkFld = (BlocksOfflineFolder)ParentFolder; return(blkFld.GetSourceBlock(this)); }
internal static S7DataRow GetInterfaceOrDBFromStep7ProjectString(string txt, ref List <String> ParaList, PLCBlockType blkTP, bool isInstanceDB, BlocksOfflineFolder myFld, S7Block myBlk, byte[] actualValues = null) { S7DataRow parameterRoot = new S7DataRow("ROOTNODE", S7DataRowType.STRUCT, myBlk); S7DataRow parameterRootWithoutTemp = new S7DataRow("ROOTNODE", S7DataRowType.STRUCT, myBlk); if (myBlk is S7FunctionBlock) { (myBlk as S7FunctionBlock).ParameterWithoutTemp = parameterRootWithoutTemp; } S7DataRow parameterIN = new S7DataRow("IN", S7DataRowType.STRUCT, myBlk); S7DataRow parameterOUT = new S7DataRow("OUT", S7DataRowType.STRUCT, myBlk); S7DataRow parameterINOUT = new S7DataRow("IN_OUT", S7DataRowType.STRUCT, myBlk); S7DataRow parameterSTAT = new S7DataRow("STATIC", S7DataRowType.STRUCT, myBlk); S7DataRow parameterTEMP = new S7DataRow("TEMP", S7DataRowType.STRUCT, myBlk); //S7DataRow parameterRETVAL = new S7DataRow("RET_VAL", S7DataRowType.STRUCT, myBlk); S7DataRow akDataRow = parameterRoot; parameterIN.isRootBlock = true; parameterOUT.isRootBlock = true; parameterINOUT.isRootBlock = true; parameterINOUT.isInOut = true; parameterSTAT.isRootBlock = true; parameterTEMP.isRootBlock = true; bool tempAdded = false; int Valpos = 0; if (txt == null) { if (blkTP != PLCBlockType.DB) { parameterRoot.Add(parameterTEMP); } return(parameterRoot); } //Todo: read the complete DB from mc5 code first, Read the containing UDTs, compare the UDTs with the Structs, if the UDTs and Structs are not Equal, marke the PLCDataRow as TimeStampConflict string[] rows = txt.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); S7DataRow lastrow = null; Dictionary <string, S7Block> blkHelpers = new Dictionary <string, S7Block>(); for (int n = 0; n < rows.Length; n++) // (string row in rows) { string rowTr = rows[n].Replace("\0", "").Trim(); int poscm = rowTr.IndexOf("\t//"); if (poscm <= 0) { poscm = rowTr.Length; } string switchrow = rowTr.Substring(0, poscm); string commnew = ""; if (poscm != rowTr.Length) { commnew = rowTr.Substring(poscm + 1); } if (rowTr.StartsWith("//")) { if (lastrow != null) { lastrow.Comment += rowTr; } else { if (commnew != null) { if (string.IsNullOrEmpty(akDataRow.Comment)) { akDataRow.Comment += rowTr; } else { akDataRow.Comment += "\r\n" + rowTr; } } } } else { switch (switchrow.Trim()) { case "VAR_INPUT": akDataRow = parameterIN; akDataRow.Comment = commnew; parameterRoot.Add(parameterIN); parameterRootWithoutTemp.Add(parameterIN); break; case "VAR_OUTPUT": akDataRow = parameterOUT; akDataRow.Comment = commnew; parameterRoot.Add(parameterOUT); parameterRootWithoutTemp.Add(parameterOUT); break; case "VAR_IN_OUT": akDataRow = parameterINOUT; akDataRow.Comment = commnew; parameterRoot.Add(parameterINOUT); parameterRootWithoutTemp.Add(parameterINOUT); break; case "VAR_TEMP": akDataRow = parameterTEMP; if (blkTP != PLCBlockType.DB) { tempAdded = true; parameterRoot.Add(parameterTEMP); } break; case "VAR": //Static Data on a FB akDataRow = parameterSTAT; parameterRoot.Add(parameterSTAT); parameterRootWithoutTemp.Add(parameterSTAT); break; case "END_STRUCT;": case "END_STRUCT ;": akDataRow = ((S7DataRow)akDataRow.Parent); break; case "STRUCT": case "END_VAR": case "": if (commnew != null) { if (string.IsNullOrEmpty(akDataRow.Comment)) { akDataRow.Comment += commnew; } else { akDataRow.Comment += "\r\n" + commnew; } } break; default: char oldChar = ' '; List <Step7Attribute> Step7Attributes = new List <Step7Attribute>(); string tmpName = ""; string tmpAttributeName = ""; string tmpAttributeValue = ""; string tmpType = ""; string tmpComment = ""; string tmpValue = ""; int parseZustand = 0; //0=ParName, 1=AttributeName, 6=AfterAttributeName, 2=AttributeValue, 3=Type, 4=Value, 7=InnerValue (without '), 5=Comment var p1 = rows[n].IndexOf(" OF "); int p2 = 0, p3 = 0; if (p1 > 0) { p2 = rows[n].IndexOf(";", p1); p3 = rows[n].IndexOf("//", p1); } //if (rows[n].Contains("ARRAY") && rows[n].Contains(" OF ") && !rows[n].Contains("\t\r")) // !rows[n].Contains("\t") if (rows[n].Contains("ARRAY") && rows[n].Contains(" OF ") && (!(p2 > p1 && (p2 < p3 || p3 < 0)) && !rows[n].Contains("\t\r"))) { if (rows.Length > n + 1) { if (rowTr.Contains("//")) { int pos = rowTr.IndexOf("//"); rowTr = rowTr.Substring(0, pos) + " " + rows[n + 1].Trim() + rowTr.Substring(pos); } else if (rowTr.Contains("OF STRUCT")) { } else if (rowTr[rowTr.Length - 1] != ';') { rowTr += " " + rows[n + 1].Trim(); } n++; } } for (int j = 0; j < rowTr.Length; j++) { char tmpChar = rowTr[j]; if (parseZustand == 0 && tmpChar == '{') { parseZustand = 1; } else if (parseZustand == 0 && tmpChar != ' ' && tmpChar != ':') { tmpName += tmpChar; } else if (parseZustand == 6 && tmpChar == '\'') { parseZustand = 2; } else if (parseZustand == 1 && tmpChar == ':' && rowTr[j + 1] == '=') { parseZustand = 6; j++; } else if (parseZustand == 1 && tmpChar != ' ' && tmpChar != ':' && tmpChar != '=' && tmpChar != '}' && tmpChar != '\'' && tmpChar != ';') { tmpAttributeName += tmpChar; } else if (parseZustand == 1 && tmpChar == '}') { parseZustand = 0; } else if (parseZustand == 0 && tmpChar == ':') { parseZustand = 3; } else if (parseZustand == 2 && tmpChar == '$') { tmpAttributeValue += rowTr[j + 1]; j++; } else if (parseZustand == 2 && tmpChar == '\'') { parseZustand = 1; Step7Attributes.Add(new Step7Attribute(tmpAttributeName, tmpAttributeValue)); tmpAttributeName = ""; tmpAttributeValue = ""; } else if (parseZustand == 2) { tmpAttributeValue += tmpChar; } //else if (parseZustand == 3 && tmpChar == ':') // parseZustand = 2; else if (parseZustand == 3 && tmpChar == ':' && rowTr[j + 1] == '=') { parseZustand = 4; j++; } else if ((parseZustand == 3 || parseZustand == 4) && tmpChar == '/' && rowTr[j + 1] == '/') { parseZustand = 5; j++; } else if (parseZustand == 4 && tmpChar == '\'') { tmpValue += tmpChar; parseZustand = 7; } else if (parseZustand == 7 && tmpChar == '$') { tmpValue += rowTr[j + 1]; j++; } else if (parseZustand == 7 && tmpChar == '\'') { tmpValue += tmpChar; parseZustand = 4; } else if (parseZustand == 3 && tmpChar != ';') { tmpType += tmpChar; } else if (parseZustand == 4 && tmpChar != ';' && tmpChar != ' ') { tmpValue += tmpChar; } else if (parseZustand == 7) { tmpValue += tmpChar; } else if (parseZustand == 5) { tmpComment += tmpChar; } } tmpType = tmpType.Trim().ToUpper(); S7DataRow addRW = new S7DataRow(tmpName, S7DataRowType.UNKNOWN, myBlk); lastrow = addRW; if (tmpType.Replace(" ", "").Contains("ARRAY[")) { List <int> arrayStart = new List <int>(); List <int> arrayStop = new List <int>(); int pos1 = tmpType.IndexOf("["); int pos2 = tmpType.IndexOf("]", pos1); string[] arrays = tmpType.Substring(pos1 + 1, pos2 - pos1 - 2).Split(','); foreach (string array in arrays) { string[] akar = array.Split(new string[] { ".." }, StringSplitOptions.RemoveEmptyEntries); arrayStart.Add(Convert.ToInt32(akar[0].Trim())); arrayStop.Add(Convert.ToInt32(akar[1].Trim())); } addRW.ArrayStart = arrayStart; addRW.ArrayStop = arrayStop; addRW.IsArray = true; tmpType = tmpType.Substring(pos2 + 5); } addRW.Comment = tmpComment.Replace("$'", "'").Replace("$$", "$"); if (Step7Attributes.Count > 0) { addRW.Attributes = Step7Attributes; } int akRowTypeNumber = 0; if (tmpType.Contains("SFB")) { addRW.DataType = S7DataRowType.SFB; akRowTypeNumber = Convert.ToInt32(tmpType.Substring(4)); string blkDesc = "SFB" + akRowTypeNumber.ToString(); S7FunctionBlock tmpBlk; if (blkHelpers.ContainsKey(blkDesc)) { tmpBlk = (S7FunctionBlock)blkHelpers[blkDesc]; } else { tmpBlk = ((S7FunctionBlock)myFld.GetBlock(blkDesc)); blkHelpers.Add(blkDesc, tmpBlk); } if (tmpBlk != null && tmpBlk.Parameter != null && tmpBlk.Parameter.Children != null) { addRW.AddRange(tmpBlk.ParameterWithoutTemp.DeepCopy().Children.Cast <S7DataRow>()); } } else if (tmpType.Contains("UDT")) { addRW.DataType = S7DataRowType.UDT; akRowTypeNumber = Convert.ToInt32(tmpType.Substring(4)); string blkDesc = "UDT" + akRowTypeNumber.ToString(); S7DataBlock tmpBlk; if (blkHelpers.ContainsKey(blkDesc)) { tmpBlk = (S7DataBlock)blkHelpers[blkDesc]; } else { tmpBlk = ((S7DataBlock)myFld.GetBlock(blkDesc)); blkHelpers.Add(blkDesc, tmpBlk); } if (tmpBlk != null && tmpBlk.Structure != null && tmpBlk.Structure.Children != null) { addRW.AddRange(((S7DataRow)tmpBlk.Structure).DeepCopy().Children.Cast <S7DataRow>()); } } else if (tmpType.Contains("BLOCK_FB")) { addRW.DataType = S7DataRowType.BLOCK_FB; //akRowTypeNumber = Convert.ToInt32(tmpType.Substring(3)); //PLCFunctionBlock tmpBlk = ((PLCFunctionBlock)myFld.GetBlock("FB" + akRowTypeNumber.ToString())); //if (tmpBlk != null && tmpBlk.Parameter != null && tmpBlk.Parameter.Children != null) // addRW.AddRange(tmpBlk.Parameter.Children); } else if (tmpType.Contains("FB")) { addRW.DataType = S7DataRowType.FB; akRowTypeNumber = Convert.ToInt32(tmpType.Substring(3)); string blkDesc = "FB" + akRowTypeNumber.ToString(); S7FunctionBlock tmpBlk; if (blkHelpers.ContainsKey(blkDesc)) { tmpBlk = (S7FunctionBlock)blkHelpers[blkDesc]; } else { tmpBlk = ((S7FunctionBlock)myFld.GetBlock(blkDesc)); blkHelpers.Add(blkDesc, tmpBlk); } if (tmpBlk != null && tmpBlk.Parameter != null && tmpBlk.Parameter.Children != null) { addRW.AddRange(tmpBlk.ParameterWithoutTemp.DeepCopy().Children.Cast <S7DataRow>()); } } else if (tmpType.Contains("STRING")) { addRW.DataType = S7DataRowType.STRING; int pos1 = tmpType.IndexOf("["); int pos2 = tmpType.IndexOf("]", pos1); addRW.StringSize = Convert.ToInt32(tmpType.Substring(pos1 + 1, pos2 - pos1 - 2)); } else { addRW.DataType = (S7DataRowType)Enum.Parse(typeof(S7DataRowType), tmpType.ToUpper()); } addRW.DataTypeBlockNumber = akRowTypeNumber; if (tmpValue != "") { //Todo: Startvalues bei arrays... //Mehrere Values... //TRUE,6(FALSE),TRUE,TRUE,7(FALSE) if (addRW.IsArray) { addRW.StartValue = tmpValue; } else { addRW.StartValue = Helper.StringValueToObject(tmpValue, addRW.DataType); } } else { if (!addRW.IsArray) { addRW.StartValue = Helper.DefaultValueForType(addRW.DataType); } } //if (actualValues != null) //{ // addRW.Value = GetVarTypeVal((byte)addRW.DataType, actualValues, ref Valpos); //} akDataRow.Add(addRW); ParaList.Add(tmpName); if (addRW.DataType == S7DataRowType.STRUCT) { akDataRow = addRW; } break; /* * Attributname kann nicht ' und } enthalten! * In Attribt Values * $$ zum ausmaskieren von $ * $' zum ausmaskieren von ' * * Beispielzeilen.... * // "ID { S7_co := 'agag'; S7_server1 := 'connection' }: INT ;\t// Connection ID 1..16" * // "LADDR { S7_co := 'agag'; S7_server1 := 'connection' }: WORD ;\t// Module address in hardware configuration" * // "RECV : ANY ;\t// Buffer for received data" * // "NDR : BOOL ;\t// Indicates whether new data were received" * // "aa { ff := '//ghghf}' }: BOOL ;" * // "bb : INT := 8888;" * // "P_1001 : ARRAY [0 .. 3 ] OF CHAR := '1', '0', '0', '1';" * // "aa : STRING [20 ] := 'deewedw';" * // "aa { dsfs := '' }: BOOL ;" * * //"res : ARRAY [1 .. 121 ] OF STRUCT" * // "P_AKL1 : ARRAY [0 .. 3 ] OF CHAR := 'A', 'K', 'L', '1';" */ } } } if (blkTP != PLCBlockType.DB && blkTP != PLCBlockType.UDT && tempAdded == false) { parameterRoot.Add(parameterTEMP); } if (actualValues != null) { int vPos = 0, bPos = 0; //FillActualValuesInDataBlock(parameterRoot, actualValues, ref vPos, ref bPos); } return(parameterRoot); }
override internal void LoadProject() { _projectLoaded = true; ProjectStructure = new Step7ProjectFolder() { Project = this }; CPUFolders = new List <CPUFolder>(); CPFolders = new List <CPFolder>(); S7ProgrammFolders = new List <S7ProgrammFolder>(); BlocksOfflineFolders = new List <BlocksOfflineFolder>(); ProjectStructure.Name = this.ToString(); //Get The Project Stations... if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hstatx" + _DirSeperator + "HOBJECT1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hstatx" + _DirSeperator + "HOBJECT1.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["OBJTYP"] == 1314969 || (int)row["OBJTYP"] == 1314970 || (int)row["OBJTYP"] == 1315650) { var x = new StationConfigurationFolder() { Project = this, Parent = ProjectStructure }; x.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { x.Name = "$$_" + x.Name; } x.ID = (int)row["ID"]; x.UnitID = (int)row["UNITID"]; switch ((int)row["OBJTYP"]) { case 1314969: x.StationType = PLCType.Simatic300; break; case 1314970: x.StationType = PLCType.Simatic400; break; case 1315650: x.StationType = PLCType.Simatic400H; break; } x.Parent = ProjectStructure; ProjectStructure.SubItems.Add(x); } } } } //Get The CP Folders if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7wb53ax" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7wb53ax" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (var y in ProjectStructure.SubItems) { if (y.GetType() == typeof(StationConfigurationFolder)) { var z = (StationConfigurationFolder)y; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["TUNITID"] == z.ID && ((int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314970 || (int)row["TUNITTYP"] == 1315650))//as in "Get The Project Stations" { var x = new CPFolder() { Project = this }; x.UnitID = Convert.ToInt32(row["TUNITID"]); x.TobjTyp = Convert.ToInt32(row["TOBJTYP"]); x.ID = Convert.ToInt32(row["SOBJID"]); x.Parent = z; z.SubItems.Add(x); CPFolders.Add(x); } } } } } } //Get The CPU 300 Folders if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (var y in ProjectStructure.SubItems) { if (y.GetType() == typeof(StationConfigurationFolder)) { var z = (StationConfigurationFolder)y; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["TUNITID"] == z.ID && (int)row["TOBJTYP"] == 1314972) //((int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314969)) { var x = new CPUFolder() { Project = this }; x.UnitID = Convert.ToInt32(row["TUNITID"]); x.TobjTyp = Convert.ToInt32(row["TOBJTYP"]); x.CpuType = z.StationType; x.ID = Convert.ToInt32(row["SOBJID"]); x.Parent = z; z.SubItems.Add(x); CPUFolders.Add(x); } } } } } } //Get The CPU 300 ET200s Folders if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hkcomx" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hkcomx" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (var y in ProjectStructure.SubItems) { if (y.GetType() == typeof(StationConfigurationFolder)) { var z = (StationConfigurationFolder)y; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["TUNITID"] == z.ID && (int)row["TOBJTYP"] == 1314972) //((int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314969)) { var x = new CPUFolder() { Project = this }; x.UnitID = Convert.ToInt32(row["TUNITID"]); x.TobjTyp = Convert.ToInt32(row["TOBJTYP"]); x.CpuType = z.StationType; x.ID = Convert.ToInt32(row["SOBJID"]); x.CpuType = PLCType.SimaticET200; x.Parent = z; z.SubItems.Add(x); CPUFolders.Add(x); } } } } } } //Get The CPU 400 Folders if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (var y in ProjectStructure.SubItems) { if (y.GetType() == typeof(StationConfigurationFolder)) { var z = (StationConfigurationFolder)y; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["TUNITID"] == z.ID && ((int)row["TOBJTYP"] == 1314972 || (int)row["TOBJTYP"] == 1315656 /* BackupCPU bei H Sys */)) //((int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314969 || (int)row["TUNITTYP"] == 1314969)) { var x = new CPUFolder() { Project = this }; x.UnitID = Convert.ToInt32(row["TUNITID"]); x.TobjTyp = Convert.ToInt32(row["TOBJTYP"]); x.CpuType = z.StationType; x.ID = Convert.ToInt32(row["SOBJID"]); x.Parent = z; z.SubItems.Add(x); CPUFolders.Add(x); } } } } } } /* * //Get The HW Folder for the Station... * if (ZipHelper.FileExists(_zipfile,ProjectFolder + "hOmSave7" + _DirSeperator + "s7hstatx" + _DirSeperator + "HRELATI1.DBF")) * { * var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hstatx" + _DirSeperator + "HRELATI1.DBF", _zipfile, _DirSeperator); * foreach (var y in Step7ProjectStructure.SubItems) * { * if (y.GetType() == typeof (StationConfigurationFolder)) * { * var z = (StationConfigurationFolder) y; * foreach (DataRow row in dbfTbl.Rows) * { * if (!(bool)row["DELETED_FLAG"] || _showDeleted) * { * if ((int)row["SOBJID"] == z.ID && (int)row["RELID"] == 1315838) * { * var x = new CPUFolder() {Project = this}; * x.UnitID = Convert.ToInt32(row["TUNITID"]); * x.TobjTyp = Convert.ToInt32(row["TOBJTYP"]); * x.CpuType = z.StationType; * bool add = true; * foreach (Step7ProjectFolder tmp in z.SubItems) * { * if (tmp.GetType() == typeof (CPUFolder) && ((CPUFolder) tmp).UnitID == x.UnitID) * add = false; * } * if (add) * { * x.Parent = z; * z.SubItems.Add(x); * CPUFolders.Add(x); * } * } * } * } * } * } * } */ //Get The CPU(ET200S)... if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hkcomx" + _DirSeperator + "HOBJECT1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hkcomx" + _DirSeperator + "HOBJECT1.DBF", _ziphelper, _DirSeperator); foreach (var y in CPUFolders) { foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["ID"] == y.ID && y.CpuType == PLCType.SimaticET200) //if ((int)row["UNITID"] == y.UnitID && y.CpuType == PLCType.SimaticET200) { y.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { y.Name = "$$_" + y.Name; } y.ID = (int)row["ID"]; } } } } } //Get The CPU(300)... if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HOBJECT1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HOBJECT1.DBF", _ziphelper, _DirSeperator); foreach (var y in CPUFolders) { foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["ID"] == y.ID && y.CpuType == PLCType.Simatic300) //if ((int)row["UNITID"] == y.UnitID && y.CpuType == PLCType.Simatic300) { y.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { y.Name = "$$_" + y.Name; } y.ID = (int)row["ID"]; } } } } } //Get The CPU(300) password if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HATTRME1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HATTRME1.DBF", _ziphelper, _DirSeperator); byte[] memoarray = null; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"]) { if ((int)row["ATTRIIDM"] == 111142) { if (row["MEMOARRAYM"] != DBNull.Value) { memoarray = (byte[])row["MEMOARRAYM"]; } if (memoarray.Length >= 12) { // memoarray[3] : level password (1-3) byte[] mempass = new byte[8]; for (int i = 0; i < 8; i++) { if (i < 2) { mempass[i] = (byte)(memoarray[i + 4] ^ 0xAA); } else { mempass[i] = (byte)(memoarray[i + 2] ^ memoarray[i + 4] ^ 0xAA); } } string res = ProjectEncoding.GetString(mempass); foreach (var y in CPUFolders) { if ((int)row["IDM"] == y.ID) { y.PasswdHard = res.Trim(); } } } } } } } //Get The CPU(400)... if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HOBJECT1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HOBJECT1.DBF", _ziphelper, _DirSeperator); foreach (var y in CPUFolders) { foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["ID"] == y.ID && (y.CpuType == PLCType.Simatic400 || y.CpuType == PLCType.Simatic400H)) //if ((int)row["UNITID"] == y.UnitID && (y.CpuType == PLCType.Simatic400 || y.CpuType == PLCType.Simatic400H) ) { y.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { y.Name = "$$_" + y.Name; } y.ID = (int)row["ID"]; } } } } } //Get The CPU(400) password if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HATTRME1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HATTRME1.DBF", _ziphelper, _DirSeperator); byte[] memoarray = null; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"]) { if ((int)row["ATTRIIDM"] == 111142) { if (row["MEMOARRAYM"] != DBNull.Value) { memoarray = (byte[])row["MEMOARRAYM"]; } if (memoarray.Length >= 12) { // memoarray[3] : level password (1-3) byte[] mempass = new byte[8]; for (int i = 0; i < 8; i++) { if (i < 2) { mempass[i] = (byte)(memoarray[i + 4] ^ 0xAA); } else { mempass[i] = (byte)(memoarray[i + 2] ^ memoarray[i + 4] ^ 0xAA); } } string res = ProjectEncoding.GetString(mempass); foreach (var y in CPUFolders) { if ((int)row["IDM"] == y.ID) { y.PasswdHard = res.Trim(); } } } } } } } //Get The CPs... if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7wb53ax" + _DirSeperator + "HOBJECT1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7wb53ax" + _DirSeperator + "HOBJECT1.DBF", _ziphelper, _DirSeperator); foreach (var y in CPFolders) { foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["ID"] == y.ID) { y.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { y.Name = "$$_" + y.Name; } } } } } } var tmpS7ProgrammFolders = new List <S7ProgrammFolder>(); //Get all Program Folders if (_ziphelper.FileExists(ProjectFolder + "hrs" + _DirSeperator + "S7RESOFF.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hrs" + _DirSeperator + "S7RESOFF.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { var x = new S7ProgrammFolder() { Project = this }; x.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { x.Name = "$$_" + x.Name; } x.ID = (int)row["ID"]; x._linkfileoffset = (int)row["RSRVD4_L"]; S7ProgrammFolders.Add(x); tmpS7ProgrammFolders.Add(x); } } } //Combine Folder and CPU (300) if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk31ax" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["RELID"] == 16) { int cpuid = (int)row["SOBJID"]; int fldid = (int)row["TOBJID"]; foreach (var y in CPUFolders) { if (y.ID == cpuid && y.CpuType == PLCType.Simatic300) { foreach (var z in S7ProgrammFolders) { if (z.ID == fldid) { z.Parent = y; y.SubItems.Add(z); tmpS7ProgrammFolders.Remove(z); } } } } } } } } //Combine Folder and CPU (300 ET200s) if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hkcomx" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hkcomx" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["RELID"] == 16) { int cpuid = (int)row["SOBJID"]; int fldid = (int)row["TOBJID"]; foreach (var y in CPUFolders) { if (y.ID == cpuid && y.CpuType == PLCType.SimaticET200) { foreach (var z in S7ProgrammFolders) { if (z.ID == fldid) { z.Parent = y; y.SubItems.Add(z); tmpS7ProgrammFolders.Remove(z); } } } } } } } } //Combine Folder and CPU (400) if (_ziphelper.FileExists(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HRELATI1.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "hOmSave7" + _DirSeperator + "s7hk41ax" + _DirSeperator + "HRELATI1.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { if ((int)row["RELID"] == 16) { int cpuid = (int)row["SOBJID"]; int fldid = (int)row["TOBJID"]; foreach (var y in CPUFolders) { if (y.ID == cpuid && (y.CpuType == PLCType.Simatic400 || y.CpuType == PLCType.Simatic400H)) { foreach (var z in S7ProgrammFolders) { if (z.ID == fldid) { z.Parent = y; y.SubItems.Add(z); tmpS7ProgrammFolders.Remove(z); } } } } } } } } //Add the BlockFolders without CPU to the Ground project foreach (var z in tmpS7ProgrammFolders) { z.Parent = ProjectStructure; ProjectStructure.SubItems.Add(z); } //Get Symbol Tables foreach (var z in S7ProgrammFolders) { var symtab = _GetSymTabForProject(z, this._showDeleted); if (symtab != null) { symtab.Parent = z; z.SymbolTable = symtab; z.SubItems.Add(symtab); } } var tmpBlocksOfflineFolders = new List <BlocksOfflineFolder>(); //Create the Programm Block folders... if (_ziphelper.FileExists(ProjectFolder + "ombstx" + _DirSeperator + "offline" + _DirSeperator + "BSTCNTOF.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "ombstx" + _DirSeperator + "offline" + _DirSeperator + "BSTCNTOF.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { var x = new BlocksOfflineFolder() { Project = this }; x.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { x.Name = "$$_" + x.Name; } x.ID = (int)row["ID"]; x.Folder = ProjectFolder + "ombstx" + _DirSeperator + "offline" + _DirSeperator + x.ID.ToString("X").PadLeft(8, '0') + _DirSeperator; tmpBlocksOfflineFolders.Add(x); _blocksOfflineFolders.Add(x); } } } var Step7ProjectTypeStep7Sources = new List <SourceFolder>(); //Create the Source Block folders... if (_ziphelper.FileExists(ProjectFolder + "s7asrcom" + _DirSeperator + "S7CNTREF.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(ProjectFolder + "s7asrcom" + _DirSeperator + "S7CNTREF.DBF", _ziphelper, _DirSeperator); foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || _showDeleted) { var x = new SourceFolder() { Project = this }; x.Name = ((string)row["Name"]).Replace("\0", ""); if ((bool)row["DELETED_FLAG"]) { x.Name = "$$_" + x.Name; } x.ID = (int)row["ID"]; x.Folder = ProjectFolder + "s7asrcom" + _DirSeperator + x.ID.ToString("X").PadLeft(8, '0') + _DirSeperator; Step7ProjectTypeStep7Sources.Add(x); } } } //Infos about Link file hrs\linkhrs.lnk //Size of a Structure in the Link File: 512 bytes //Offset of Linkfile is in hrs\S7RESOFF.DBF, Filed 12 (RSRVD3_L) //after 0x04, 0x20, 0x11 follows the Step7ProjectBlockFolder ID (2 Bytes) or maybe the source folder id //after 0x01, 0x60, 0x11 follows the Step7Programm ID (2 Bytes) //Create the Link BlocksOfflineFolder Folder with S7ProgrammFolders... if (_ziphelper.FileExists(ProjectFolder + "hrs" + _DirSeperator + "linkhrs.lnk")) { //FileStream hrsLink = new FileStream(ProjectFolder + "hrs" + _DirSeperator + "linkhrs.lnk", FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite); Stream hrsLink = _ziphelper.GetReadStream(ProjectFolder + "hrs" + _DirSeperator + "linkhrs.lnk"); BinaryReader rd = new BinaryReader(hrsLink); byte[] completeBuffer = rd.ReadBytes((int)_ziphelper.GetStreamLength(ProjectFolder + "hrs" + _DirSeperator + "linkhrs.lnk", hrsLink)); rd.Close(); hrsLink.Close(); hrsLink = new MemoryStream(completeBuffer); foreach (var x in S7ProgrammFolders) { byte[] tmpLink = new byte[0x200]; hrsLink.Position = x._linkfileoffset; hrsLink.Read(tmpLink, 0, 0x200); int pos1 = ASCIIEncoding.ASCII.GetString(tmpLink).IndexOf(ASCIIEncoding.ASCII.GetString(new byte[] { 0x01, 0x60, 0x11 })); int wrt1 = tmpLink[pos1 + 3] * 0x100 + tmpLink[pos1 + 4]; int pos2 = ASCIIEncoding.ASCII.GetString(tmpLink).IndexOf(ASCIIEncoding.ASCII.GetString(new byte[] { 0x04, 0x20, 0x11 })); int wrt2 = tmpLink[pos2 + 3] * 0x100 + tmpLink[pos2 + 4]; foreach (var y in tmpBlocksOfflineFolders) { if (y.ID == wrt1) { y.Parent = x; x.SubItems.Add(y); x.BlocksOfflineFolder = y; } } foreach (var y in Step7ProjectTypeStep7Sources) { if (y.ID == wrt2) { y.Parent = x; x.SubItems.Add(y); x.SourceFolder = y; } } } hrsLink.Close(); } else { foreach (var y in tmpBlocksOfflineFolders) { y.Parent = ProjectStructure; ProjectStructure.SubItems.Add(y); } foreach (var y in Step7ProjectTypeStep7Sources) { y.Parent = ProjectStructure; ProjectStructure.SubItems.Add(y); } } }
//In this Class a UC is converted to a Call and also backwards... public static void ConvertUCToCall(S7FunctionBlock myFct, S7ProgrammFolder myFld, BlocksOfflineFolder myblkFld, S7ConvertingOptions myOpt, byte[] addInfoFromBlock) { if (myOpt.GenerateCallsfromUCs) { int inBld = 0; //1=nach BLD 1 S7FunctionBlockRow newRow = null; Dictionary <string, string> Parameters = new Dictionary <string, string>(); List <FunctionBlockRow> retVal = new List <FunctionBlockRow>(); List <FunctionBlockRow> tempList = new List <FunctionBlockRow>(); string akPar = ""; string db = ""; string label = ""; bool afterCall = false; S7FunctionBlockRow callRow = null; for (int n = 0; n < myFct.AWLCode.Count; n++) { S7FunctionBlockRow row = (S7FunctionBlockRow)myFct.AWLCode[n]; if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "1" || row.Parameter == "7") && inBld == 0) { retVal.AddRange(tempList); tempList.Clear(); Parameters.Clear(); db = ""; label = row.Label; inBld = Convert.ToInt32(row.Parameter); newRow = null; afterCall = false; callRow = null; tempList.Add(row); } else if (inBld > 0) { tempList.Add(row); if (row.Command == "=" && n > 0 && myFct.AWLCode[n - 1].Command == Mnemonic.opBLD[(int)myOpt.Mnemonic]) { //Do nothing, but this line needs to be there! } else if (row.Command == Mnemonic.opU[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opUN[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opO[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opON[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opX[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opXN[(int)myOpt.Mnemonic] || row.Command == Mnemonic.opL[(int)myOpt.Mnemonic]) { akPar = row.Parameter; } else if (row.Command == "AUF") { db = row.Parameter + "."; } else if (row.Command == "CLR") { akPar = "FALSE"; } else if (row.Command == "SET") { akPar = "TRUE"; } else if ((row.Command == "=") && akPar != "") { if (afterCall == false) { string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key, db + akPar); } } else { string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key, db + row.Parameter); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opT[(int)myOpt.Mnemonic] && akPar != "") { if (afterCall == false) { string key = row.Parameter.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key + ".0", db + akPar); } } else { string key = akPar.Replace("L", "").Replace("W", "").Replace("B", "").Replace("D", ""); if (!Parameters.ContainsKey(key)) { Parameters.Add("P#V " + key, db + row.Parameter); } } akPar = ""; db = ""; } else if (row.Command == Mnemonic.opUC[(int)myOpt.Mnemonic]) { //Commands after a Call --> Out-Para callRow = row; afterCall = true; } else if (row.Command == Mnemonic.opBLD[(int)myOpt.Mnemonic] && (row.Parameter == "2" || row.Parameter == "8")) { //Block Interface auslesen (von FC oder vom Programm) //myFld.BlocksOfflineFolder.GetBlock() S7DataRow para = myblkFld.GetInterface(callRow.Parameter); newRow = new S7FunctionBlockRow(); newRow.Command = Mnemonic.opCALL[(int)myOpt.Mnemonic]; newRow.Parameter = callRow.Parameter; //newRow.ExtParameter = new List<string>(); newRow.CallParameter = new List <S7FunctionBlockParameter>(); for (int i = 0; i < callRow.ExtParameter.Count; i++) { string s = callRow.ExtParameter[i]; string parnm = ""; S7DataRow akRow = Parameter.GetFunctionParameterFromNumber(para, i); if (akRow != null) { parnm = akRow.Name + ""; } else { parnm = "$$undef"; } S7FunctionBlockParameter newPar = new S7FunctionBlockParameter(); newPar.Name = parnm; if (akRow != null) { newPar.ParameterDataType = akRow.DataType; if (akRow.Parent.Name == "OUT") { newPar.ParameterType = S7FunctionBlockParameterDirection.OUT; } else if (akRow.Parent.Name == "IN_OUT") { newPar.ParameterType = S7FunctionBlockParameterDirection.IN_OUT; } else { newPar.ParameterType = S7FunctionBlockParameterDirection.IN; } //newPar.ParameterType } if (akRow != null) { int posL = s.IndexOf(' '); int ak_address = 0; if (posL >= 0) { ak_address = Convert.ToInt32(s.Substring(posL + 1).Split('.')[0]); } else { ak_address = Convert.ToInt32(s.Substring(2).Split('.')[0]) * 8 + Convert.ToInt32(s.Substring(2).Split('.')[1]); } int lokaldata_address = -1; if (s.Substring(0, 3) == "P#V") { lokaldata_address = Convert.ToInt32(s.Substring(4).Split('.')[0]); } if (akRow.DataType == S7DataRowType.STRING || akRow.DataType == S7DataRowType.DATE_AND_TIME || akRow.DataType == S7DataRowType.STRUCT || akRow.DataType == S7DataRowType.UDT || akRow.DataType == S7DataRowType.POINTER || akRow.IsArray) { string p1 = Parameters["P#V " + (lokaldata_address + 0).ToString() + ".0"]; string p2 = Parameters["P#V " + (lokaldata_address + 2).ToString() + ".0"]; string tmp = ""; if (p1 != "" && p1 != "0") { tmp += "P#DB" + p1 + "." + p2.Substring(2); } else { tmp += p2; } newPar.Value = tmp; newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + tmp); } else if (akRow.DataType == S7DataRowType.ANY) { string tmp = s; if (Parameters.ContainsKey("P#V " + (lokaldata_address + 0).ToString() + ".0") && Parameters.ContainsKey("P#V " + (lokaldata_address + 2).ToString() + ".0") && Parameters.ContainsKey("P#V " + (lokaldata_address + 4).ToString() + ".0") && Parameters.ContainsKey("P#V " + (lokaldata_address + 6).ToString() + ".0")) { string p1 = Parameters["P#V " + (lokaldata_address + 0).ToString() + ".0"]; string p2 = Parameters["P#V " + (lokaldata_address + 2).ToString() + ".0"]; string p3 = Parameters["P#V " + (lokaldata_address + 4).ToString() + ".0"]; string p4 = Parameters["P#V " + (lokaldata_address + 6).ToString() + ".0"]; tmp = "P#"; if (p3 != "0") { tmp += "DB" + p3 + "."; } tmp += p4.Substring(2); tmp += " BYTE "; //Todo Parse Byte 1 if the Type is Byte! tmp += p2; } newPar.Value = tmp; newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + tmp); } else { if (Parameters.ContainsKey(s)) { string par = Parameters[s]; if (akRow.DataType == S7DataRowType.S5TIME && par[0] >= '0' && par[0] <= '9') { newPar.Value = Helper.GetS5Time( BitConverter.GetBytes(Convert.ToInt32(par))[1], BitConverter.GetBytes(Convert.ToInt32(par))[0]); newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + // Helper.GetS5Time( // BitConverter.GetBytes(Convert.ToInt32(par))[1], // BitConverter.GetBytes(Convert.ToInt32(par))[0])); } else if (akRow.DataType == S7DataRowType.TIME && par[0] >= '0' && par[0] <= '9') { newPar.Value = Helper.GetDTime(BitConverter.GetBytes(Convert.ToInt32(par)), 0); newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + // Helper.GetDTime(BitConverter.GetBytes(Convert.ToInt32(par)),0)); } else if (akRow.DataType == S7DataRowType.CHAR && par[0] == 'B') { newPar.Value = (char) Int32.Parse(par.Substring(5), System.Globalization.NumberStyles.AllowHexSpecifier) + "'"; newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + "'" + // (char)Int32.Parse(par.Substring(5), System.Globalization.NumberStyles.AllowHexSpecifier) + "'"); } else { newPar.Value = Parameters[s]; newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + Parameters[s]); } } else { if (akRow.DataType == S7DataRowType.BOOL) { newPar.Value = s.Substring(2).Replace('V', 'L'); newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + s.Substring(2).Replace('V', 'L')); } else if (akRow.DataType == S7DataRowType.BLOCK_DB) { newPar.Value = "DB" + ak_address.ToString(); newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + "DB" + ak_address.ToString()); } else if (akRow.DataType == S7DataRowType.BLOCK_FB) { newPar.Value = "FB" + ak_address.ToString(); newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + "FB" + ak_address.ToString()); } else if (akRow.DataType == S7DataRowType.BLOCK_FC) { newPar.Value = "FC" + ak_address.ToString(); newRow.CallParameter.Add(newPar); } else if (akRow.DataType == S7DataRowType.BLOCK_SDB) { newPar.Value = "SDB" + ak_address.ToString(); newRow.CallParameter.Add(newPar); } else if (akRow.DataType == S7DataRowType.TIMER) { newPar.Value = Mnemonic.adT[(int)myOpt.Mnemonic] + ak_address.ToString(); newRow.CallParameter.Add(newPar); } else if (akRow.DataType == S7DataRowType.COUNTER) { newPar.Value = Mnemonic.adZ[(int)myOpt.Mnemonic] + ak_address.ToString(); newRow.CallParameter.Add(newPar); } else { string ber = ""; if (s.Substring(0, 5) == "P#DBX") { ber = "DB"; } else if (s.Substring(0, 5) == "P#DIX") { ber = "DI"; } else { ber = s.Substring(2, 1); } if (akRow.ByteLength == 1) { ber += "B"; } else if (akRow.ByteLength == 2) { ber += "W"; } else if (akRow.ByteLength == 4) { ber += "D"; } newPar.Value = ber.Replace('V', 'L') + ak_address.ToString(); newRow.CallParameter.Add(newPar); //newRow.ExtParameter.Add(parnm + // ber.Replace('V', 'L') + // ak_address.ToString()); } } } } } newRow.CombinedCommands = tempList; newRow.Label = label; int sz = 0; foreach (var functionBlockRow in newRow.CombinedCommands) { sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize; } byte[] mcges = new byte[sz]; sz = 0; foreach (var functionBlockRow in newRow.CombinedCommands) { Array.Copy(((S7FunctionBlockRow)functionBlockRow).MC7, 0, mcges, sz, ((S7FunctionBlockRow)functionBlockRow).ByteSize); sz += ((S7FunctionBlockRow)functionBlockRow).ByteSize; } newRow.MC7 = mcges; retVal.Add(newRow); Parameters.Clear(); tempList = new List <FunctionBlockRow>(); inBld = 0; } else { retVal.AddRange(tempList); tempList.Clear(); inBld = 0; } } else { retVal.Add(row); } } myFct.AWLCode = retVal; } }