Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AXSharp-L1-tests.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"AXSharp.compiler\\tests\\AXSharp.ixr.Tests\\AXSharp.ixr.Tests.csproj",
"AXSharp.connectors\\tests\\AXSharp.ConnectorLegacyTests\\AXSharp.ConnectorLegacyTests.csproj",
"AXSharp.connectors\\tests\\AXSharp.ConnectorTests\\AXSharp.ConnectorTests\\AXSharp.ConnectorTests.csproj",
"AXSharp.tools\\src\\AXSharp.TIA2AX.TranformerTests\\AXSharp.TIA2AX.TransformerTests.csproj",
"AXSharp.tools\\tests\\AXSharp.LocalizablesToResx.Tests\\AXSharp.LocalizablesToResx.Tests.csproj",
"AXSharp.tools\\tests\\AXSharp.nuget.update.Tests\\AXSharp.nuget.update.Tests.csproj"
]
Expand Down
2 changes: 2 additions & 0 deletions src/AXSharp-packable-only.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"AXSharp.connectors\\src\\AXSharp.Connector.S71500.WebAPI\\AXSharp.Connector.S71500.WebAPI.csproj",
"AXSharp.connectors\\src\\AXSharp.Connector\\AXSharp.Connector.csproj",
"AXSharp.connectors\\src\\AXSharp.TIA.Connector\\AXSharp.TIA2AXSharp.csproj",
"AXSharp.tools\\src\\AXSharp.LocalizablesToResx\\AXSharp.LocalizablesToResx.csproj",
"AXSharp.tools\\src\\AXSharp.TIA2AX.Tranformer\\AXSharp.TIA2AX.Transformer.csproj",
"AXSharp.tools\\src\\AXSharp.TIA2AXTool\\AXSharp.TIA2AXTool.csproj"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AXSharp.Compiler.Cs.Helpers;
using AXSharp.Connector;
using AXSharp.Connector.BuilderHelpers;
using AXSharp.Compiler.Cs;
using System;

