Skip to content

Commit

Permalink
Merge pull request #123 from dotnetprojects/feature/varTabExport
Browse files Browse the repository at this point in the history
work on var tab export
  • Loading branch information
jogibear9988 authored Jul 3, 2019
2 parents 059cd59 + 26cc1ff commit e208aa2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 20 deletions.
31 changes: 18 additions & 13 deletions DotNetSiemensPLCToolBoxLibrary.TIAV15_1/Step7ProjectV15_1Tia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ public override string Export(ExportFormat exportFormat)
}
}

public class TIAOpennessTagTable
public class TIAOpennessTagTable : ITIAVarTab
{
public string Name { get; set; }

public List<TIAOpennessConstant> Constants { get; set; }
public List<ITIAConstant> Constants { get; set; }

public IEnumerable<TIAOpennessTag> Tags { get; internal set; }
public List<ITIATag> Tags { get; internal set; }

internal PlcTagTable PlcTagTable { get; set; }

Expand All @@ -248,10 +248,15 @@ public virtual string Export(ExportFormat exportFormat)
File.Delete(file);

return text;
}
}

public string Export()
{
return Export(ExportFormat.Xml);
}
}

public class TIAOpennessTag
public class TIAOpennessTag : ITIATag
{
public string Name { get; set; }
public string Address { get; set; }
Expand All @@ -278,7 +283,7 @@ public class TIAOpennessComment
public string Text { get; internal set; }
}

public class TIAOpennessConstant
public class TIAOpennessConstant : ITIAConstant
{
private readonly PlcUserConstant controllerConstant;

Expand Down Expand Up @@ -378,7 +383,7 @@ private Block GetBlockRecursive(TIAOpennessPlcDatatypeFolder folder, string name
}
}

public class TIAVarTabFolder : TIAOpennessProjectFolder
public class TIAVarTabFolder : TIAOpennessProjectFolder, ITIAVarTabFolder
{
public TIAOpennessControllerFolder ControllerFolder { get; set; }

Expand All @@ -397,21 +402,21 @@ public TIAOpennessConstant FindConstant(string name)
{
var c = t.Constants.FirstOrDefault(x => x.Name == name);
if (c != null)
return c;
return (TIAOpennessConstant)c;
}
foreach (var f in SubItems.Flatten(x => x.SubItems))
{
foreach (var t in TagTables)
{
var c = t.Constants.FirstOrDefault(x => x.Name == name);
if (c != null)
return c;
return (TIAOpennessConstant)c;
}
}
return null;
}

