Skip to content

Commit 4b3cd94

Browse files
committed
added TIA V20 support and ET200SP OpenController support for TiaGitHandler
1 parent 3835170 commit 4b3cd94

File tree

42 files changed

+186882
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+186882
-13
lines changed

DotNetSiemensPLCToolBoxLibrary.TIAV14SP1/Step7ProjectV14SP1Tia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ internal void LoadViaOpennessDlls()
644644

645645
foreach (var d in tiapProject.Devices)
646646
{
647-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
647+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
648648
{
649649
foreach (DeviceItem deviceItem in d.DeviceItems)
650650
{

DotNetSiemensPLCToolBoxLibrary.TIAV15/Step7ProjectV15Tia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ internal void LoadViaOpennessDlls(Credentials credentials)
651651

652652
foreach (var d in tiapProject.Devices)
653653
{
654-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
654+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
655655
{
656656
foreach (DeviceItem deviceItem in d.DeviceItems)
657657
{

DotNetSiemensPLCToolBoxLibrary.TIAV16/Step7ProjectV16Tia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ internal void LoadViaOpennessDlls()
861861

862862
foreach (var d in tiapProject.Devices)
863863
{
864-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
864+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
865865
{
866866
foreach (DeviceItem deviceItem in d.DeviceItems)
867867
{

DotNetSiemensPLCToolBoxLibrary.TIAV17/Step7ProjectV17Tia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ internal void LoadViaOpennessDlls()
861861

862862
foreach (var d in tiapProject.Devices)
863863
{
864-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
864+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
865865
{
866866
foreach (DeviceItem deviceItem in d.DeviceItems)
867867
{

DotNetSiemensPLCToolBoxLibrary.TIAV18/Step7ProjectV18Tia.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ internal void LoadViaOpennessDlls()
861861

862862
foreach (var d in tiapProject.Devices)
863863
{
864-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
864+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
865865
{
866866
foreach (DeviceItem deviceItem in d.DeviceItems)
867867
{

DotNetSiemensPLCToolBoxLibrary.TIAV19/Step7ProjectV19Tia.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ public override void ExportTextlists(ProjectFolder folder, string exportPath)
806806
{
807807
foreach (var d in tiapProject.Devices)
808808
{
809-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
809+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
810810
{
811811
foreach (DeviceItem deviceItem in d.DeviceItems)
812812
{
@@ -900,7 +900,7 @@ internal void LoadViaOpennessDlls()
900900

901901
foreach (var d in tiapProject.Devices)
902902
{
903-
if (d.TypeIdentifier != null && d.TypeIdentifier.EndsWith(".S71500"))
903+
if (d.TypeIdentifier != null && (d.TypeIdentifier.EndsWith(".S71500") || d.TypeIdentifier.EndsWith("ET200SP_OC")))
904904
{
905905
foreach (DeviceItem deviceItem in d.DeviceItems)
906906
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
<PropertyGroup><GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks></PropertyGroup>
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net48</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
<UseWPF>true</UseWPF>
8+
</PropertyGroup>
9+
<PropertyGroup>
10+
<PackageId>DotNetProjects.DotNetSiemensPLCToolBoxLibrary.TIAV20</PackageId>
11+
<Authors>DotNetProjects</Authors>
12+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13+
<PackageProjectUrl>https://github.com/jogibear9988/DotNetSiemensPLCToolBoxLibrary</PackageProjectUrl>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
15+
<Version>1.0.0</Version>
16+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
17+
<FileVersion>1.0.0.0</FileVersion>
18+
</PropertyGroup>
19+
<PropertyGroup>
20+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
21+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
22+
<IncludeSymbols>true</IncludeSymbols>
23+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
24+
</PropertyGroup>
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ProjectReference Include="..\LibNoDaveConnectionLibrary\DotNetSiemensPLCToolBoxLibrary.csproj" />
30+
</ItemGroup>
31+
<ItemGroup>
32+
<Reference Include="Siemens.Engineering">
33+
<HintPath>..\externalDlls\siemens\V20\Siemens.Engineering.dll</HintPath>
34+
<Private>False</Private>
35+
<SpecificVersion>False</SpecificVersion>
36+
</Reference>
37+
<Reference Include="Siemens.Engineering.Hmi">
38+
<HintPath>..\externalDlls\siemens\V20\Siemens.Engineering.Hmi.dll</HintPath>
39+
<Private>False</Private>
40+
<SpecificVersion>False</SpecificVersion>
41+
</Reference>
42+
<Reference Include="System.Windows.Forms" />
43+
</ItemGroup>
44+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Window x:Class="DotNetSiemensPLCToolBoxLibrary.TIAV20.SelectPortalInstance"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
mc:Ignorable="d" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen"
7+
Height="450" Width="800">
8+
<Grid>
9+
<ListBox x:Name="lstInstances" Margin="10,31,10,64"/>
10+
<TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Select Portal Instance" VerticalAlignment="Top"/>
11+
<Button Content="Ok" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="130" Height="49" Click="Button_Click"/>
12+
</Grid>
13+
</Window>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace DotNetSiemensPLCToolBoxLibrary.TIAV20
2+
{
3+
public partial class SelectPortalInstance
4+
{
5+
public SelectPortalInstance()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
11+
{
12+
this.Close();
13+
}
14+
}
15+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Windows;
8+
using System.Xml;
9+
using DotNetSiemensPLCToolBoxLibrary.DataTypes;
10+
using DotNetSiemensPLCToolBoxLibrary.General;
11+
using DotNetSiemensPLCToolBoxLibrary.Projectfiles.TIA;
12+
using DotNetSiemensPLCToolBoxLibrary.TIAV20;
13+
using Microsoft.Win32;
14+
using Siemens.Engineering;
15+
16+
namespace DotNetSiemensPLCToolBoxLibrary.Projectfiles.V20
17+
{
18+
public partial class Step7ProjectV20 : Project, IDisposable
19+
{
20+
private readonly Credentials _credentials;
21+
22+
private string DataFile = null;
23+
24+
private XmlDocument tiaProject;
25+
26+
internal ZipHelper _ziphelper = new ZipHelper(null);
27+
28+
public CultureInfo Culture { get; set; }
29+
30+
public Step7ProjectV20()
31+
{
32+
AppDomain currentDomain = AppDomain.CurrentDomain;
33+
currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;
34+
35+
AskForInstance();
36+
37+
LoadViaOpennessDlls();
38+
39+
currentDomain.AssemblyResolve -= currentDomain_AssemblyResolve;
40+
}
41+
42+
public static Step7ProjectV20 AttachToInstanceWithFilename(string filename)
43+
{
44+
var inst = new Step7ProjectV20("");
45+
46+
AppDomain currentDomain = AppDomain.CurrentDomain;
47+
currentDomain.AssemblyResolve += inst.currentDomain_AssemblyResolve;
48+
inst.AksForInstanceWithFilename(filename);
49+
inst.LoadViaOpennessDlls();
50+
currentDomain.AssemblyResolve -= inst.currentDomain_AssemblyResolve;
51+
52+
return inst;
53+
}
54+
55+
private Step7ProjectV20(string notUsed)
56+
{ }
57+
58+
59+
private void AksForInstanceWithFilename(string file)
60+
{
61+
62+
tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface);
63+
64+
var processes = TiaPortal.GetProcesses().ToArray();
65+
var process = processes.First(x => x.ProjectPath != null && x.ProjectPath.FullName == file);
66+
tiaPortal = process.Attach();
67+
tiapProject = tiaPortal.Projects[0];
68+
this.ProjectFile = process.ProjectPath.ToString();
69+
}
70+
71+
private void AskForInstance()
72+
{
73+
74+
tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface);
75+
76+
var processes = TiaPortal.GetProcesses().ToArray();
77+
var sLst = processes.Select(x => "Projekt : " + (x.ProjectPath != null ? x.ProjectPath.ToString() : "-")).ToArray();
78+
AppDomain domain = AppDomain.CreateDomain("another domain");
79+
CrossAppDomainDelegate action = () =>
80+
{
81+
var app = new Application();
82+
var ask = new SelectPortalInstance();
83+
var p = AppDomain.CurrentDomain.GetData("processes") as string[];
84+
ask.lstInstances.ItemsSource = p;
85+
app.Run(ask);
86+
AppDomain.CurrentDomain.SetData("idx", ask.lstInstances.SelectedIndex);
87+
};
88+
domain.SetData("processes", sLst);
89+
domain.DoCallBack(action);
90+
var idx = (int)domain.GetData("idx");
91+
92+
tiaPortal = processes[idx].Attach();
93+
tiapProject = tiaPortal.Projects[0];
94+
this.ProjectFile = processes[idx].ProjectPath.ToString();
95+
}
96+
97+
public Step7ProjectV20(string projectfile, CultureInfo culture = null) : this(projectfile, culture, null)
98+
{
99+
}
100+
101+
public Step7ProjectV20(string projectfile, CultureInfo culture = null, Credentials credentials = null)
102+
{
103+
_credentials = credentials;
104+
if (culture == null)
105+
Culture = CultureInfo.CurrentCulture;
106+
else
107+
Culture = culture;
108+
109+
AppDomain currentDomain = AppDomain.CurrentDomain;
110+
currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;
111+
112+
ProjectFile = projectfile;
113+
114+
if (ProjectFile.ToLower().EndsWith("zip") || ProjectFile.ToLower().EndsWith("zap20"))
115+
{
116+
this._ziphelper = new ZipHelper(projectfile);
117+
if (string.IsNullOrEmpty(ProjectFile))
118+
ProjectFile = _ziphelper.GetFirstZipEntryWithEnding(".ap20");
119+
if (string.IsNullOrEmpty(ProjectFile))
120+
ProjectFile = _ziphelper.GetFirstZipEntryWithEnding(".al20");
121+
if (string.IsNullOrEmpty(projectfile))
122+
throw new Exception("Zip-File contains no valid TIA Project !");
123+
}
124+
125+
try
126+
{
127+
using (var stream = _ziphelper.GetReadStream(projectfile))
128+
{
129+
var xmlDoc = new XmlDocument();
130+
xmlDoc.Load(stream);
131+
132+
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
133+
nsmgr.AddNamespace("x", "http://www.siemens.com/2007/07/Automation/CommonServices/DataInfoValueData");
134+
135+
var nd = xmlDoc.SelectSingleNode("x:Data", nsmgr);
136+
this.ProjectName = nd.Attributes["Name"].Value;
137+
}
138+
}
139+
catch (Exception)
140+
{ }
141+
142+
DataFile = Path.GetDirectoryName(projectfile) + "\\System\\PEData.plf";
143+
ProjectFolder = projectfile.Substring(0, projectfile.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar;
144+
145+
//BinaryParseTIAFile();
146+
//LoadProject();
147+
OpenViaOpennessDlls(credentials);
148+
149+
currentDomain.AssemblyResolve -= currentDomain_AssemblyResolve;
150+
}
151+
152+
internal XmlDocument xmlDoc;
153+
154+
Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
155+
{
156+
int index = args.Name.IndexOf(',');
157+
if (index == -1)
158+
{
159+
return null;
160+
}
161+
var name = args.Name.Substring(0, index) + ".dll";
162+
163+
var filePathReg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Siemens\\Automation\\_InstalledSW\\TIAP20\\Global") ??
164+
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Siemens\\Automation\\_InstalledSW\\TIAP20\\Global");
165+
166+
if (filePathReg != null)
167+
{
168+
string filePath = Path.Combine(filePathReg.GetValue("Path").ToString(), "PublicAPI\\V20");
169+
var path = Path.Combine(filePath, name);
170+
var fullPath = Path.GetFullPath(path);
171+
if (File.Exists(fullPath))
172+
{
173+
return Assembly.LoadFrom(fullPath);
174+
}
175+
}
176+
177+
return null;
178+
}
179+
180+
private object tiaExport;
181+
private Type tiaExportType;
182+
183+
public override ProjectType ProjectType
184+
{
185+
get { return ProjectType.Tia20; }
186+
}
187+
188+
protected override void LoadProject()
189+
{
190+
_projectLoaded = true;
191+
}
192+
}
193+
}

0 commit comments

Comments
 (0)