Skip to content

Commit

Permalink
TIA PORTAL V15 SUPPORT FOR OPENESS
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Dec 27, 2017
1 parent 0d58ba2 commit d443019
Show file tree
Hide file tree
Showing 10 changed files with 1,341 additions and 4 deletions.
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{61E6DB85-4280-4963-95EF-254BA1A81C04}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DotNetSiemensPLCToolBoxLibrary.TIAV15</RootNamespace>
<AssemblyName>DotNetSiemensPLCToolBoxLibrary.TIAV15</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\compiled\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Siemens.Engineering">
<HintPath>..\externalDlls\siemens\V15\Siemens.Engineering.dll</HintPath>
</Reference>
<Reference Include="Siemens.Engineering.Hmi">
<HintPath>..\externalDlls\siemens\V15\Siemens.Engineering.Hmi.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Step7ProjectV15.cs" />
<Compile Include="Step7ProjectV15Tia.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibNoDaveConnectionLibrary\DotNetSiemensPLCToolBoxLibrary.csproj">
<Project>{e3ed87e8-b550-46ac-9196-9688d30efd29}</Project>
<Name>DotNetSiemensPLCToolBoxLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions DotNetSiemensPLCToolBoxLibrary.TIAV15/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("DotNetSiemensPLCToolBoxLibrary.TIAV14SP1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DotNetSiemensPLCToolBoxLibrary.TIAV14SP1")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("ab0895ae-446f-4cd8-96ab-c8007d618593")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
123 changes: 123 additions & 0 deletions DotNetSiemensPLCToolBoxLibrary.TIAV15/Step7ProjectV15.cs
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xml;
using DotNetSiemensPLCToolBoxLibrary.General;
using DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA;
using Microsoft.Win32;

namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.V15
{
public partial class Step7ProjectV15 : Project, IDisposable
{
public enum TiaVersionTypes
{
V11 = 11,
V12 = 12,
V13 = 13,
V14 = 14,
}

public static TiaVersionTypes TiaVersion { get; private set; }

private string DataFile = null;

private XmlDocument tiaProject;

internal ZipHelper _ziphelper = new ZipHelper(null);

public CultureInfo Culture { get; set; }

public Step7ProjectV15(string projectfile, CultureInfo culture = null)
{
if (culture == null)
Culture = CultureInfo.CurrentCulture;
else
Culture = culture;

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;

ProjectFile = projectfile;

if (ProjectFile.ToLower().EndsWith("zip") || ProjectFile.ToLower().EndsWith("zap15"))
{
if (string.IsNullOrEmpty(ProjectFile))
ProjectFile = ZipHelper.GetFirstZipEntryWithEnding(ProjectFile, ".ap15");
if (string.IsNullOrEmpty(ProjectFile))
ProjectFile = ZipHelper.GetFirstZipEntryWithEnding(ProjectFile, ".al15");

if (string.IsNullOrEmpty(projectfile))
throw new Exception("Zip-File contains no valid TIA Project !");
this._ziphelper = new ZipHelper(projectfile);
}


try
{
var xmlDoc = new XmlDocument();
xmlDoc.Load(_ziphelper.GetReadStream(projectfile));

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)
{ }

DataFile = Path.GetDirectoryName(projectfile) + "\\System\\PEData.plf";
ProjectFolder = projectfile.Substring(0, projectfile.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar;

//BinaryParseTIAFile();
//LoadProject();
LoadViaOpennessDlls();

currentDomain.AssemblyResolve -= currentDomain_AssemblyResolve;
}

internal XmlDocument xmlDoc;

Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
int index = args.Name.IndexOf(',');
if (index == -1)
{
return null;
}
var name = args.Name.Substring(0, index) + ".dll";

var filePathReg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Siemens\\Automation\\_InstalledSW\\TIAP15\\Global") ??
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Siemens\\Automation\\_InstalledSW\\TIAP15\\Global");

if (filePathReg != null)
{
string filePath = Path.Combine(filePathReg.GetValue("Path").ToString(), "PublicAPI\\V15");
if (Directory.Exists(filePath) == false)
filePath = Path.Combine(filePathReg.GetValue("Path").ToString(), "PublicAPI\\V15 SP1");
var path = Path.Combine(filePath, name);
var fullPath = Path.GetFullPath(path);
if (File.Exists(fullPath))
{
return Assembly.LoadFrom(fullPath);
}
}

return null;
}

private object tiaExport;
private Type tiaExportType;


internal Dictionary<TiaObjectId, TiaFileObject> TiaObjects = new Dictionary<TiaObjectId, TiaFileObject>();

protected override void LoadProject()
{
_projectLoaded = true;
}
}
}

0 comments on commit d443019

Please sign in to comment.