private void ExportStructureItem(ProjectFolder fld, string targetFolder) { if (fld is IBlocksFolder) { var pfd = System.IO.Path.Combine(Properties.Settings.Default.TargetDirectory, targetFolder.Substring(1)); var bl = fld as IBlocksFolder; foreach (var i in bl.BlockInfos) { if (i is ITiaProjectBlockInfo) { var ti = i as ITiaProjectBlockInfo; try { var wrt = ti.ExportToString(); File.WriteAllText(System.IO.Path.Combine(pfd, ti.Name + ".exp"), ti.ExportToString()); } catch (Exception ex) { Debug.WriteLine("Error Exporting: " + ti.Name + " Error:" + ex.Message); } } } } foreach (var projectFolder in fld.SubItems) { var path = targetFolder + "\\" + projectFolder.Name; var pfd = System.IO.Path.Combine(Properties.Settings.Default.TargetDirectory, path.Substring(1)); Directory.CreateDirectory(pfd); ExportStructureItem(projectFolder, path); } }
private List<ProjectBlockInfo> GetBlocksFromProject(ProjectFolder project) { //create new list List<ProjectBlockInfo> allBlocks = new List<ProjectBlockInfo>(); try { if (project.GetType() == typeof(BlocksOfflineFolder)) { BlocksOfflineFolder offline = (BlocksOfflineFolder)project; allBlocks.AddRange(offline.BlockInfos); } if (project.GetType() == typeof(SourceFolder)) { SourceFolder source = (SourceFolder)project; // TODO: Use source files instead of the compiled FBs? allBlocks.AddRange(source.BlockInfos); } //add all child blocks foreach (ProjectFolder subFolder in project.SubItems) { allBlocks.AddRange(GetBlocksFromProject(subFolder)); } } catch (Exception err) { EventFire.Error(err.ToString()); } return allBlocks; }
private List<ISymbolTable> GetSymbolTablesFromProject(ProjectFolder project) { //create new list List<ISymbolTable> allSymTables = new List<ISymbolTable>(); try { if (project.GetType() == typeof(S7ProgrammFolder)) { ISymbolTable symtab = ((S7ProgrammFolder)project).SymbolTable; allSymTables.Add(symtab); } //add all child blocks foreach (ProjectFolder subFolder in project.SubItems) { allSymTables.AddRange(GetSymbolTablesFromProject(subFolder)); } } catch (Exception err) { EventFire.Error(err.ToString()); } return allSymTables; }
public static string TryGetStructuredName(ProjectFolder folder, string operand, string dbAddress, bool isForAnyPointer = false) { if (!(folder is BlocksOfflineFolder)) return dbAddress; var f = folder as BlocksOfflineFolder; var o = operand.Replace(" ", ""); var dbBlock = f.GetBlock(o, new S7ConvertingOptions { Mnemonic = folder.Project.ProjectLanguage }) as S7DataBlock; if (dbBlock == null) return dbAddress; var address = dbAddress.Replace(" ", ""); var pointPosition = address.IndexOf('.'); blockAddress.ByteAddress = int.Parse(pointPosition< 0 ? address.Substring(3) : address.Substring(3, pointPosition - 3)); blockAddress.BitAddress = int.Parse(pointPosition< 0 ? "0" : address.Substring(address.Length - 1)); var dbRow = dbBlock.GetDataRowWithAddress(blockAddress); if (dbRow == null) return dbAddress; if (dbRow.DataType != S7DataRowType.STRING) return dbRow.StructuredName; var byteOffset = blockAddress.ByteAddress - dbRow.BlockAddress.ByteAddress; if (pointPosition< 0 && (byteOffset)>1) //if its not using a bit access to access the string variable return dbRow.StructuredName + "[" + (byteOffset - 2) + "]"; if (isForAnyPointer && byteOffset == 0) return dbRow.StructuredName; return dbAddress; }