namespace AXSharp.Compiler.Cs.Onliner;
Expand Down Expand Up @@ -127,10 +128,13 @@ private void AddArrayMemberInitialization(IArrayTypeDeclaration type, IVariableD

private void AddMemberInitialization(IClassDeclaration type, IVariableDeclaration variable, IxNodeVisitor visitor)
{
var attributes = variable.Pragmas.AddAttributes();
var isdb = attributes.Split('\n').Any(p => p == "[DBAttribute()]");
AddToSource($"{variable.Name}");
AddToSource("= new");
type.Accept(visitor, this);
AddToSource($"(this.Connector, \"\", \"{variable.Name}\");");
var symbol = isdb ? $"\"\\\"{variable.Name}\\\"\"" : $"\"{variable.Name}\"";
AddToSource($"(this.Connector, \"\", {symbol});");
}

private void AddMemberInitialization(IStructuredTypeDeclaration type, IVariableDeclaration variable, IxNodeVisitor visitor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
using Siemens.Simatic.S7.Webserver.API.Models;
using Siemens.Simatic.S7.Webserver.API.Services;
using Siemens.Simatic.S7.Webserver.API.Services.RequestHandling;
namespace AXSharp.TIA.Connector;

namespace AXSharp.TIA2AXSharp;

/// <summary>
/// Class containing methods for creating a TIA2AX adapter
Expand Down Expand Up @@ -65,6 +66,7 @@ public static async Task<TIARootObject> CreateTIARootObject(WebApiConnector conn
/// Creates TIARootObject from provided connector and from symbol downwards
/// </summary>
/// <param name="connector">Instance of WebApiConnector</param>
/// <param name="symbol">Symbol from which browsing should start.</param>
/// <returns>TIARootObject</returns>
public static async Task<TIARootObject> CreateTIARootObject(WebApiConnector connector, string symbol)
{
Expand Down Expand Up @@ -197,6 +199,7 @@ private static async Task BrowseParent(ApiPlcProgramData parentNode, IApiRequest
var children = requestHandler.PlcProgramBrowseAsync(ApiPlcProgramBrowseMode.Children, parentNode).Result.Result;
parentNode.Children = children;


await CreateTwin(parentNode, requestHandler, parent, dept);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using AXSharp.TIA2AXSharp;
using Newtonsoft.Json;

namespace AXSharp.TIA.Connector;
namespace AXSharp.TIA2AXSharp;

public class TIATwinObject : ITwinObject, ITIAGenericObject
{
Expand All @@ -27,6 +27,7 @@ public TIATwinObject(ITwinObject parent, string readableTail, string symbolTail)
{
_parent = parent;
Symbol = Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail);
_symbolTail = symbolTail;
}

public string Symbol { get; }
Expand All @@ -48,9 +49,11 @@ public ITwinObject GetParent()
return _parent;
}

private readonly string _symbolTail;

public string GetSymbolTail()
{
throw new NotImplementedException();
return _symbolTail;
}

public void Poll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Xunit;
using AXSharp.TIA.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using AXSharp.Connector;
using AXSharp.Connector.ValueTypes;
using AXSharp.TIA.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AXSharp.TIA2AXSharp;
using Xunit;

namespace AXSharp.TIA2AXSharpTests
Expand Down
32 changes: 32 additions & 0 deletions src/AXSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXSharp.TIA2AXSharpTests_L3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXSharp.TIA2AXTool", "AXSharp.tools\src\AXSharp.TIA2AXTool\AXSharp.TIA2AXTool.csproj", "{9C5A4D17-FEA3-4880-AE0D-66C01EAA7FD2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{391CFB2E-DC64-4F30-B479-17F21DAF1532}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXSharp.TIA2AX.Transformer", "AXSharp.tools\src\AXSharp.TIA2AX.Tranformer\AXSharp.TIA2AX.Transformer.csproj", "{16C14306-C701-491A-81C8-B4B6D8FDB367}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXSharp.TIA2AX.TransformerTests", "AXSharp.tools\src\AXSharp.TIA2AX.TranformerTests\AXSharp.TIA2AX.TransformerTests.csproj", "{ECC1D9CE-EB81-430D-9784-007700D285FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -600,6 +606,30 @@ Global
{9C5A4D17-FEA3-4880-AE0D-66C01EAA7FD2}.Release|x64.Build.0 = Release|Any CPU
{9C5A4D17-FEA3-4880-AE0D-66C01EAA7FD2}.Release|x86.ActiveCfg = Release|Any CPU
{9C5A4D17-FEA3-4880-AE0D-66C01EAA7FD2}.Release|x86.Build.0 = Release|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Debug|x64.ActiveCfg = Debug|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Debug|x64.Build.0 = Debug|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Debug|x86.ActiveCfg = Debug|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Debug|x86.Build.0 = Debug|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Release|Any CPU.Build.0 = Release|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Release|x64.ActiveCfg = Release|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Release|x64.Build.0 = Release|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Release|x86.ActiveCfg = Release|Any CPU
{16C14306-C701-491A-81C8-B4B6D8FDB367}.Release|x86.Build.0 = Release|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Debug|x64.ActiveCfg = Debug|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Debug|x64.Build.0 = Debug|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Debug|x86.ActiveCfg = Debug|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Debug|x86.Build.0 = Debug|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Release|Any CPU.Build.0 = Release|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Release|x64.ActiveCfg = Release|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Release|x64.Build.0 = Release|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Release|x86.ActiveCfg = Release|Any CPU
{ECC1D9CE-EB81-430D-9784-007700D285FE}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -661,6 +691,8 @@ Global
{E4EA5E5B-FA1A-4348-A826-F95FA16DC2C9} = {7F2A7036-E894-46A0-ADDA-6E69A5387CE4}
{597C4C50-1F9D-4302-8A66-05009DF32CBD} = {2C77593D-3432-408B-8E94-C41D7BD4242F}
{9C5A4D17-FEA3-4880-AE0D-66C01EAA7FD2} = {FC332118-F8B8-48DC-A7EA-AC7559CD4A98}
{16C14306-C701-491A-81C8-B4B6D8FDB367} = {FC332118-F8B8-48DC-A7EA-AC7559CD4A98}
{ECC1D9CE-EB81-430D-9784-007700D285FE} = {FE787422-9AB3-4065-A6D9-97511EC6141C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {99D50E81-8A37-4BB9-A435-C2C98430D600}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
using TAXSharp.TIA2AX.Transformer;

namespace AXSharp.TIA2AX.Transformer
{
public class AXPseoudoProjectGenerator
{
public static void Create(string baseDirectory, string outputProject, IEnumerable<string> sources)
{
var generator = new AXPseoudoProjectGenerator();

generator.CreateProjectStructure(baseDirectory, outputProject);

var srcFolderPath = Path.Combine(baseDirectory, outputProject, "src");

var configurationBuilder = new StringBuilder();
configurationBuilder.AppendLine("CONFIGURATION MyConfiguration");
configurationBuilder.AppendLine("TASK Main(Interval := T#10ms, Priority := 1);");
configurationBuilder.AppendLine("PROGRAM P1 WITH Main: MyProgram;");
configurationBuilder.AppendLine("\tVAR_GLOBAL");
foreach (var source in sources)
{
var fileName = new FileInfo(source);
var input = File.ReadAllText(source);
var tranformed = string.Empty;
using (var sw = new StreamWriter(Path.Combine(srcFolderPath, $"{fileName.Name}.st")))
{
tranformed = TIA2AXTypeTransformer.GetTransformation(input);
sw.Write(TIA2AXTypeTransformer.GetTransformation(tranformed));
}


foreach (var dbName in generator.GetDbNames(tranformed))
{
configurationBuilder.AppendLine($"\t{{#ix-attr: [DBAttribute()]}}");
configurationBuilder.AppendLine($"\t{dbName} : {dbName};");
}
}
configurationBuilder.AppendLine("\tEND_VAR");
configurationBuilder.AppendLine("END_CONFIGURATION");

configurationBuilder.Append(@"PROGRAM MyProgram
VAR

END_VAR
;
END_PROGRAM");

using (var sw = new StreamWriter(Path.Combine(srcFolderPath, $"configuration.st")))
{
sw.Write(configurationBuilder.ToString());
}
}

private void EnsureDirectory(string directory)
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
}


private IEnumerable<string> GetDbNames(string source)
{
var regex = new Regex(@"{#ix-db: (?<dbName>\w+)}");
var matches = regex.Matches(source);
foreach (Match match in matches)
{
yield return match.Groups["dbName"].Value;
}
}

private void CreateProjectStructure(string baseDirectory, string outputProject)
{
// Combine paths to create the full directory paths
string projectDirectory = Path.Combine(baseDirectory, outputProject);
string srcDirectory = Path.Combine(projectDirectory, "src");
string testDirectory = Path.Combine(projectDirectory, "test");

// Create the src and test directories
EnsureDirectory(srcDirectory);
EnsureDirectory(testDirectory);

// Path for the apax.yml file
string apaxFilePath = Path.Combine(projectDirectory, "apax.yml");

// Content for the apax.yml file
string apaxContent = $@"name: ""{outputProject}""
version: 0.0.0
type: app
targets:
- axunit-llvm
devDependencies:
""@ax/sdk"": ^4.0.8
";

// Write the apax content to the file
File.WriteAllText(apaxFilePath, apaxContent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!--NuGet Specific part-->
<Description>Generator of Pseudo AX project from exported TIA datablocks</Description>
<PackAsTool>True</PackAsTool>
<ToolCommandName>tiapax</ToolCommandName>

<!-- NuGet Common part-->
<PackageProjectUrl>https://github.com/ix-ax/</PackageProjectUrl>
<RepositoryUrl>https://github.com/ix-ax/axsharp</RepositoryUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>ix-ax</Authors>
<Copyright>(c) Peter Kurhajec and Contributors</Copyright>
<PackageTags>simatix-ax, PLC, industrial automation, SCADA, HMI</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Title>AX# compiler CLI</Title>
<PackageIcon>icon_128_128.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>
Release notes are published here:
https://github.com/ix-ax/axsharp/releases
</PackageReleaseNotes>
<PackageReadmeFile>NUGET-README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\..\..\assets\icons\icon_128_128.png" Link="icon_128_128.png">
<PackagePath>\</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
</None>
<None Include="..\..\..\NUGET-README.md" Link="NUGET-README.md">
<PackagePath>\</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="GitVersion.MsBuild" Version="5.10.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions src/AXSharp.tools/src/AXSharp.TIA2AX.Tranformer/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommandLine;

namespace AXSharp.TIA2AX.Transformer
{
public class Options
{
[Option('d', "db-files", Required = false, HelpText = "list of exported db blocks from TIA portal which should be used")]
public IEnumerable<string> DataBlocks { get; set; }

[Option('o', "output", Required = true, HelpText = "Output folder for pseudo AX project")]
public string? Output{ get; set; }
}
}
28 changes: 28 additions & 0 deletions src/AXSharp.tools/src/AXSharp.TIA2AX.Tranformer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using AXSharp.TIA2AX.Transformer;
using CommandLine;
using TAXSharp.TIA2AX.Transformer;

Parser.Default.ParseArguments<Options>(args)
.WithParsed(Main);

void Main(Options args)
{
AXPseoudoProjectGenerator.Create(args.Output, "PseudoAX", args.DataBlocks);
}














Loading