-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0aeb0f
commit ff40227
Showing
27 changed files
with
264 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
LibNoDaveConnectionLibrary/General/BinaryReaderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace DotNetSiemensPLCToolBoxLibrary.General | ||
{ | ||
public static class BinaryReaderExtensions | ||
{ | ||
public static Guid ReadGuid(this BinaryReader binaryReader) | ||
{ | ||
return new Guid(binaryReader.ReadBytes(16)); | ||
} | ||
|
||
public static Version ReadVersion(this BinaryReader binaryReader) | ||
{ | ||
return new Version(binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ public enum ProjectType | |
{ | ||
Step5, | ||
Step7, | ||
TiaBinary, | ||
Tia13, | ||
Tia14SP1, | ||
Tia15, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
LibNoDaveConnectionLibrary/Projectfiles/TIA/Step7ProjectTiaBinaryParsed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Xml; | ||
using DotNetSiemensPLCToolBoxLibrary.DataTypes; | ||
using DotNetSiemensPLCToolBoxLibrary.General; | ||
using DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA.Structs; | ||
|
||
namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA | ||
{ | ||
public class Step7ProjectTiaBinaryParsed : Project | ||
{ | ||
private readonly Credentials _credentials; | ||
|
||
private string DataFile = null; | ||
|
||
private XmlDocument tiaProject; | ||
|
||
internal ZipHelper _ziphelper = new ZipHelper(null); | ||
|
||
public CultureInfo Culture { get; set; } | ||
|
||
//will be removed later... | ||
public List<TiaObjectHeader> TiaObjectsList; | ||
|
||
public void BinaryParseTIAFile() | ||
{ | ||
using (var sourceStream = _ziphelper.GetReadStream(DataFile)) | ||
{ | ||
var rd = new BinaryReader(sourceStream); | ||
var header = TiaFileHeader.Deserialize(rd); | ||
|
||
TiaObjectsList = new List<TiaObjectHeader>(); | ||
try | ||
{ | ||
while (true) | ||
{ | ||
var hd = TiaObjectHeader.Deserialize(rd); | ||
TiaObjectsList.Add(hd); | ||
} | ||
} | ||
catch (EndOfStreamException) // Zip File Stream has no length | ||
{ } | ||
|
||
/*var rootId = new TiaObjectId(TiaFixedRootObjectInstanceIds.RootObjectCollectionId); | ||
var rootObjects = new TiaRootObjectList(TiaObjects[rootId]); | ||
var projectid = rootObjects.TiaRootObjectEntrys.FirstOrDefault(x => x.ObjectId.TypeId == (int)TiaTypeIds.Siemens_Automation_DomainModel_ProjectData).ObjectId; | ||
var projectobj = TiaObjects[projectid];*/ | ||
} | ||
} | ||
|
||
public Step7ProjectTiaBinaryParsed(string projectfile, CultureInfo culture = null) : this(projectfile, culture, null) | ||
{ | ||
} | ||
|
||
public Step7ProjectTiaBinaryParsed(string projectfile, CultureInfo culture = null, Credentials credentials = null) | ||
{ | ||
_credentials = credentials; | ||
if (culture == null) | ||
Culture = CultureInfo.CurrentCulture; | ||
else | ||
Culture = culture; | ||
|
||
ProjectFile = projectfile; | ||
|
||
if (ProjectFile.ToLower().EndsWith("zip") || Path.GetExtension(ProjectFile.ToLower()).Contains("zap")) | ||
{ | ||
this._ziphelper = new ZipHelper(projectfile); | ||
if (string.IsNullOrEmpty(ProjectFile)) | ||
ProjectFile = _ziphelper.GetFirstZipEntryWithMatch("\\.ap.*"); | ||
if (string.IsNullOrEmpty(ProjectFile)) | ||
ProjectFile = _ziphelper.GetFirstZipEntryWithMatch("\\.al.*"); | ||
if (string.IsNullOrEmpty(projectfile)) | ||
throw new Exception("Zip-File contains no valid TIA Project !"); | ||
} | ||
|
||
try | ||
{ | ||
using (var stream = _ziphelper.GetReadStream(projectfile)) | ||
{ | ||
var xmlDoc = new XmlDocument(); | ||
xmlDoc.Load(stream); | ||
|
||
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); | ||
nsmgr.AddNamespace("x", "http://www.siemens.com/2007/07/Automation/CommonServices/DataInfoValueData"); | ||
|
||
var nd = xmlDoc.SelectSingleNode("x:Data", nsmgr); | ||
this.ProjectName = nd.Attributes["Name"].Value; | ||
} | ||
} | ||
catch (Exception) | ||
{ } | ||
|
||
if (_ziphelper.IsZipFile) | ||
DataFile = "System\\PEData.plf"; | ||
else | ||
DataFile = Path.GetDirectoryName(projectfile) + "\\System\\PEData.plf"; | ||
ProjectFolder = projectfile.Substring(0, projectfile.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar; | ||
|
||
BinaryParseTIAFile(); | ||
} | ||
|
||
internal XmlDocument xmlDoc; | ||
|
||
private object tiaExport; | ||
private Type tiaExportType; | ||
|
||
|
||
public override ProjectType ProjectType | ||
{ | ||
get { return ProjectType.TiaBinary; } | ||
} | ||
|
||
protected override void LoadProject() | ||
{ | ||
_projectLoaded = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.