-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from CMor1184/TIA_V20_readiness
added TIA V20 support and ET200SP OpenController support for TiaGitHa…
- Loading branch information
Showing
42 changed files
with
186,881 additions
and
13 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
44 changes: 44 additions & 0 deletions
44
DotNetSiemensPLCToolBoxLibrary.TIAV20/DotNetSiemensPLCToolBoxLibrary.TIAV20.csproj
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,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||
<PropertyGroup><GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks></PropertyGroup> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net48</TargetFramework> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PackageId>DotNetProjects.DotNetSiemensPLCToolBoxLibrary.TIAV20</PackageId> | ||
<Authors>DotNetProjects</Authors> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/jogibear9988/DotNetSiemensPLCToolBoxLibrary</PackageProjectUrl> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>1.0.0</Version> | ||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | ||
<FileVersion>1.0.0.0</FileVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\LibNoDaveConnectionLibrary\DotNetSiemensPLCToolBoxLibrary.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Siemens.Engineering"> | ||
<HintPath>..\externalDlls\siemens\V20\Siemens.Engineering.dll</HintPath> | ||
<Private>False</Private> | ||
<SpecificVersion>False</SpecificVersion> | ||
</Reference> | ||
<Reference Include="Siemens.Engineering.Hmi"> | ||
<HintPath>..\externalDlls\siemens\V20\Siemens.Engineering.Hmi.dll</HintPath> | ||
<Private>False</Private> | ||
<SpecificVersion>False</SpecificVersion> | ||
</Reference> | ||
<Reference Include="System.Windows.Forms" /> | ||
</ItemGroup> | ||
</Project> |
13 changes: 13 additions & 0 deletions
13
DotNetSiemensPLCToolBoxLibrary.TIAV20/SelectPortalInstance.xaml
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,13 @@ | ||
<Window x:Class="DotNetSiemensPLCToolBoxLibrary.TIAV20.SelectPortalInstance" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
mc:Ignorable="d" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen" | ||
Height="450" Width="800"> | ||
<Grid> | ||
<ListBox x:Name="lstInstances" Margin="10,31,10,64"/> | ||
<TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Select Portal Instance" VerticalAlignment="Top"/> | ||
<Button Content="Ok" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="130" Height="49" Click="Button_Click"/> | ||
</Grid> | ||
</Window> |
15 changes: 15 additions & 0 deletions
15
DotNetSiemensPLCToolBoxLibrary.TIAV20/SelectPortalInstance.xaml.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,15 @@ | ||
namespace DotNetSiemensPLCToolBoxLibrary.TIAV20 | ||
{ | ||
public partial class SelectPortalInstance | ||
{ | ||
public SelectPortalInstance() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void Button_Click(object sender, System.Windows.RoutedEventArgs e) | ||
{ | ||
this.Close(); | ||
} | ||
} | ||
} |
193 changes: 193 additions & 0 deletions
193
DotNetSiemensPLCToolBoxLibrary.TIAV20/Step7ProjectV20.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,193 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Windows; | ||
using System.Xml; | ||
using DotNetSiemensPLCToolBoxLibrary.DataTypes; | ||
using DotNetSiemensPLCToolBoxLibrary.General; | ||
using DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA; | ||
using DotNetSiemensPLCToolBoxLibrary.TIAV20; | ||
using Microsoft.Win32; | ||
using Siemens.Engineering; | ||
|
||
namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.V20 | ||
{ | ||
public partial class Step7ProjectV20 : Project, IDisposable | ||
{ | ||
private readonly Credentials _credentials; | ||
|
||
private string DataFile = null; | ||
|
||
private XmlDocument tiaProject; | ||
|
||
internal ZipHelper _ziphelper = new ZipHelper(null); | ||
|
||
public CultureInfo Culture { get; set; } | ||
|
||
public Step7ProjectV20() | ||
{ | ||
AppDomain currentDomain = AppDomain.CurrentDomain; | ||
currentDomain.AssemblyResolve += currentDomain_AssemblyResolve; | ||
|
||
AskForInstance(); | ||
|
||
LoadViaOpennessDlls(); | ||
|
||
currentDomain.AssemblyResolve -= currentDomain_AssemblyResolve; | ||
} | ||
|
||
public static Step7ProjectV20 AttachToInstanceWithFilename(string filename) | ||
{ | ||
var inst = new Step7ProjectV20(""); | ||
|
||
AppDomain currentDomain = AppDomain.CurrentDomain; | ||
currentDomain.AssemblyResolve += inst.currentDomain_AssemblyResolve; | ||
inst.AksForInstanceWithFilename(filename); | ||
inst.LoadViaOpennessDlls(); | ||
currentDomain.AssemblyResolve -= inst.currentDomain_AssemblyResolve; | ||
|
||
return inst; | ||
} | ||
|
||
private Step7ProjectV20(string notUsed) | ||
{ } | ||
|
||
|
||
private void AksForInstanceWithFilename(string file) | ||
{ | ||
|
||
tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface); | ||
|
||
var processes = TiaPortal.GetProcesses().ToArray(); | ||
var process = processes.First(x => x.ProjectPath != null && x.ProjectPath.FullName == file); | ||
tiaPortal = process.Attach(); | ||
tiapProject = tiaPortal.Projects[0]; | ||
this.ProjectFile = process.ProjectPath.ToString(); | ||
} | ||
|
||
private void AskForInstance() | ||
{ | ||
|
||
tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface); | ||
|
||
var processes = TiaPortal.GetProcesses().ToArray(); | ||
var sLst = processes.Select(x => "Projekt : " + (x.ProjectPath != null ? x.ProjectPath.ToString() : "-")).ToArray(); | ||
AppDomain domain = AppDomain.CreateDomain("another domain"); | ||
CrossAppDomainDelegate action = () => | ||
{ | ||
var app = new Application(); | ||
var ask = new SelectPortalInstance(); | ||
var p = AppDomain.CurrentDomain.GetData("processes") as string[]; | ||
ask.lstInstances.ItemsSource = p; | ||
app.Run(ask); | ||
AppDomain.CurrentDomain.SetData("idx", ask.lstInstances.SelectedIndex); | ||
}; | ||
domain.SetData("processes", sLst); | ||
domain.DoCallBack(action); | ||
var idx = (int)domain.GetData("idx"); | ||
|
||
tiaPortal = processes[idx].Attach(); | ||
tiapProject = tiaPortal.Projects[0]; | ||
this.ProjectFile = processes[idx].ProjectPath.ToString(); | ||
} | ||
|
||
public Step7ProjectV20(string projectfile, CultureInfo culture = null) : this(projectfile, culture, null) | ||
{ | ||
} | ||
|
||
public Step7ProjectV20(string projectfile, CultureInfo culture = null, Credentials credentials = null) | ||
{ | ||
_credentials = credentials; | ||
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("zap20")) | ||
{ | ||
this._ziphelper = new ZipHelper(projectfile); | ||
if (string.IsNullOrEmpty(ProjectFile)) | ||
ProjectFile = _ziphelper.GetFirstZipEntryWithEnding(".ap20"); | ||
if (string.IsNullOrEmpty(ProjectFile)) | ||
ProjectFile = _ziphelper.GetFirstZipEntryWithEnding(".al20"); | ||
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) | ||
{ } | ||
|
||
DataFile = Path.GetDirectoryName(projectfile) + "\\System\\PEData.plf"; | ||
ProjectFolder = projectfile.Substring(0, projectfile.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar; | ||
|
||
//BinaryParseTIAFile(); | ||
//LoadProject(); | ||
OpenViaOpennessDlls(credentials); | ||
|
||
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\\TIAP20\\Global") ?? | ||
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Siemens\\Automation\\_InstalledSW\\TIAP20\\Global"); | ||
|
||
if (filePathReg != null) | ||
{ | ||
string filePath = Path.Combine(filePathReg.GetValue("Path").ToString(), "PublicAPI\\V20"); | ||
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; | ||
|
||
public override ProjectType ProjectType | ||
{ | ||
get { return ProjectType.Tia20; } | ||
} | ||
|
||
protected override void LoadProject() | ||
{ | ||
_projectLoaded = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.