public List<TIAOpennessTagTable> TagTables
public List<ITIAVarTab> TagTables
{
get
{
Expand All @@ -422,14 +427,14 @@ public List<TIAOpennessTagTable> TagTables
var q = this.TiaPortalItem as PlcTagTableSystemGroup;
if (q != null)
tags = q.TagTables;
var retVal = new List<TIAOpennessTagTable>();
var retVal = new List<ITIAVarTab>();

foreach (var tagList in tags)
{
var info = new TIAOpennessTagTable() { Name = tagList.Name, PlcTagTable = tagList };
retVal.Add(info);
info.Tags = tagList.Tags.Select(t => new TIAOpennessTag(t));
info.Constants = new List<TIAOpennessConstant>();
info.Tags = tagList.Tags.Select(t => new TIAOpennessTag(t)).Cast<ITIATag>().ToList();
info.Constants = new List<ITIAConstant>();
foreach (var c in tagList.UserConstants)
{
info.Constants.Add(new TIAOpennessConstant(c) { Name = c.Name });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V11
{
public interface ITIAConstant
{
string Name { get; set; }

object Value { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V11
{
public interface ITIATag
{
string Name { get; set; }
string Address { get; set; }
string DataTypeName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using DotNetSiemensPLCToolBoxLibrary.DataTypes.Projectfolders;
using System.Collections.Generic;

namespace DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V11
{
public interface ITIAVarTabFolder: IProjectFolder
{
List<ITIAVarTab> TagTables { get; }
}
}
15 changes: 15 additions & 0 deletions LibNoDaveConnectionLibrary/DataTypes/Blocks/Step7V11/ITiaVarTab.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V11
{
public interface ITIAVarTab
{
string Name { get; set; }

List<ITIAConstant> Constants { get; }

List<ITIATag> Tags { get; }

string Export();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
<Compile Include="Communication\S7_xxx\SZLDatasets.cs" />
<Compile Include="DataTypes\Blocks\IBlock.cs" />
<Compile Include="DataTypes\Blocks\IProjectBlockInfo.cs" />
<Compile Include="DataTypes\Blocks\Step7V11\ITIAConstant.cs" />
<Compile Include="DataTypes\Blocks\Step7V11\ITIATag.cs" />
<Compile Include="DataTypes\Blocks\Step7V11\ITIAVarTab.cs" />
<Compile Include="DataTypes\Blocks\Step7V11\ITIAVarTabFolder.cs" />
<Compile Include="DataTypes\Blocks\TiaAndSTep7DataBlockRow.cs" />
<Compile Include="DataTypes\Blocks\Step7V5\S7AnyPointer.cs" />
<Compile Include="DataTypes\BitByteAddress.cs" />
Expand Down
24 changes: 17 additions & 7 deletions TiaGitHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.Xml;
using DotNetSiemensPLCToolBoxLibrary.DataTypes;
using DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V11;
using DotNetSiemensPLCToolBoxLibrary.DataTypes.Projectfolders;
using DotNetSiemensPLCToolBoxLibrary.General;
using DotNetSiemensPLCToolBoxLibrary.Projectfiles;
Expand Down Expand Up @@ -39,7 +40,7 @@ static void Main(string[] args)
string exportPath = "";
string user = Settings.Default.DefaultUser;
string password = Settings.Default.DefaultPassword;


Project prj = null;

Expand Down Expand Up @@ -128,7 +129,7 @@ static void Main(string[] args)
}

Directory.CreateDirectory(exportPath);
}
}
else
{
file = args[0];
Expand All @@ -143,7 +144,7 @@ static void Main(string[] args)
Credentials credentials = null;
if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password))
{
credentials = new Credentials() {Username = user, Password = new SecureString()};
credentials = new Credentials() { Username = user, Password = new SecureString() };
foreach (char c in password)
{
credentials.Password.AppendChar(c);
Expand Down Expand Up @@ -200,7 +201,7 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
if (folder is IBlocksFolder)
{
var blkFld = folder as IBlocksFolder;

foreach (var projectBlockInfo in blkFld.BlockInfos)
{
try
Expand Down Expand Up @@ -464,7 +465,7 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
}

if (xml != null)
{
{
var xmlValid2 = false;
XmlDocument xmlDoc2 = new XmlDocument();
XmlNamespaceManager ns2 = new XmlNamespaceManager(xmlDoc2.NameTable);
Expand Down Expand Up @@ -506,7 +507,7 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
catch
{ }
}

try
{
var nodes = xmlDoc2.SelectNodes("//Created");
Expand Down Expand Up @@ -710,7 +711,6 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s

Directory.CreateDirectory(path);
File.WriteAllText(xmlfile, xml, new UTF8Encoding(true));

}
}
else
Expand All @@ -725,6 +725,16 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
}
}
}
else if (folder is ITIAVarTabFolder varTabfld)
{
foreach (var varTab in varTabfld.TagTables)
{
var vt = varTab.Export();
var file = Path.Combine(path, varTab.Name.Replace("\\", "_").Replace("/", "_") + ".xml");
Directory.CreateDirectory(path);
File.WriteAllText(file, vt, new UTF8Encoding(true));
}
}
}

private static string NormalizeFolderName(string name)
Expand Down

0 comments on commit e208aa2

Please sign in to comment.