diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 735e4d7..2002e9c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -30,6 +30,21 @@ jobs: fileVersion: ${{ steps.gitversion.outputs.MajorMinorPatch }} informationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }} + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: TiaCodegen-ts/package-lock.json + - name: Install TypeScript dependencies + run: npm ci + working-directory: TiaCodegen-ts + - name: Build TypeScript + run: npm run build + working-directory: TiaCodegen-ts + - name: Test TypeScript + run: npm test + working-directory: TiaCodegen-ts - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/dotnetpull.yml b/.github/workflows/dotnetpull.yml index a547030..4fc917f 100644 --- a/.github/workflows/dotnetpull.yml +++ b/.github/workflows/dotnetpull.yml @@ -15,6 +15,21 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 9.0.x + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: TiaCodegen-ts/package-lock.json + - name: Install TypeScript dependencies + run: npm ci + working-directory: TiaCodegen-ts + - name: Build TypeScript + run: npm run build + working-directory: TiaCodegen-ts + - name: Test TypeScript + run: npm test + working-directory: TiaCodegen-ts - name: Restore dependencies run: dotnet restore - name: Build diff --git a/TiaCodeGen.Tests/SampleTests.cs b/TiaCodeGen.Tests/SampleTests.cs index c161b39..dac9d01 100644 --- a/TiaCodeGen.Tests/SampleTests.cs +++ b/TiaCodeGen.Tests/SampleTests.cs @@ -1,568 +1,602 @@ -using NUnit.Framework; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using TiaCodegen.Blocks; -using TiaCodegen.Commands; -using TiaCodegen.Commands.Coils; -using TiaCodegen.Commands.Comparisons; -using TiaCodegen.Commands.Functions; -using TiaCodegen.Commands.Functions.Base; -using TiaCodegen.Commands.Signals; -using TiaCodegen.Enums; -using TiaCodegen.Interfaces; - -namespace TiaCodegen.Samples -{ - [TestFixture] - public class SampleTests - { - const string TestInterface = @" - - -
- - - Initial call of this OB - - - - - =True, if remanent data are available - - -
-
- - - - - - - - - - - - - - -
-
- -"; - - [Test] - public void CreateBlock1() - { - var codeblock = new CodeBlock(); - var nw = new Network("Test1", "Test1en"); - - nw.Add( - new And( - new Signal("#Bool1"), - new Distributor - ( - new RCoil(new Signal("#Bool2")), - new Coil(new Signal("#Bool3")) - ))); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void CreateBlock2() - { - var codeblock = new CodeBlock(); - - var nw = new Network("Test2", "Test2en"); - nw.Add( - new And( - new Signal("#Bool1"), - new Signal("#Bool2"), - new Convert( - new Signal("#Real1", SignalType.Real), - new Signal("#Dint2", SignalType.DInt) - ), - new Distributor( - new And( - new Move( - new Signal("#Real3"), - new Signal("#Real4") - ), - new SCoil(new Signal("#Bool3")) - ), - new And( - new Gt( - new Signal("#Real1", SignalType.Real), - new Signal("#Real2", SignalType.Real) - ), - new SCoil(new Signal("#Bool4")) - ) - ) - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - var xml = block.GetCode(); - block.Interface = TestInterface; - } - - [Test] - public void CreateBlock3() - { - var codeblock = new CodeBlock(); - - var nw = new Network("Test2", "Test2en"); - nw.Add( - new Coil( - new Signal("#Bool1"), - new And( - new Signal("#Bool2"), - new Or( - new Signal("#Bool3"), - new And( - new Signal("#Bool1"), - new Signal("#Bool4") - ) - ) - ) - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void DynamicSample1() - { - var codeblock = new CodeBlock(); - - var signals = new List() { "#Bool1", "#Bool2", "#Bool3" }; - var and = new And(); - foreach (var s in signals) - and.Add(new Signal(s)); - - var nw = new Network("Test2", "test2en"); - nw.Add( - new Coil( - new Signal("#Bool4"), - and - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void TestCallWithOr() - { - var codeblock = new CodeBlock(); - - var nw = new Network("Test2", "Test2en"); - - var f = new FunctionBlockCall("CheckContour", "CheckContourInstance"); - f.Interface["BoolPar"] = new IOperationOrSignalDirectionWrapper(new Or(new Signal("P1"), new Signal("P2")), Direction.InOut); - f.Children.AddRange(f.Interface.Values.Where(x => x.OperationOrSignal != null).Select(x => x.OperationOrSignal)); - nw.Add(f); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void TestDistributor() - { - var codeblock = new CodeBlock(); - - var nw = new Network("Test2", "Test2en"); - nw.Add( - new And( - new Not(new Signal("Tag_9")), - new Distributor( - new And( - new Coil(new Signal("#monitoringSignal")) - ), - new And( - new TONCall("OnDelaySafetyDoorSDA11N13", pt: new Signal("T#60s", SignalType.ConstantTime), q: null) - ) - ) - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void TestCallWithInRange() - { - var codeblock = new CodeBlock(); - - var nw = new Network("Test2", "Test2en"); - - var f = new InRangeCall(new Signal(1), new Signal(2), new Signal(3), new Coil(new Signal("MW0", SignalType.Int))); - nw.Add(f); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void TestCallWithTOn() - { - var codeblock = new CodeBlock() { Safety = true }; - - var nw = new Network("Test2", "Test2en"); - - var f = new TONCall("Hallo", pt: new Signal("T#4m", SignalType.ConstantTime)); - nw.Add(f); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void TestCallWithCTU() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("Test2", "Test2en"); - - var f = new And(new Signal("aa"), new CTUCall("Hallo", r: new Signal("bbb", SignalType.Bool), pv: new Signal("2", SignalType.ConstantInt), q: new Coil(new Signal("ccc", SignalType.Bool)))); - nw.Add(f); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void TestCallWithTPAndDistributor() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("Test2", "Test2en"); - var and = - new And( - new Signal("#aaa"), - new TPCall("PulseStartPrint", - pt: new Signal("T#100ms", SignalType.ConstantTime), - q: new Distributor( - new Coil(new Signal("#bbbb")), - new RCoil(new Signal("#cccc")), - new SCoil(new Signal("#dddd")) - ) - ) - ); - - nw.Add(and); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void DistributorWithOr() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("Test2", "Test2en"); - nw.Add( - new And( - new Signal("asd"), - new Distributor( - new SCoil(new Signal("x")), - new And( - new Or( - new And( - new Signal("a"), - new Signal("h") - ), - new And( - new Signal("b"), - new Signal("f") - ) - ), - new SCoil(new Signal("c")) - ) - ) - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void MultipleOr() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("Test2", "Test2en"); - nw.Add( - new Coil( - new Signal("a"), - new And( - new Signal("1"), - new Or( - new And( - new Or( - new Signal("b"), - new Signal("c") - ), - new Signal("d") - ), - new Signal("e") - ) - ) - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void PeripheryFixedSignal() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("Test3", "Test3en"); - nw.Add( - new Coil( - new FixedPeripherySignal("=PBG10.6+FBG11-BV1:4"), - new And( - new Signal("1") - ) - ) - ); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void ComplexVariableAccessTest1() - { - var sb = new StringBuilder(); - var s = new Signal("#A.B.C[#D.E.F, 1]"); - s.AddXmlToStringBuilder(1, sb); - var xml = sb.ToString(); - Assert.AreEqual("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nDInt\r\n1\r\n\r\n\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); - } - - [Test] - public void ComplexVariableAccessTest2() - { - var sb = new StringBuilder(); - var s = new Signal("#A.B.C[#D.E.F, #G.H.I]"); - s.AddXmlToStringBuilder(1, sb); - var xml = sb.ToString(); - Assert.AreEqual("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); - } - - [Test] - public void TestConstant() - { - var sb = new StringBuilder(); - var s = new Signal("AAA", SignalType.Constant); - s.AddXmlToStringBuilder(1, sb); - var xml = sb.ToString(); - Assert.AreEqual("\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); - } - - [Test] - public void SystemFunctionDPXX_DAT() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("TestDPXX_DAT", "TestDPXX_DATen"); - - var sf1 = new SystemFunctionCall("DPRD_DAT"); - sf1.Interface["LADDR"] = new IOperationOrSignalDirectionWrapper(new Signal("#Configuration.GeneralMoviC.ModuleHardwareID"), Direction.Input); - sf1.Interface["RET_VAL"] = new IOperationOrSignalDirectionWrapper(new Signal("#retVal"), Direction.Output); - sf1.Interface["RECORD"] = new IOperationOrSignalDirectionWrapper(new Signal("#PeripheryInputsMoviC"), Direction.Output); - sf1.Children.AddRange(sf1.Interface.Values.Where(x => x.OperationOrSignal != null).Select(x => x.OperationOrSignal)); - - nw.Add(sf1); - - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - - //Assert.AreEqual("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nDInt\r\n1\r\n\r\n\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); - } - - [Test] - public void ComplexOr() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("T1", "T1"); - - nw.Add( - new Coil( - new Signal("Test11"), - new Or( - new And( - new Signal("Test1"), - new Or( - new And( - new Signal("Test2"), - new Or( - new Signal("Test3"), - new Signal("Test4") - ) - { DebugInfo = "aaa" } - ), - new Signal("Test5") - ) - { DebugInfo = "bbb" } - ), - new And( - new Signal("Test6"), - new Or( - new And( - new Signal("Test7"), - new Or( - new Signal("Test8"), - new Signal("Test9") - ) - { DebugInfo = "ccc" } - ), - new Signal("Test10") - ) - { DebugInfo = "ddd" } - ) - ) - { DebugInfo = "eee" } - ) - ); - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - [Test] - public void ComplexOr2() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("T1", "T1"); - - nw.Add( - new Coil( - new Signal("Test11"), - new Or( - new Signal("Test12"), - new Or( - new And( - new Signal("Test1"), - new Or( - new And( - new Signal("Test2"), - new Or( - new Signal("Test3"), - new Signal("Test4") - ) - ), - new Signal("Test5") - ) - ), - new And( - new Signal("Test6"), - new Or( - new And( - new Signal("Test7"), - new Or( - new Signal("Test8"), - new Signal("Test9") - ) - ), - new Signal("Test10") - ) - ) - ) - ) - ) - ); - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - - - [Test] - public void Complex3() - { - var codeblock = new CodeBlock() { Safety = false }; - - var nw = new Network("T1", "T1"); - - nw.Add( - new Coil( - new Signal("Test11"), - new And( - new Signal("Test1"), - new Or( - new Signal("Test2") - ) - ) - ) - ); - codeblock.Add(nw); - - var block = new Block("Test", "blabla", codeblock); - block.Interface = TestInterface; - var xml = block.GetCode(); - } - } -} +using NUnit.Framework; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using TiaCodegen.Blocks; +using TiaCodegen.Commands; +using TiaCodegen.Commands.Coils; +using TiaCodegen.Commands.Comparisons; +using TiaCodegen.Commands.Functions; +using TiaCodegen.Commands.Functions.Base; +using TiaCodegen.Commands.Signals; +using TiaCodegen.Enums; +using TiaCodegen.Interfaces; + +namespace TiaCodegen.Samples +{ + [TestFixture] + public class SampleTests + { + const string TestInterface = @" + + +
+ + + Initial call of this OB + + + + + =True, if remanent data are available + + +
+
+ + + + + + + + + + + + + + +
+
+ +"; + + [Test] + public void CreateBlock1() + { + var codeblock = new CodeBlock(); + var nw = new Network("Test1", "Test1en"); + + nw.Add( + new And( + new Signal("#Bool1"), + new Distributor + ( + new RCoil(new Signal("#Bool2")), + new Coil(new Signal("#Bool3")) + ))); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void CreateBlock2() + { + var codeblock = new CodeBlock(); + + var nw = new Network("Test2", "Test2en"); + nw.Add( + new And( + new Signal("#Bool1"), + new Signal("#Bool2"), + new Convert( + new Signal("#Real1", SignalType.Real), + new Signal("#Dint2", SignalType.DInt) + ), + new Distributor( + new And( + new Move( + new Signal("#Real3"), + new Signal("#Real4") + ), + new SCoil(new Signal("#Bool3")) + ), + new And( + new Gt( + new Signal("#Real1", SignalType.Real), + new Signal("#Real2", SignalType.Real) + ), + new SCoil(new Signal("#Bool4")) + ) + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + var xml = block.GetCode(); + block.Interface = TestInterface; + } + + [Test] + public void CreateBlock3() + { + var codeblock = new CodeBlock(); + + var nw = new Network("Test2", "Test2en"); + nw.Add( + new Coil( + new Signal("#Bool1"), + new And( + new Signal("#Bool2"), + new Or( + new Signal("#Bool3"), + new And( + new Signal("#Bool1"), + new Signal("#Bool4") + ) + ) + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void DynamicSample1() + { + var codeblock = new CodeBlock(); + + var signals = new List() { "#Bool1", "#Bool2", "#Bool3" }; + var and = new And(); + foreach (var s in signals) + and.Add(new Signal(s)); + + var nw = new Network("Test2", "test2en"); + nw.Add( + new Coil( + new Signal("#Bool4"), + and + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void TestCallWithOr() + { + var codeblock = new CodeBlock(); + + var nw = new Network("Test2", "Test2en"); + + var f = new FunctionBlockCall("CheckContour", "CheckContourInstance"); + f.Interface["BoolPar"] = new IOperationOrSignalDirectionWrapper(new Or(new Signal("P1"), new Signal("P2")), Direction.InOut); + f.Children.AddRange(f.Interface.Values.Where(x => x.OperationOrSignal != null).Select(x => x.OperationOrSignal)); + nw.Add(f); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void TestDistributor() + { + var codeblock = new CodeBlock(); + + var nw = new Network("Test2", "Test2en"); + nw.Add( + new And( + new Not(new Signal("Tag_9")), + new Distributor( + new And( + new Coil(new Signal("#monitoringSignal")) + ), + new And( + new TONCall("OnDelaySafetyDoorSDA11N13", pt: new Signal("T#60s", SignalType.ConstantTime), q: null) + ) + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void TestCallWithInRange() + { + var codeblock = new CodeBlock(); + + var nw = new Network("Test2", "Test2en"); + + var f = new InRangeCall(new Signal(1), new Signal(2), new Signal(3), new Coil(new Signal("MW0", SignalType.Int))); + nw.Add(f); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void TestCallWithTOn() + { + var codeblock = new CodeBlock() { Safety = true }; + + var nw = new Network("Test2", "Test2en"); + + var f = new TONCall("Hallo", pt: new Signal("T#4m", SignalType.ConstantTime)); + nw.Add(f); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void TestCallWithCTU() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("Test2", "Test2en"); + + var f = new And(new Signal("aa"), new CTUCall("Hallo", r: new Signal("bbb", SignalType.Bool), pv: new Signal("2", SignalType.ConstantInt), q: new Coil(new Signal("ccc", SignalType.Bool)))); + nw.Add(f); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void TestCallWithTPAndDistributor() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("Test2", "Test2en"); + var and = + new And( + new Signal("#aaa"), + new TPCall("PulseStartPrint", + pt: new Signal("T#100ms", SignalType.ConstantTime), + q: new Distributor( + new Coil(new Signal("#bbbb")), + new RCoil(new Signal("#cccc")), + new SCoil(new Signal("#dddd")) + ) + ) + ); + + nw.Add(and); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void DistributorWithOr() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("Test2", "Test2en"); + nw.Add( + new And( + new Signal("asd"), + new Distributor( + new SCoil(new Signal("x")), + new And( + new Or( + new And( + new Signal("a"), + new Signal("h") + ), + new And( + new Signal("b"), + new Signal("f") + ) + ), + new SCoil(new Signal("c")) + ) + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void MultipleOr() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("Test2", "Test2en"); + nw.Add( + new Coil( + new Signal("a"), + new And( + new Signal("1"), + new Or( + new And( + new Or( + new Signal("b"), + new Signal("c") + ), + new Signal("d") + ), + new Signal("e") + ) + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void PeripheryFixedSignal() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("Test3", "Test3en"); + nw.Add( + new Coil( + new FixedPeripherySignal("=PBG10.6+FBG11-BV1:4"), + new And( + new Signal("1") + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void ComplexVariableAccessTest1() + { + var sb = new StringBuilder(); + var s = new Signal("#A.B.C[#D.E.F, 1]"); + s.AddXmlToStringBuilder(1, sb); + var xml = sb.ToString(); + Assert.AreEqual("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nDInt\r\n1\r\n\r\n\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); + } + + [Test] + public void ComplexVariableAccessTest2() + { + var sb = new StringBuilder(); + var s = new Signal("#A.B.C[#D.E.F, #G.H.I]"); + s.AddXmlToStringBuilder(1, sb); + var xml = sb.ToString(); + Assert.AreEqual("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); + } + + [Test] + public void TestConstant() + { + var sb = new StringBuilder(); + var s = new Signal("AAA", SignalType.Constant); + s.AddXmlToStringBuilder(1, sb); + var xml = sb.ToString(); + Assert.AreEqual("\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); + } + + [Test] + public void SystemFunctionDPXX_DAT() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("TestDPXX_DAT", "TestDPXX_DATen"); + + var sf1 = new SystemFunctionCall("DPRD_DAT"); + sf1.Interface["LADDR"] = new IOperationOrSignalDirectionWrapper(new Signal("#Configuration.GeneralMoviC.ModuleHardwareID"), Direction.Input); + sf1.Interface["RET_VAL"] = new IOperationOrSignalDirectionWrapper(new Signal("#retVal"), Direction.Output); + sf1.Interface["RECORD"] = new IOperationOrSignalDirectionWrapper(new Signal("#PeripheryInputsMoviC"), Direction.Output); + sf1.Children.AddRange(sf1.Interface.Values.Where(x => x.OperationOrSignal != null).Select(x => x.OperationOrSignal)); + + nw.Add(sf1); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + + //Assert.AreEqual("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nDInt\r\n1\r\n\r\n\r\n\r\n\r\n\r\n".Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); + } + + [Test] + public void ComplexOr() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("T1", "T1"); + + nw.Add( + new Coil( + new Signal("Test11"), + new Or( + new And( + new Signal("Test1"), + new Or( + new And( + new Signal("Test2"), + new Or( + new Signal("Test3"), + new Signal("Test4") + ) + { DebugInfo = "aaa" } + ), + new Signal("Test5") + ) + { DebugInfo = "bbb" } + ), + new And( + new Signal("Test6"), + new Or( + new And( + new Signal("Test7"), + new Or( + new Signal("Test8"), + new Signal("Test9") + ) + { DebugInfo = "ccc" } + ), + new Signal("Test10") + ) + { DebugInfo = "ddd" } + ) + ) + { DebugInfo = "eee" } + ) + ); + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void ComplexOr2() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("T1", "T1"); + + nw.Add( + new Coil( + new Signal("Test11"), + new Or( + new Signal("Test12"), + new Or( + new And( + new Signal("Test1"), + new Or( + new And( + new Signal("Test2"), + new Or( + new Signal("Test3"), + new Signal("Test4") + ) + ), + new Signal("Test5") + ) + ), + new And( + new Signal("Test6"), + new Or( + new And( + new Signal("Test7"), + new Or( + new Signal("Test8"), + new Signal("Test9") + ) + ), + new Signal("Test10") + ) + ) + ) + ) + ) + ); + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + + [Test] + public void Complex3() + { + var codeblock = new CodeBlock() { Safety = false }; + + var nw = new Network("T1", "T1"); + + nw.Add( + new Coil( + new Signal("Test11"), + new And( + new Signal("Test1"), + new Or( + new Signal("Test2") + ) + ) + ) + ); + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + block.Interface = TestInterface; + var xml = block.GetCode(); + } + + [Test] + public void DoubleCarrierTest() + { + var codeblock = new CodeBlock() { Safety = false }; + var nw = new Network("Test", "Testen"); + + nw.Add( + new And( + new Eq(new Signal("#Configuration.General.SingleDoubleCarrier", SignalType.Int), new Signal(2)), + new Distributor( + new And( + new Or( + new Signal("#DoubleCarrier.Sensors.V[#Configuration.General.CoordinationAxisConveyor, 1]"), + new Signal("#DoubleCarrier.Sensors.R[#Configuration.General.CoordinationAxisConveyor, 1]") + ), + new Coil(new Signal("#CarrierGeneral.States.CarriageOccupied[2]")) + ), + new And( + new Signal("#DoubleCarrierData.MOrder.DataPresent"), + new Coil(new Signal("#CarrierGeneral.States.CarriageDataPresent[2]")) + ) + ) + ) + ); + + codeblock.Add(nw); + + var block = new Block("Test", "blabla", codeblock); + var xml = block.GetCode(); + + var expectedXml = @" General 1.0 Optimized Test LAD DInt2DInt2DInt1DInt1Int2Int2 LADde-DEen-GBde-DETesten-GBTesten de-DE blabla en-GB de-DE en-GB "; + Assert.AreEqual(expectedXml.Replace("\n", "").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", "")); + } + } +} \ No newline at end of file diff --git a/TiaCodegen-ts/.gitignore b/TiaCodegen-ts/.gitignore new file mode 100644 index 0000000..1eae0cf --- /dev/null +++ b/TiaCodegen-ts/.gitignore @@ -0,0 +1,2 @@ +dist/ +node_modules/ diff --git a/TiaCodegen-ts/package-lock.json b/TiaCodegen-ts/package-lock.json index ccbaed7..8703977 100644 --- a/TiaCodegen-ts/package-lock.json +++ b/TiaCodegen-ts/package-lock.json @@ -1,15 +1,16 @@ { - "name": "tia-codegen-ts", - "version": "1.0.0", + "name": "@node-projects/tia-codegen-ts", + "version": "2.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "tia-codegen-ts", - "version": "1.0.0", + "name": "@node-projects/tia-codegen-ts", + "version": "2.0.1", "devDependencies": { "@types/jest": "^29.5.12", "@types/node": "^20.12.7", + "esbuild": "^0.27.4", "jest": "^29.7.0", "ts-jest": "^29.1.2", "typescript": "^5.4.5" @@ -511,6 +512,448 @@ "dev": true, "license": "MIT" }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.4.tgz", + "integrity": "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.4.tgz", + "integrity": "sha512-X9bUgvxiC8CHAGKYufLIHGXPJWnr0OCdR0anD2e21vdvgCI8lIfqFbnoeOz7lBjdrAGUhqLZLcQo6MLhTO2DKQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.4.tgz", + "integrity": "sha512-gdLscB7v75wRfu7QSm/zg6Rx29VLdy9eTr2t44sfTW7CxwAtQghZ4ZnqHk3/ogz7xao0QAgrkradbBzcqFPasw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.4.tgz", + "integrity": "sha512-PzPFnBNVF292sfpfhiyiXCGSn9HZg5BcAz+ivBuSsl6Rk4ga1oEXAamhOXRFyMcjwr2DVtm40G65N3GLeH1Lvw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.4.tgz", + "integrity": "sha512-b7xaGIwdJlht8ZFCvMkpDN6uiSmnxxK56N2GDTMYPr2/gzvfdQN8rTfBsvVKmIVY/X7EM+/hJKEIbbHs9oA4tQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.4.tgz", + "integrity": "sha512-sR+OiKLwd15nmCdqpXMnuJ9W2kpy0KigzqScqHI3Hqwr7IXxBp3Yva+yJwoqh7rE8V77tdoheRYataNKL4QrPw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.4.tgz", + "integrity": "sha512-jnfpKe+p79tCnm4GVav68A7tUFeKQwQyLgESwEAUzyxk/TJr4QdGog9sqWNcUbr/bZt/O/HXouspuQDd9JxFSw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.4.tgz", + "integrity": "sha512-2kb4ceA/CpfUrIcTUl1wrP/9ad9Atrp5J94Lq69w7UwOMolPIGrfLSvAKJp0RTvkPPyn6CIWrNy13kyLikZRZQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.4.tgz", + "integrity": "sha512-aBYgcIxX/wd5n2ys0yESGeYMGF+pv6g0DhZr3G1ZG4jMfruU9Tl1i2Z+Wnj9/KjGz1lTLCcorqE2viePZqj4Eg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.4.tgz", + "integrity": "sha512-7nQOttdzVGth1iz57kxg9uCz57dxQLHWxopL6mYuYthohPKEK0vU0C3O21CcBK6KDlkYVcnDXY099HcCDXd9dA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.4.tgz", + "integrity": "sha512-oPtixtAIzgvzYcKBQM/qZ3R+9TEUd1aNJQu0HhGyqtx6oS7qTpvjheIWBbes4+qu1bNlo2V4cbkISr8q6gRBFA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.4.tgz", + "integrity": "sha512-8mL/vh8qeCoRcFH2nM8wm5uJP+ZcVYGGayMavi8GmRJjuI3g1v6Z7Ni0JJKAJW+m0EtUuARb6Lmp4hMjzCBWzA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.4.tgz", + "integrity": "sha512-1RdrWFFiiLIW7LQq9Q2NES+HiD4NyT8Itj9AUeCl0IVCA459WnPhREKgwrpaIfTOe+/2rdntisegiPWn/r/aAw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.4.tgz", + "integrity": "sha512-tLCwNG47l3sd9lpfyx9LAGEGItCUeRCWeAx6x2Jmbav65nAwoPXfewtAdtbtit/pJFLUWOhpv0FpS6GQAmPrHA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.4.tgz", + "integrity": "sha512-BnASypppbUWyqjd1KIpU4AUBiIhVr6YlHx/cnPgqEkNoVOhHg+YiSVxM1RLfiy4t9cAulbRGTNCKOcqHrEQLIw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.4.tgz", + "integrity": "sha512-+eUqgb/Z7vxVLezG8bVB9SfBie89gMueS+I0xYh2tJdw3vqA/0ImZJ2ROeWwVJN59ihBeZ7Tu92dF/5dy5FttA==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.4.tgz", + "integrity": "sha512-S5qOXrKV8BQEzJPVxAwnryi2+Iq5pB40gTEIT69BQONqR7JH1EPIcQ/Uiv9mCnn05jff9umq/5nqzxlqTOg9NA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.4.tgz", + "integrity": "sha512-xHT8X4sb0GS8qTqiwzHqpY00C95DPAq7nAwX35Ie/s+LO9830hrMd3oX0ZMKLvy7vsonee73x0lmcdOVXFzd6Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.4.tgz", + "integrity": "sha512-RugOvOdXfdyi5Tyv40kgQnI0byv66BFgAqjdgtAKqHoZTbTF2QqfQrFwa7cHEORJf6X2ht+l9ABLMP0dnKYsgg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.4.tgz", + "integrity": "sha512-2MyL3IAaTX+1/qP0O1SwskwcwCoOI4kV2IBX1xYnDDqthmq5ArrW94qSIKCAuRraMgPOmG0RDTA74mzYNQA9ow==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.4.tgz", + "integrity": "sha512-u8fg/jQ5aQDfsnIV6+KwLOf1CmJnfu1ShpwqdwC0uA7ZPwFws55Ngc12vBdeUdnuWoQYx/SOQLGDcdlfXhYmXQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.4.tgz", + "integrity": "sha512-JkTZrl6VbyO8lDQO3yv26nNr2RM2yZzNrNHEsj9bm6dOwwu9OYN28CjzZkH57bh4w0I2F7IodpQvUAEd1mbWXg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.4.tgz", + "integrity": "sha512-/gOzgaewZJfeJTlsWhvUEmUG4tWEY2Spp5M20INYRg2ZKl9QPO3QEEgPeRtLjEWSW8FilRNacPOg8R1uaYkA6g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.4.tgz", + "integrity": "sha512-Z9SExBg2y32smoDQdf1HRwHRt6vAHLXcxD2uGgO/v2jK7Y718Ix4ndsbNMU/+1Qiem9OiOdaqitioZwxivhXYg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.4.tgz", + "integrity": "sha512-DAyGLS0Jz5G5iixEbMHi5KdiApqHBWMGzTtMiJ72ZOLhbu/bzxgAe8Ue8CTS3n3HbIUHQz/L51yMdGMeoxXNJw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.4.tgz", + "integrity": "sha512-+knoa0BDoeXgkNvvV1vvbZX4+hizelrkwmGJBdT17t8FNPwG2lKemmuMZlmaNQ3ws3DKKCxpb4zRZEIp3UxFCg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1280,7 +1723,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -1620,6 +2062,48 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/esbuild": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.4.tgz", + "integrity": "sha512-Rq4vbHnYkK5fws5NF7MYTU68FPRE1ajX7heQ/8QXXWqNgqqJ/GkmmyxIzUnf2Sr/bakf8l54716CcMGHYhMrrQ==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.4", + "@esbuild/android-arm": "0.27.4", + "@esbuild/android-arm64": "0.27.4", + "@esbuild/android-x64": "0.27.4", + "@esbuild/darwin-arm64": "0.27.4", + "@esbuild/darwin-x64": "0.27.4", + "@esbuild/freebsd-arm64": "0.27.4", + "@esbuild/freebsd-x64": "0.27.4", + "@esbuild/linux-arm": "0.27.4", + "@esbuild/linux-arm64": "0.27.4", + "@esbuild/linux-ia32": "0.27.4", + "@esbuild/linux-loong64": "0.27.4", + "@esbuild/linux-mips64el": "0.27.4", + "@esbuild/linux-ppc64": "0.27.4", + "@esbuild/linux-riscv64": "0.27.4", + "@esbuild/linux-s390x": "0.27.4", + "@esbuild/linux-x64": "0.27.4", + "@esbuild/netbsd-arm64": "0.27.4", + "@esbuild/netbsd-x64": "0.27.4", + "@esbuild/openbsd-arm64": "0.27.4", + "@esbuild/openbsd-x64": "0.27.4", + "@esbuild/openharmony-arm64": "0.27.4", + "@esbuild/sunos-x64": "0.27.4", + "@esbuild/win32-arm64": "0.27.4", + "@esbuild/win32-ia32": "0.27.4", + "@esbuild/win32-x64": "0.27.4" + } + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -2126,7 +2610,6 @@ "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", @@ -3638,7 +4121,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/TiaCodegen-ts/package.json b/TiaCodegen-ts/package.json index 8d49c6e..b53e105 100644 --- a/TiaCodegen-ts/package.json +++ b/TiaCodegen-ts/package.json @@ -1,24 +1,47 @@ { - "name": "tia-codegen-ts", - "version": "1.0.0", + "name": "@node-projects/tia-codegen-ts", + "version": "2.0.1", "description": "TypeScript port of TiaCodeGen C# library", + "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, "scripts": { "build": "tsc", - "test": "jest --testPathPattern=tests", - "typecheck": "tsc --noEmit" + "test": "node --experimental-vm-modules node_modules/jest-cli/bin/jest.js --testPathPattern=tests", + "typecheck": "tsc --noEmit", + "bundle": "esbuild ./dist/index.js --format=esm --minify --external:wunderbaum --platform=neutral --bundle --outfile=./dist/index-min.js", + "prepublishOnly": "npm run build && npm run bundle" }, "devDependencies": { "@types/jest": "^29.5.12", "@types/node": "^20.12.7", + "esbuild": "^0.27.4", "jest": "^29.7.0", "ts-jest": "^29.1.2", "typescript": "^5.4.5" }, "jest": { - "preset": "ts-jest", + "preset": "ts-jest/presets/default-esm", "testEnvironment": "node", - "testMatch": ["**/tests/**/*.test.ts"] + "testMatch": [ + "**/tests/**/*.test.ts" + ], + "moduleNameMapper": { + "^(\\.{1,2}/.*)\\.js$": "$1" + }, + "transform": { + "^.+\\.tsx?$": [ + "ts-jest", + { + "useESM": true + } + ] + } } } diff --git a/TiaCodegen-ts/src/Blocks/Block.ts b/TiaCodegen-ts/src/Blocks/Block.ts index 332f632..0bc761a 100644 --- a/TiaCodegen-ts/src/Blocks/Block.ts +++ b/TiaCodegen-ts/src/Blocks/Block.ts @@ -1,5 +1,5 @@ -import { CodeBlock } from './CodeBlock'; -import { KopCodeHelper } from '../CodeGen/KopCodeHelper'; +import { CodeBlock } from './CodeBlock.js'; +import { KopCodeHelper } from '../CodeGen/KopCodeHelper.js'; export class Block { name: string; @@ -71,7 +71,7 @@ export class Block { en-GB - ${this.titleEnglish} + ${this.titleEnglish ?? ''} @@ -81,13 +81,13 @@ export class Block { de-DE - ${this.comment} + ${this.comment ?? ''} en-GB - ${this.commentEnglish} + ${this.commentEnglish ?? ''} diff --git a/TiaCodegen-ts/src/Blocks/CodeBlock.ts b/TiaCodegen-ts/src/Blocks/CodeBlock.ts index 8a1c1ea..f0995fb 100644 --- a/TiaCodegen-ts/src/Blocks/CodeBlock.ts +++ b/TiaCodegen-ts/src/Blocks/CodeBlock.ts @@ -1,4 +1,4 @@ -import { BaseOperationOrSignal } from '../Commands/BaseOperationOrSignal'; +import { BaseOperationOrSignal } from '../Commands/BaseOperationOrSignal.js'; export class CodeBlock extends BaseOperationOrSignal { name: string; diff --git a/TiaCodegen-ts/src/Blocks/Network.ts b/TiaCodegen-ts/src/Blocks/Network.ts index f5f91b2..ea4f1c8 100644 --- a/TiaCodegen-ts/src/Blocks/Network.ts +++ b/TiaCodegen-ts/src/Blocks/Network.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { BaseOperationOrSignal } from '../Commands/BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { BaseOperationOrSignal } from '../Commands/BaseOperationOrSignal.js'; export class Network extends BaseOperationOrSignal { networkTitle: string | undefined; diff --git a/TiaCodegen-ts/src/CodeGen/KopCodeHelper.ts b/TiaCodegen-ts/src/CodeGen/KopCodeHelper.ts index 2d1ae42..eda5a78 100644 --- a/TiaCodegen-ts/src/CodeGen/KopCodeHelper.ts +++ b/TiaCodegen-ts/src/CodeGen/KopCodeHelper.ts @@ -1,39 +1,39 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { ICoil } from '../Interfaces/ICoil'; -import { IFunctionOperation } from '../Interfaces/IFunctionOperation'; -import { IPartName } from '../Interfaces/IPartName'; -import { StringBuilder } from '../utils/StringBuilder'; -import { flatten } from '../Internal/IEnumerableExtensions'; -import { NaturalComparer } from '../Extensions/NaturalComparer'; -import { CodeBlock } from '../Blocks/CodeBlock'; -import { Network } from '../Blocks/Network'; -import { And } from '../Commands/And'; -import { Or } from '../Commands/Or'; -import { Not } from '../Commands/Not'; -import { Distributor } from '../Commands/Distributor'; -import { Move } from '../Commands/Move'; -import { Convert } from '../Commands/Convert'; -import { S_Move } from '../Commands/S_Move'; -import { Signal } from '../Commands/Signals/Signal'; -import { BaseCoil } from '../Commands/Coils/BaseCoil'; -import { BaseNPCoil } from '../Commands/Coils/BaseNPCoil'; -import { Coil } from '../Commands/Coils/Coil'; -import { SCoil } from '../Commands/Coils/SCoil'; -import { RCoil } from '../Commands/Coils/RCoil'; -import { BaseOperationOrSignal } from '../Commands/BaseOperationOrSignal'; -import { CompareOperator } from '../Commands/Comparisons/CompareOperator'; -import { InRangeCall } from '../Commands/Comparisons/InRangeCall'; -import { OutRangeCall } from '../Commands/Comparisons/OutRangeCall'; -import { FunctionCall } from '../Commands/Functions/Base/FunctionCall'; -import { FunctionBlockCall } from '../Commands/Functions/Base/FunctionBlockCall'; -import { SystemFunctionCall } from '../Commands/Functions/Base/SystemFunctionCall'; -import { SystemFunctionBlockCall } from '../Commands/Functions/Base/SystemFunctionBlockCall'; -import { ArithmeticCall } from '../Commands/Functions/Arithmetic/ArithmeticCall'; -import { VariableArithmeticCall } from '../Commands/Functions/Arithmetic/VariableArithmeticCall'; -import { AckGlCall } from '../Commands/Functions/AckGlCall'; -import { CTUCall } from '../Commands/Functions/CTUCall'; -import { CTUDCall } from '../Commands/Functions/CTUDCall'; -import { tryGetParent } from '../Extensions/OperationOrSignalExtensions'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { ICoil } from '../Interfaces/ICoil.js'; +import { IFunctionOperation } from '../Interfaces/IFunctionOperation.js'; +import { IPartName } from '../Interfaces/IPartName.js'; +import { StringBuilder } from '../utils/StringBuilder.js'; +import { flatten } from '../Internal/IEnumerableExtensions.js'; +import { NaturalComparer } from '../Extensions/NaturalComparer.js'; +import { CodeBlock } from '../Blocks/CodeBlock.js'; +import { Network } from '../Blocks/Network.js'; +import { And } from '../Commands/And.js'; +import { Or } from '../Commands/Or.js'; +import { Not } from '../Commands/Not.js'; +import { Distributor } from '../Commands/Distributor.js'; +import { Move } from '../Commands/Move.js'; +import { Convert } from '../Commands/Convert.js'; +import { S_Move } from '../Commands/S_Move.js'; +import { Signal } from '../Commands/Signals/Signal.js'; +import { BaseCoil } from '../Commands/Coils/BaseCoil.js'; +import { BaseNPCoil } from '../Commands/Coils/BaseNPCoil.js'; +import { Coil } from '../Commands/Coils/Coil.js'; +import { SCoil } from '../Commands/Coils/SCoil.js'; +import { RCoil } from '../Commands/Coils/RCoil.js'; +import { BaseOperationOrSignal } from '../Commands/BaseOperationOrSignal.js'; +import { CompareOperator } from '../Commands/Comparisons/CompareOperator.js'; +import { InRangeCall } from '../Commands/Comparisons/InRangeCall.js'; +import { OutRangeCall } from '../Commands/Comparisons/OutRangeCall.js'; +import { FunctionCall } from '../Commands/Functions/Base/FunctionCall.js'; +import { FunctionBlockCall } from '../Commands/Functions/Base/FunctionBlockCall.js'; +import { SystemFunctionCall } from '../Commands/Functions/Base/SystemFunctionCall.js'; +import { SystemFunctionBlockCall } from '../Commands/Functions/Base/SystemFunctionBlockCall.js'; +import { ArithmeticCall } from '../Commands/Functions/Arithmetic/ArithmeticCall.js'; +import { VariableArithmeticCall } from '../Commands/Functions/Arithmetic/VariableArithmeticCall.js'; +import { AckGlCall } from '../Commands/Functions/AckGlCall.js'; +import { CTUCall } from '../Commands/Functions/CTUCall.js'; +import { CTUDCall } from '../Commands/Functions/CTUDCall.js'; +import { tryGetParent } from '../Extensions/OperationOrSignalExtensions.js'; export class KopCodeHelper { static flattenOrdered(e: T[], f: (t: T) => T[]): T[] { @@ -218,7 +218,7 @@ export class KopCodeHelper { const idx = part.indexOf('[') + 1; if (idx > 0) { this._sb.appendLine(``); - const arrays = part.substring(idx, part.length - idx - 1); + const arrays = part.substring(idx, part.length - 1); if (arrays.includes('"')) { this._sb.appendLine(''); @@ -312,7 +312,7 @@ export class KopCodeHelper { const idx = instanceNamePart.indexOf('[') + 1; if (idx > 0) { this._sb.appendLine(``); - const arrays = instanceNamePart.substring(idx, instanceNamePart.length - idx - 1); + const arrays = instanceNamePart.substring(idx, instanceNamePart.length - 1); if (arrays.includes('"')) { this._sb.appendLine(''); @@ -818,14 +818,14 @@ export class KopCodeHelper { idRef.value++; this._sb.appendLine(''); this._sb.appendLine('de-DE'); - this._sb.appendLine(`${network.description}`); + this._sb.appendLine(`${network.description ?? ''}`); this._sb.appendLine(''); this._sb.appendLine(''); this._sb.appendLine(``); idRef.value++; this._sb.appendLine(''); this._sb.appendLine('en-GB'); - this._sb.appendLine(`${network.descriptionEnglish}`); + this._sb.appendLine(`${network.descriptionEnglish ?? ''}`); this._sb.appendLine(''); this._sb.appendLine(''); this._sb.appendLine(''); diff --git a/TiaCodegen-ts/src/Commands/And.ts b/TiaCodegen-ts/src/Commands/And.ts index 4948c91..bbc412d 100644 --- a/TiaCodegen-ts/src/Commands/And.ts +++ b/TiaCodegen-ts/src/Commands/And.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { BaseOperationOrSignal } from './BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { BaseOperationOrSignal } from './BaseOperationOrSignal.js'; export class And extends BaseOperationOrSignal { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/BaseOperationOrSignal.ts b/TiaCodegen-ts/src/Commands/BaseOperationOrSignal.ts index 057d33e..11b776f 100644 --- a/TiaCodegen-ts/src/Commands/BaseOperationOrSignal.ts +++ b/TiaCodegen-ts/src/Commands/BaseOperationOrSignal.ts @@ -1,4 +1,4 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; export abstract class BaseOperationOrSignal implements IOperationOrSignal { debugInfo: string | null = null; @@ -23,9 +23,10 @@ export abstract class BaseOperationOrSignal implements IOperationOrSignal { createContactAndFillCardinality(parent: IOperationOrSignal): number { this.cardinality = 1; - if (this.children.length > 0 && this.children[this.children.length - 1] instanceof Or) { - this.cardinality = this.children[this.children.length - 1].createContactAndFillCardinality(parent); - this.children[this.children.length - 1].doNotCreateContact = true; + const lastChild = this.children[this.children.length - 1]; + if (this.children.length > 0 && lastChild.constructor.name === 'Or') { + this.cardinality = lastChild.createContactAndFillCardinality(parent); + lastChild.doNotCreateContact = true; } return this.cardinality; } @@ -35,14 +36,15 @@ export abstract class BaseOperationOrSignal implements IOperationOrSignal { } toString(): string { - if (this instanceof And || this instanceof Or) { - return `${this.constructor.name} (${this.children.map(x => x.toString()).join(',')})`; + const name = this.constructor.name; + if (name === 'And' || name === 'Or') { + return `${name} (${this.children.map(x => x.toString()).join(',')})`; } - return this.constructor.name; + return name; } getFirstChildNotAnd(): IOperationOrSignal { - if (this instanceof And) { + if (this.constructor.name === 'And') { const ch1 = this.children[0]; if (ch1 instanceof BaseOperationOrSignal) { return ch1.getFirstChildNotAnd(); @@ -63,7 +65,3 @@ export abstract class BaseOperationOrSignal implements IOperationOrSignal { return inst; } } - -// Forward declarations to avoid circular imports - these are resolved at runtime -import { And } from './And'; -import { Or } from './Or'; diff --git a/TiaCodegen-ts/src/Commands/Coils/BaseCoil.ts b/TiaCodegen-ts/src/Commands/Coils/BaseCoil.ts index 8fc7b30..2a6e13a 100644 --- a/TiaCodegen-ts/src/Commands/Coils/BaseCoil.ts +++ b/TiaCodegen-ts/src/Commands/Coils/BaseCoil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { ICoil } from '../../Interfaces/ICoil'; -import { Signal } from '../Signals/Signal'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { ICoil } from '../../Interfaces/ICoil.js'; +import { Signal } from '../Signals/Signal.js'; export class BaseCoil implements IOperationOrSignal, ICoil { debugInfo: string | null = null; diff --git a/TiaCodegen-ts/src/Commands/Coils/BaseNPCoil.ts b/TiaCodegen-ts/src/Commands/Coils/BaseNPCoil.ts index 907c454..d9c09fb 100644 --- a/TiaCodegen-ts/src/Commands/Coils/BaseNPCoil.ts +++ b/TiaCodegen-ts/src/Commands/Coils/BaseNPCoil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { Signal } from '../Signals/Signal'; -import { BaseCoil } from './BaseCoil'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { Signal } from '../Signals/Signal.js'; +import { BaseCoil } from './BaseCoil.js'; export class BaseNPCoil extends BaseCoil { helpSignal: Signal | null; diff --git a/TiaCodegen-ts/src/Commands/Coils/Coil.ts b/TiaCodegen-ts/src/Commands/Coils/Coil.ts index b5b862d..8190377 100644 --- a/TiaCodegen-ts/src/Commands/Coils/Coil.ts +++ b/TiaCodegen-ts/src/Commands/Coils/Coil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { Signal } from '../Signals/Signal'; -import { BaseCoil } from './BaseCoil'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { Signal } from '../Signals/Signal.js'; +import { BaseCoil } from './BaseCoil.js'; export class Coil extends BaseCoil { constructor(signal: Signal, op: IOperationOrSignal | null = null) { diff --git a/TiaCodegen-ts/src/Commands/Coils/PCoil.ts b/TiaCodegen-ts/src/Commands/Coils/PCoil.ts index bcee6b4..4c1744b 100644 --- a/TiaCodegen-ts/src/Commands/Coils/PCoil.ts +++ b/TiaCodegen-ts/src/Commands/Coils/PCoil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { Signal } from '../Signals/Signal'; -import { BaseNPCoil } from './BaseNPCoil'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { Signal } from '../Signals/Signal.js'; +import { BaseNPCoil } from './BaseNPCoil.js'; export class PCoil extends BaseNPCoil { constructor(signal: Signal, helpSignal: Signal, op: IOperationOrSignal | null = null) { diff --git a/TiaCodegen-ts/src/Commands/Coils/RCoil.ts b/TiaCodegen-ts/src/Commands/Coils/RCoil.ts index 0329e1b..8c29bf9 100644 --- a/TiaCodegen-ts/src/Commands/Coils/RCoil.ts +++ b/TiaCodegen-ts/src/Commands/Coils/RCoil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { Signal } from '../Signals/Signal'; -import { BaseCoil } from './BaseCoil'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { Signal } from '../Signals/Signal.js'; +import { BaseCoil } from './BaseCoil.js'; export class RCoil extends BaseCoil { constructor(signal: Signal, op: IOperationOrSignal | null = null) { diff --git a/TiaCodegen-ts/src/Commands/Coils/SCoil.ts b/TiaCodegen-ts/src/Commands/Coils/SCoil.ts index bba4ee5..5569f14 100644 --- a/TiaCodegen-ts/src/Commands/Coils/SCoil.ts +++ b/TiaCodegen-ts/src/Commands/Coils/SCoil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { Signal } from '../Signals/Signal'; -import { BaseCoil } from './BaseCoil'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { Signal } from '../Signals/Signal.js'; +import { BaseCoil } from './BaseCoil.js'; export class SCoil extends BaseCoil { constructor(signal: Signal, op: IOperationOrSignal | null = null) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/CompareOperator.ts b/TiaCodegen-ts/src/Commands/Comparisons/CompareOperator.ts index c458647..49a501a 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/CompareOperator.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/CompareOperator.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { BaseOperationOrSignal } from '../BaseOperationOrSignal'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { BaseOperationOrSignal } from '../BaseOperationOrSignal.js'; export abstract class CompareOperator extends BaseOperationOrSignal { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/Eq.ts b/TiaCodegen-ts/src/Commands/Comparisons/Eq.ts index d6d6b20..c2c08fb 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/Eq.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/Eq.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { CompareOperator } from './CompareOperator'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { CompareOperator } from './CompareOperator.js'; export class Eq extends CompareOperator { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/Ge.ts b/TiaCodegen-ts/src/Commands/Comparisons/Ge.ts index 584ecf1..5f03313 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/Ge.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/Ge.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { CompareOperator } from './CompareOperator'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { CompareOperator } from './CompareOperator.js'; export class Ge extends CompareOperator { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/Gt.ts b/TiaCodegen-ts/src/Commands/Comparisons/Gt.ts index 2412406..8bc983c 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/Gt.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/Gt.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { CompareOperator } from './CompareOperator'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { CompareOperator } from './CompareOperator.js'; export class Gt extends CompareOperator { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/InRangeCall.ts b/TiaCodegen-ts/src/Commands/Comparisons/InRangeCall.ts index bd141bc..ea69e86 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/InRangeCall.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/InRangeCall.ts @@ -1,7 +1,7 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionCall } from '../Functions/Base/SystemFunctionCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionCall } from '../Functions/Base/SystemFunctionCall.js'; export class InRangeCall extends SystemFunctionCall { constructor( @@ -11,7 +11,7 @@ export class InRangeCall extends SystemFunctionCall { out: IOperationOrSignal, eno: IOperationOrSignal | null = null, ) { - super('InRange', eno); + super({ functionName: 'InRange', eno }); this.disableEno = false; this.iface['min'] = new IOperationOrSignalDirectionWrapper(min, Direction.Input); this.iface['in'] = new IOperationOrSignalDirectionWrapper(inParam, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Comparisons/Le.ts b/TiaCodegen-ts/src/Commands/Comparisons/Le.ts index 8d55b5f..ed9c420 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/Le.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/Le.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { CompareOperator } from './CompareOperator'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { CompareOperator } from './CompareOperator.js'; export class Le extends CompareOperator { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/Lt.ts b/TiaCodegen-ts/src/Commands/Comparisons/Lt.ts index ea1db20..d06b850 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/Lt.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/Lt.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { CompareOperator } from './CompareOperator'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { CompareOperator } from './CompareOperator.js'; export class Lt extends CompareOperator { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/Ne.ts b/TiaCodegen-ts/src/Commands/Comparisons/Ne.ts index b4403db..61b08d8 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/Ne.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/Ne.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { CompareOperator } from './CompareOperator'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { CompareOperator } from './CompareOperator.js'; export class Ne extends CompareOperator { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Comparisons/OutRangeCall.ts b/TiaCodegen-ts/src/Commands/Comparisons/OutRangeCall.ts index 5cb2dac..9c683e7 100644 --- a/TiaCodegen-ts/src/Commands/Comparisons/OutRangeCall.ts +++ b/TiaCodegen-ts/src/Commands/Comparisons/OutRangeCall.ts @@ -1,7 +1,7 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionCall } from '../Functions/Base/SystemFunctionCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionCall } from '../Functions/Base/SystemFunctionCall.js'; export class OutRangeCall extends SystemFunctionCall { constructor( @@ -11,7 +11,7 @@ export class OutRangeCall extends SystemFunctionCall { out: IOperationOrSignal, eno: IOperationOrSignal | null = null, ) { - super('OutRange', eno); + super({ functionName: 'OutRange', eno }); this.disableEno = false; this.iface['min'] = new IOperationOrSignalDirectionWrapper(min, Direction.Input); this.iface['in'] = new IOperationOrSignalDirectionWrapper(inParam, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Convert.ts b/TiaCodegen-ts/src/Commands/Convert.ts index 7e6ab78..ebbfe3c 100644 --- a/TiaCodegen-ts/src/Commands/Convert.ts +++ b/TiaCodegen-ts/src/Commands/Convert.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { IFunctionOperation } from '../Interfaces/IFunctionOperation'; -import { BaseOperationOrSignal } from './BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { IFunctionOperation } from '../Interfaces/IFunctionOperation.js'; +import { BaseOperationOrSignal } from './BaseOperationOrSignal.js'; export class Convert extends BaseOperationOrSignal implements IFunctionOperation { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Distributor.ts b/TiaCodegen-ts/src/Commands/Distributor.ts index 632fc13..4c30820 100644 --- a/TiaCodegen-ts/src/Commands/Distributor.ts +++ b/TiaCodegen-ts/src/Commands/Distributor.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { BaseOperationOrSignal } from './BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { BaseOperationOrSignal } from './BaseOperationOrSignal.js'; export class Distributor extends BaseOperationOrSignal { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Functions/AckGlCall.ts b/TiaCodegen-ts/src/Commands/Functions/AckGlCall.ts index 4a14d9a..263b69c 100644 --- a/TiaCodegen-ts/src/Commands/Functions/AckGlCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/AckGlCall.ts @@ -1,15 +1,18 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface AckGlCallOptions { + instanceName: string; + ackGlob?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class AckGlCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - ackGlob: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('ACK_GL', instanceName, eno); + constructor(options: AckGlCallOptions) { + const { instanceName, ackGlob = null, eno = null } = options; + super({ functionName: 'ACK_GL', instanceName, eno }); this.iface['ACK_GLOB'] = new IOperationOrSignalDirectionWrapper(ackGlob, Direction.Input); this.additionalSafetyTemplateValues = ` diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/AddCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/AddCall.ts index 466c9ff..adb341d 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/AddCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/AddCall.ts @@ -1,117 +1,75 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../../Enums/Direction'; -import { VariableArithmeticCall } from './VariableArithmeticCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; +import { VariableArithmeticCall } from './VariableArithmeticCall.js'; +import { numericType } from './ArithmeticCall.js'; + +export interface AddCallOptions { + type: numericType; + in1: IOperationOrSignal; + in2: IOperationOrSignal; + in3?: IOperationOrSignal | null; + in4?: IOperationOrSignal | null; + in5?: IOperationOrSignal | null; + in6?: IOperationOrSignal | null; + in7?: IOperationOrSignal | null; + in8?: IOperationOrSignal | null; + in9?: IOperationOrSignal | null; + in10?: IOperationOrSignal | null; + in11?: IOperationOrSignal | null; + in12?: IOperationOrSignal | null; + in13?: IOperationOrSignal | null; + in14?: IOperationOrSignal | null; + in15?: IOperationOrSignal | null; + in16?: IOperationOrSignal | null; + in17?: IOperationOrSignal | null; + in18?: IOperationOrSignal | null; + in19?: IOperationOrSignal | null; + in20?: IOperationOrSignal | null; + in21?: IOperationOrSignal | null; + in22?: IOperationOrSignal | null; + in23?: IOperationOrSignal | null; + in24?: IOperationOrSignal | null; + in25?: IOperationOrSignal | null; + in26?: IOperationOrSignal | null; + in27?: IOperationOrSignal | null; + in28?: IOperationOrSignal | null; + in29?: IOperationOrSignal | null; + in30?: IOperationOrSignal | null; + in31?: IOperationOrSignal | null; + in32?: IOperationOrSignal | null; + in33?: IOperationOrSignal | null; + in34?: IOperationOrSignal | null; + in35?: IOperationOrSignal | null; + in36?: IOperationOrSignal | null; + in37?: IOperationOrSignal | null; + in38?: IOperationOrSignal | null; + in39?: IOperationOrSignal | null; + in40?: IOperationOrSignal | null; + in41?: IOperationOrSignal | null; + in42?: IOperationOrSignal | null; + in43?: IOperationOrSignal | null; + in44?: IOperationOrSignal | null; + in45?: IOperationOrSignal | null; + in46?: IOperationOrSignal | null; + in47?: IOperationOrSignal | null; + in48?: IOperationOrSignal | null; + in49?: IOperationOrSignal | null; + in50?: IOperationOrSignal | null; + out1?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class AddCall extends VariableArithmeticCall { - constructor( - type: string, - in1: IOperationOrSignal, - in2: IOperationOrSignal, - in3: IOperationOrSignal | null = null, - in4: IOperationOrSignal | null = null, - in5: IOperationOrSignal | null = null, - in6: IOperationOrSignal | null = null, - in7: IOperationOrSignal | null = null, - in8: IOperationOrSignal | null = null, - in9: IOperationOrSignal | null = null, - in10: IOperationOrSignal | null = null, - in11: IOperationOrSignal | null = null, - in12: IOperationOrSignal | null = null, - in13: IOperationOrSignal | null = null, - in14: IOperationOrSignal | null = null, - in15: IOperationOrSignal | null = null, - in16: IOperationOrSignal | null = null, - in17: IOperationOrSignal | null = null, - in18: IOperationOrSignal | null = null, - in19: IOperationOrSignal | null = null, - in20: IOperationOrSignal | null = null, - in21: IOperationOrSignal | null = null, - in22: IOperationOrSignal | null = null, - in23: IOperationOrSignal | null = null, - in24: IOperationOrSignal | null = null, - in25: IOperationOrSignal | null = null, - in26: IOperationOrSignal | null = null, - in27: IOperationOrSignal | null = null, - in28: IOperationOrSignal | null = null, - in29: IOperationOrSignal | null = null, - in30: IOperationOrSignal | null = null, - in31: IOperationOrSignal | null = null, - in32: IOperationOrSignal | null = null, - in33: IOperationOrSignal | null = null, - in34: IOperationOrSignal | null = null, - in35: IOperationOrSignal | null = null, - in36: IOperationOrSignal | null = null, - in37: IOperationOrSignal | null = null, - in38: IOperationOrSignal | null = null, - in39: IOperationOrSignal | null = null, - in40: IOperationOrSignal | null = null, - in41: IOperationOrSignal | null = null, - in42: IOperationOrSignal | null = null, - in43: IOperationOrSignal | null = null, - in44: IOperationOrSignal | null = null, - in45: IOperationOrSignal | null = null, - in46: IOperationOrSignal | null = null, - in47: IOperationOrSignal | null = null, - in48: IOperationOrSignal | null = null, - in49: IOperationOrSignal | null = null, - in50: IOperationOrSignal | null = null, - out1: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('Add', eno); + constructor(options: AddCallOptions) { + const { type, in1, in2, out1 = null, eno = null } = options; + super({ functionName: 'Add', eno }); this.disableEno = true; this.type = type; this.iface['IN1'] = new IOperationOrSignalDirectionWrapper(in1, Direction.Input); this.iface['IN2'] = new IOperationOrSignalDirectionWrapper(in2, Direction.Input); - this.iface['IN3'] = new IOperationOrSignalDirectionWrapper(in3, Direction.Input); - this.iface['IN4'] = new IOperationOrSignalDirectionWrapper(in4, Direction.Input); - this.iface['IN5'] = new IOperationOrSignalDirectionWrapper(in5, Direction.Input); - this.iface['IN6'] = new IOperationOrSignalDirectionWrapper(in6, Direction.Input); - this.iface['IN7'] = new IOperationOrSignalDirectionWrapper(in7, Direction.Input); - this.iface['IN8'] = new IOperationOrSignalDirectionWrapper(in8, Direction.Input); - this.iface['IN9'] = new IOperationOrSignalDirectionWrapper(in9, Direction.Input); - this.iface['IN10'] = new IOperationOrSignalDirectionWrapper(in10, Direction.Input); - this.iface['IN11'] = new IOperationOrSignalDirectionWrapper(in11, Direction.Input); - this.iface['IN12'] = new IOperationOrSignalDirectionWrapper(in12, Direction.Input); - this.iface['IN13'] = new IOperationOrSignalDirectionWrapper(in13, Direction.Input); - this.iface['IN14'] = new IOperationOrSignalDirectionWrapper(in14, Direction.Input); - this.iface['IN15'] = new IOperationOrSignalDirectionWrapper(in15, Direction.Input); - this.iface['IN16'] = new IOperationOrSignalDirectionWrapper(in16, Direction.Input); - this.iface['IN17'] = new IOperationOrSignalDirectionWrapper(in17, Direction.Input); - this.iface['IN18'] = new IOperationOrSignalDirectionWrapper(in18, Direction.Input); - this.iface['IN19'] = new IOperationOrSignalDirectionWrapper(in19, Direction.Input); - this.iface['IN20'] = new IOperationOrSignalDirectionWrapper(in20, Direction.Input); - this.iface['IN21'] = new IOperationOrSignalDirectionWrapper(in21, Direction.Input); - this.iface['IN22'] = new IOperationOrSignalDirectionWrapper(in22, Direction.Input); - this.iface['IN23'] = new IOperationOrSignalDirectionWrapper(in23, Direction.Input); - this.iface['IN24'] = new IOperationOrSignalDirectionWrapper(in24, Direction.Input); - this.iface['IN25'] = new IOperationOrSignalDirectionWrapper(in25, Direction.Input); - this.iface['IN26'] = new IOperationOrSignalDirectionWrapper(in26, Direction.Input); - this.iface['IN27'] = new IOperationOrSignalDirectionWrapper(in27, Direction.Input); - this.iface['IN28'] = new IOperationOrSignalDirectionWrapper(in28, Direction.Input); - this.iface['IN29'] = new IOperationOrSignalDirectionWrapper(in29, Direction.Input); - this.iface['IN30'] = new IOperationOrSignalDirectionWrapper(in30, Direction.Input); - this.iface['IN31'] = new IOperationOrSignalDirectionWrapper(in31, Direction.Input); - this.iface['IN32'] = new IOperationOrSignalDirectionWrapper(in32, Direction.Input); - this.iface['IN33'] = new IOperationOrSignalDirectionWrapper(in33, Direction.Input); - this.iface['IN34'] = new IOperationOrSignalDirectionWrapper(in34, Direction.Input); - this.iface['IN35'] = new IOperationOrSignalDirectionWrapper(in35, Direction.Input); - this.iface['IN36'] = new IOperationOrSignalDirectionWrapper(in36, Direction.Input); - this.iface['IN37'] = new IOperationOrSignalDirectionWrapper(in37, Direction.Input); - this.iface['IN38'] = new IOperationOrSignalDirectionWrapper(in38, Direction.Input); - this.iface['IN39'] = new IOperationOrSignalDirectionWrapper(in39, Direction.Input); - this.iface['IN40'] = new IOperationOrSignalDirectionWrapper(in40, Direction.Input); - this.iface['IN41'] = new IOperationOrSignalDirectionWrapper(in41, Direction.Input); - this.iface['IN42'] = new IOperationOrSignalDirectionWrapper(in42, Direction.Input); - this.iface['IN43'] = new IOperationOrSignalDirectionWrapper(in43, Direction.Input); - this.iface['IN44'] = new IOperationOrSignalDirectionWrapper(in44, Direction.Input); - this.iface['IN45'] = new IOperationOrSignalDirectionWrapper(in45, Direction.Input); - this.iface['IN46'] = new IOperationOrSignalDirectionWrapper(in46, Direction.Input); - this.iface['IN47'] = new IOperationOrSignalDirectionWrapper(in47, Direction.Input); - this.iface['IN48'] = new IOperationOrSignalDirectionWrapper(in48, Direction.Input); - this.iface['IN49'] = new IOperationOrSignalDirectionWrapper(in49, Direction.Input); - this.iface['IN50'] = new IOperationOrSignalDirectionWrapper(in50, Direction.Input); + //@ts-ignore + this.addVariableInputs(options, 3, 50); this.iface['OUT'] = new IOperationOrSignalDirectionWrapper(out1, Direction.Output); for (const w of Object.values(this.iface)) { diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ArithmeticCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ArithmeticCall.ts index eee7a97..31ddf06 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ArithmeticCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ArithmeticCall.ts @@ -1,10 +1,13 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { SystemFunctionCall } from '../Base/SystemFunctionCall'; +import { SystemFunctionCall, SystemFunctionCallOptions } from '../Base/SystemFunctionCall.js'; + +export interface ArithmeticCallOptions extends SystemFunctionCallOptions { } + +export type numericType = "Int" | "DInt" | "LInt" | "UInt" | "UDInt" | "ULInt" | "Real"; export abstract class ArithmeticCall extends SystemFunctionCall { - type: string = ''; + type?: numericType = 'Int'; - constructor(functionName: string, eno: IOperationOrSignal | null = null) { - super(functionName, eno); + constructor(options: ArithmeticCallOptions) { + super(options); } } diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/DivCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/DivCall.ts index 26b9c32..d331cf5 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/DivCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/DivCall.ts @@ -1,17 +1,20 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../../Enums/Direction'; -import { ArithmeticCall } from './ArithmeticCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; +import { ArithmeticCall, numericType } from './ArithmeticCall.js'; + +export interface DivCallOptions { + type: numericType; + in1: IOperationOrSignal; + in2: IOperationOrSignal; + out1?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class DivCall extends ArithmeticCall { - constructor( - type: string, - in1: IOperationOrSignal, - in2: IOperationOrSignal, - out1: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('Div', eno); + constructor(options: DivCallOptions) { + const { type, in1, in2, out1 = null, eno = null } = options; + super({ functionName: 'Div', eno }); this.disableEno = true; this.type = type; this.iface['IN1'] = new IOperationOrSignalDirectionWrapper(in1, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ModCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ModCall.ts index 0b24db0..1575d1b 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ModCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/ModCall.ts @@ -1,17 +1,20 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../../Enums/Direction'; -import { ArithmeticCall } from './ArithmeticCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; +import { ArithmeticCall, numericType } from './ArithmeticCall.js'; + +export interface ModCallOptions { + type: numericType; + in1: IOperationOrSignal; + in2: IOperationOrSignal; + out1?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class ModCall extends ArithmeticCall { - constructor( - type: string, - in1: IOperationOrSignal, - in2: IOperationOrSignal, - out1: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('Mod', eno); + constructor(options: ModCallOptions) { + const { type, in1, in2, out1 = null, eno = null } = options; + super({ functionName: 'Mod', eno }); this.disableEno = true; this.type = type; this.iface['IN1'] = new IOperationOrSignalDirectionWrapper(in1, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/MulCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/MulCall.ts index e8e681e..e992a87 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/MulCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/MulCall.ts @@ -1,117 +1,75 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../../Enums/Direction'; -import { VariableArithmeticCall } from './VariableArithmeticCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; +import { VariableArithmeticCall } from './VariableArithmeticCall.js'; +import { numericType } from './ArithmeticCall.js'; + +export interface MulCallOptions { + type: numericType; + in1: IOperationOrSignal; + in2: IOperationOrSignal; + in3?: IOperationOrSignal | null; + in4?: IOperationOrSignal | null; + in5?: IOperationOrSignal | null; + in6?: IOperationOrSignal | null; + in7?: IOperationOrSignal | null; + in8?: IOperationOrSignal | null; + in9?: IOperationOrSignal | null; + in10?: IOperationOrSignal | null; + in11?: IOperationOrSignal | null; + in12?: IOperationOrSignal | null; + in13?: IOperationOrSignal | null; + in14?: IOperationOrSignal | null; + in15?: IOperationOrSignal | null; + in16?: IOperationOrSignal | null; + in17?: IOperationOrSignal | null; + in18?: IOperationOrSignal | null; + in19?: IOperationOrSignal | null; + in20?: IOperationOrSignal | null; + in21?: IOperationOrSignal | null; + in22?: IOperationOrSignal | null; + in23?: IOperationOrSignal | null; + in24?: IOperationOrSignal | null; + in25?: IOperationOrSignal | null; + in26?: IOperationOrSignal | null; + in27?: IOperationOrSignal | null; + in28?: IOperationOrSignal | null; + in29?: IOperationOrSignal | null; + in30?: IOperationOrSignal | null; + in31?: IOperationOrSignal | null; + in32?: IOperationOrSignal | null; + in33?: IOperationOrSignal | null; + in34?: IOperationOrSignal | null; + in35?: IOperationOrSignal | null; + in36?: IOperationOrSignal | null; + in37?: IOperationOrSignal | null; + in38?: IOperationOrSignal | null; + in39?: IOperationOrSignal | null; + in40?: IOperationOrSignal | null; + in41?: IOperationOrSignal | null; + in42?: IOperationOrSignal | null; + in43?: IOperationOrSignal | null; + in44?: IOperationOrSignal | null; + in45?: IOperationOrSignal | null; + in46?: IOperationOrSignal | null; + in47?: IOperationOrSignal | null; + in48?: IOperationOrSignal | null; + in49?: IOperationOrSignal | null; + in50?: IOperationOrSignal | null; + out1?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class MulCall extends VariableArithmeticCall { - constructor( - type: string, - in1: IOperationOrSignal, - in2: IOperationOrSignal, - in3: IOperationOrSignal | null = null, - in4: IOperationOrSignal | null = null, - in5: IOperationOrSignal | null = null, - in6: IOperationOrSignal | null = null, - in7: IOperationOrSignal | null = null, - in8: IOperationOrSignal | null = null, - in9: IOperationOrSignal | null = null, - in10: IOperationOrSignal | null = null, - in11: IOperationOrSignal | null = null, - in12: IOperationOrSignal | null = null, - in13: IOperationOrSignal | null = null, - in14: IOperationOrSignal | null = null, - in15: IOperationOrSignal | null = null, - in16: IOperationOrSignal | null = null, - in17: IOperationOrSignal | null = null, - in18: IOperationOrSignal | null = null, - in19: IOperationOrSignal | null = null, - in20: IOperationOrSignal | null = null, - in21: IOperationOrSignal | null = null, - in22: IOperationOrSignal | null = null, - in23: IOperationOrSignal | null = null, - in24: IOperationOrSignal | null = null, - in25: IOperationOrSignal | null = null, - in26: IOperationOrSignal | null = null, - in27: IOperationOrSignal | null = null, - in28: IOperationOrSignal | null = null, - in29: IOperationOrSignal | null = null, - in30: IOperationOrSignal | null = null, - in31: IOperationOrSignal | null = null, - in32: IOperationOrSignal | null = null, - in33: IOperationOrSignal | null = null, - in34: IOperationOrSignal | null = null, - in35: IOperationOrSignal | null = null, - in36: IOperationOrSignal | null = null, - in37: IOperationOrSignal | null = null, - in38: IOperationOrSignal | null = null, - in39: IOperationOrSignal | null = null, - in40: IOperationOrSignal | null = null, - in41: IOperationOrSignal | null = null, - in42: IOperationOrSignal | null = null, - in43: IOperationOrSignal | null = null, - in44: IOperationOrSignal | null = null, - in45: IOperationOrSignal | null = null, - in46: IOperationOrSignal | null = null, - in47: IOperationOrSignal | null = null, - in48: IOperationOrSignal | null = null, - in49: IOperationOrSignal | null = null, - in50: IOperationOrSignal | null = null, - out1: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('Mul', eno); + constructor(options: MulCallOptions) { + const { type, in1, in2, out1 = null, eno = null } = options; + super({ functionName: 'Mul', eno }); this.disableEno = true; this.type = type; this.iface['IN1'] = new IOperationOrSignalDirectionWrapper(in1, Direction.Input); this.iface['IN2'] = new IOperationOrSignalDirectionWrapper(in2, Direction.Input); - this.iface['IN3'] = new IOperationOrSignalDirectionWrapper(in3, Direction.Input); - this.iface['IN4'] = new IOperationOrSignalDirectionWrapper(in4, Direction.Input); - this.iface['IN5'] = new IOperationOrSignalDirectionWrapper(in5, Direction.Input); - this.iface['IN6'] = new IOperationOrSignalDirectionWrapper(in6, Direction.Input); - this.iface['IN7'] = new IOperationOrSignalDirectionWrapper(in7, Direction.Input); - this.iface['IN8'] = new IOperationOrSignalDirectionWrapper(in8, Direction.Input); - this.iface['IN9'] = new IOperationOrSignalDirectionWrapper(in9, Direction.Input); - this.iface['IN10'] = new IOperationOrSignalDirectionWrapper(in10, Direction.Input); - this.iface['IN11'] = new IOperationOrSignalDirectionWrapper(in11, Direction.Input); - this.iface['IN12'] = new IOperationOrSignalDirectionWrapper(in12, Direction.Input); - this.iface['IN13'] = new IOperationOrSignalDirectionWrapper(in13, Direction.Input); - this.iface['IN14'] = new IOperationOrSignalDirectionWrapper(in14, Direction.Input); - this.iface['IN15'] = new IOperationOrSignalDirectionWrapper(in15, Direction.Input); - this.iface['IN16'] = new IOperationOrSignalDirectionWrapper(in16, Direction.Input); - this.iface['IN17'] = new IOperationOrSignalDirectionWrapper(in17, Direction.Input); - this.iface['IN18'] = new IOperationOrSignalDirectionWrapper(in18, Direction.Input); - this.iface['IN19'] = new IOperationOrSignalDirectionWrapper(in19, Direction.Input); - this.iface['IN20'] = new IOperationOrSignalDirectionWrapper(in20, Direction.Input); - this.iface['IN21'] = new IOperationOrSignalDirectionWrapper(in21, Direction.Input); - this.iface['IN22'] = new IOperationOrSignalDirectionWrapper(in22, Direction.Input); - this.iface['IN23'] = new IOperationOrSignalDirectionWrapper(in23, Direction.Input); - this.iface['IN24'] = new IOperationOrSignalDirectionWrapper(in24, Direction.Input); - this.iface['IN25'] = new IOperationOrSignalDirectionWrapper(in25, Direction.Input); - this.iface['IN26'] = new IOperationOrSignalDirectionWrapper(in26, Direction.Input); - this.iface['IN27'] = new IOperationOrSignalDirectionWrapper(in27, Direction.Input); - this.iface['IN28'] = new IOperationOrSignalDirectionWrapper(in28, Direction.Input); - this.iface['IN29'] = new IOperationOrSignalDirectionWrapper(in29, Direction.Input); - this.iface['IN30'] = new IOperationOrSignalDirectionWrapper(in30, Direction.Input); - this.iface['IN31'] = new IOperationOrSignalDirectionWrapper(in31, Direction.Input); - this.iface['IN32'] = new IOperationOrSignalDirectionWrapper(in32, Direction.Input); - this.iface['IN33'] = new IOperationOrSignalDirectionWrapper(in33, Direction.Input); - this.iface['IN34'] = new IOperationOrSignalDirectionWrapper(in34, Direction.Input); - this.iface['IN35'] = new IOperationOrSignalDirectionWrapper(in35, Direction.Input); - this.iface['IN36'] = new IOperationOrSignalDirectionWrapper(in36, Direction.Input); - this.iface['IN37'] = new IOperationOrSignalDirectionWrapper(in37, Direction.Input); - this.iface['IN38'] = new IOperationOrSignalDirectionWrapper(in38, Direction.Input); - this.iface['IN39'] = new IOperationOrSignalDirectionWrapper(in39, Direction.Input); - this.iface['IN40'] = new IOperationOrSignalDirectionWrapper(in40, Direction.Input); - this.iface['IN41'] = new IOperationOrSignalDirectionWrapper(in41, Direction.Input); - this.iface['IN42'] = new IOperationOrSignalDirectionWrapper(in42, Direction.Input); - this.iface['IN43'] = new IOperationOrSignalDirectionWrapper(in43, Direction.Input); - this.iface['IN44'] = new IOperationOrSignalDirectionWrapper(in44, Direction.Input); - this.iface['IN45'] = new IOperationOrSignalDirectionWrapper(in45, Direction.Input); - this.iface['IN46'] = new IOperationOrSignalDirectionWrapper(in46, Direction.Input); - this.iface['IN47'] = new IOperationOrSignalDirectionWrapper(in47, Direction.Input); - this.iface['IN48'] = new IOperationOrSignalDirectionWrapper(in48, Direction.Input); - this.iface['IN49'] = new IOperationOrSignalDirectionWrapper(in49, Direction.Input); - this.iface['IN50'] = new IOperationOrSignalDirectionWrapper(in50, Direction.Input); + //@ts-ignore + this.addVariableInputs(options, 3, 50); this.iface['OUT'] = new IOperationOrSignalDirectionWrapper(out1, Direction.Output); for (const w of Object.values(this.iface)) { diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/SubCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/SubCall.ts index 9567653..2a87aa2 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/SubCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/SubCall.ts @@ -1,17 +1,20 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../../Enums/Direction'; -import { ArithmeticCall } from './ArithmeticCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; +import { ArithmeticCall, numericType } from './ArithmeticCall.js'; + +export interface SubCallOptions { + type: numericType; + in1: IOperationOrSignal; + in2: IOperationOrSignal; + out1?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class SubCall extends ArithmeticCall { - constructor( - type: string, - in1: IOperationOrSignal, - in2: IOperationOrSignal, - out1: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('Sub', eno); + constructor(options: SubCallOptions) { + const { type, in1, in2, out1 = null, eno = null } = options; + super({ functionName: 'Sub', eno }); this.disableEno = true; this.type = type; this.iface['IN1'] = new IOperationOrSignalDirectionWrapper(in1, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/VariableArithmeticCall.ts b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/VariableArithmeticCall.ts index 942985c..1cd7bda 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Arithmetic/VariableArithmeticCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Arithmetic/VariableArithmeticCall.ts @@ -1,8 +1,23 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { ArithmeticCall } from './ArithmeticCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; +import { ArithmeticCall, ArithmeticCallOptions } from './ArithmeticCall.js'; + +export interface VariableArithmeticCallOptions extends ArithmeticCallOptions { } export abstract class VariableArithmeticCall extends ArithmeticCall { - constructor(functionName: string, eno: IOperationOrSignal | null = null) { - super(functionName, eno); + constructor(options: VariableArithmeticCallOptions) { + super(options); + } + + protected addVariableInputs( + options: Record, + startIndex: number, + endIndex: number + ): void { + for (let i = startIndex; i <= endIndex; i++) { + const value = ((options as Record)[`in${i}`] as IOperationOrSignal | null | undefined) ?? null; + this.iface[`IN${i}`] = new IOperationOrSignalDirectionWrapper(value, Direction.Input); + } } } diff --git a/TiaCodegen-ts/src/Commands/Functions/Base/FunctionBlockCall.ts b/TiaCodegen-ts/src/Commands/Functions/Base/FunctionBlockCall.ts index 6379d32..bb09961 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Base/FunctionBlockCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Base/FunctionBlockCall.ts @@ -1,11 +1,18 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { FunctionCall } from './FunctionCall'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { FunctionCall } from './FunctionCall.js'; + +export interface FunctionBlockCallOptions { + functionName: string; + instanceName: string; + eno?: IOperationOrSignal | null; +} export class FunctionBlockCall extends FunctionCall { instanceName: string; - constructor(functionName: string, instanceName: string, eno: IOperationOrSignal | null = null) { - super(functionName, eno); + constructor(options: FunctionBlockCallOptions) { + const { functionName, instanceName, eno = null } = options; + super({ functionName, eno }); this.instanceName = instanceName; } } diff --git a/TiaCodegen-ts/src/Commands/Functions/Base/FunctionCall.ts b/TiaCodegen-ts/src/Commands/Functions/Base/FunctionCall.ts index 27f24a3..402802b 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Base/FunctionCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Base/FunctionCall.ts @@ -1,6 +1,11 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../../Enums/Direction'; +import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../../Enums/Direction.js'; + +export interface FunctionCallOptions { + functionName: string; + eno?: IOperationOrSignal | null; +} export class FunctionCall implements IOperationOrSignal { safetyTemplateString: string | null = null; @@ -20,7 +25,8 @@ export class FunctionCall implements IOperationOrSignal { cardinality: number = 0; hasNoEn: boolean = false; - constructor(functionName: string, eno: IOperationOrSignal | null = null) { + constructor(options: FunctionCallOptions) { + const { functionName, eno = null } = options; this.functionName = functionName; this.iface = {}; this.children = []; diff --git a/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionBlockCall.ts b/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionBlockCall.ts index 4fcaf2a..207e588 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionBlockCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionBlockCall.ts @@ -1,12 +1,13 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { FunctionBlockCall } from './FunctionBlockCall'; +import { FunctionBlockCall, FunctionBlockCallOptions } from './FunctionBlockCall.js'; + +export interface SystemFunctionBlockCallOptions extends FunctionBlockCallOptions {} export class SystemFunctionBlockCall extends FunctionBlockCall { templateValueName: string | null = null; templateValueType: string | null = null; templateValue: string | null = null; - constructor(functionName: string, instanceName: string, eno: IOperationOrSignal | null = null) { - super(functionName, instanceName, eno); + constructor(options: SystemFunctionBlockCallOptions) { + super(options); } } diff --git a/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionCall.ts b/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionCall.ts index 9b7fed5..312f773 100644 --- a/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/Base/SystemFunctionCall.ts @@ -1,8 +1,9 @@ -import { IOperationOrSignal } from '../../../Interfaces/IOperationOrSignal'; -import { FunctionCall } from './FunctionCall'; +import { FunctionCall, FunctionCallOptions } from './FunctionCall.js'; + +export interface SystemFunctionCallOptions extends FunctionCallOptions {} export class SystemFunctionCall extends FunctionCall { - constructor(functionName: string, eno: IOperationOrSignal | null = null) { - super(functionName, eno); + constructor(options: SystemFunctionCallOptions) { + super(options); } } diff --git a/TiaCodegen-ts/src/Commands/Functions/CTUCall.ts b/TiaCodegen-ts/src/Commands/Functions/CTUCall.ts index b46853c..7293cee 100644 --- a/TiaCodegen-ts/src/Commands/Functions/CTUCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/CTUCall.ts @@ -1,18 +1,21 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface CTUCallOptions { + instanceName: string; + r?: IOperationOrSignal | null; + pv?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + cv?: IOperationOrSignal | null; + templateValue?: string; +} export class CTUCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - r: IOperationOrSignal | null = null, - pv: IOperationOrSignal | null = null, - q: IOperationOrSignal | null = null, - cv: IOperationOrSignal | null = null, - templateValue: string = 'Int', - ) { - super('CTU', instanceName, null); + constructor(options: CTUCallOptions) { + const { instanceName, r = null, pv = null, q = null, cv = null, templateValue = 'Int' } = options; + super({ functionName: 'CTU', instanceName }); this.iface['R'] = new IOperationOrSignalDirectionWrapper(r, Direction.Input); this.iface['PV'] = new IOperationOrSignalDirectionWrapper(pv, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Functions/CTUDCall.ts b/TiaCodegen-ts/src/Commands/Functions/CTUDCall.ts index 47d2d95..5649588 100644 --- a/TiaCodegen-ts/src/Commands/Functions/CTUDCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/CTUDCall.ts @@ -1,21 +1,24 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface CTUDCallOptions { + instanceName: string; + cd?: IOperationOrSignal | null; + r?: IOperationOrSignal | null; + ld?: IOperationOrSignal | null; + pv?: IOperationOrSignal | null; + qu?: IOperationOrSignal | null; + qd?: IOperationOrSignal | null; + cv?: IOperationOrSignal | null; + templateValue?: string; +} export class CTUDCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - cd: IOperationOrSignal | null = null, - r: IOperationOrSignal | null = null, - ld: IOperationOrSignal | null = null, - pv: IOperationOrSignal | null = null, - qu: IOperationOrSignal | null = null, - qd: IOperationOrSignal | null = null, - cv: IOperationOrSignal | null = null, - templateValue: string = 'Int', - ) { - super('CTUD', instanceName, null); + constructor(options: CTUDCallOptions) { + const { instanceName, cd = null, r = null, ld = null, pv = null, qu = null, qd = null, cv = null, templateValue = 'Int' } = options; + super({ functionName: 'CTUD', instanceName }); this.iface['CD'] = new IOperationOrSignalDirectionWrapper(cd, Direction.Input); this.iface['R'] = new IOperationOrSignalDirectionWrapper(r, Direction.Input); this.iface['LD'] = new IOperationOrSignalDirectionWrapper(ld, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Functions/FDBACKCall.ts b/TiaCodegen-ts/src/Commands/Functions/FDBACKCall.ts index a311a50..09bbb29 100644 --- a/TiaCodegen-ts/src/Commands/Functions/FDBACKCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/FDBACKCall.ts @@ -1,23 +1,38 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface FDBACKCallOptions { + instanceName: string; + on?: IOperationOrSignal | null; + feedback?: IOperationOrSignal | null; + qbad_fio?: IOperationOrSignal | null; + ack_nec?: IOperationOrSignal | null; + ack?: IOperationOrSignal | null; + fdb_time?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + error?: IOperationOrSignal | null; + ack_req?: IOperationOrSignal | null; + diag?: IOperationOrSignal | null; +} export class FDBACKCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - on: IOperationOrSignal | null = null, - feedback: IOperationOrSignal | null = null, - qbad_fio: IOperationOrSignal | null = null, - ack_nec: IOperationOrSignal | null = null, - ack: IOperationOrSignal | null = null, - fdb_time: IOperationOrSignal | null = null, - q: IOperationOrSignal | null = null, - error: IOperationOrSignal | null = null, - ack_req: IOperationOrSignal | null = null, - diag: IOperationOrSignal | null = null, - ) { - super('FDBACK', instanceName, null); + constructor(options: FDBACKCallOptions) { + const { + instanceName, + on = null, + feedback = null, + qbad_fio = null, + ack_nec = null, + ack = null, + fdb_time = null, + q = null, + error = null, + ack_req = null, + diag = null, + } = options; + super({ functionName: 'FDBACK', instanceName }); this.iface['ON'] = new IOperationOrSignalDirectionWrapper(on, Direction.Input); this.iface['FEEDBACK'] = new IOperationOrSignalDirectionWrapper(feedback, Direction.Input); this.iface['QBAD_FIO'] = new IOperationOrSignalDirectionWrapper(qbad_fio, Direction.Input); diff --git a/TiaCodegen-ts/src/Commands/Functions/FTrigCall.ts b/TiaCodegen-ts/src/Commands/Functions/FTrigCall.ts index 7073a98..39d91a3 100644 --- a/TiaCodegen-ts/src/Commands/Functions/FTrigCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/FTrigCall.ts @@ -1,16 +1,19 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface FTrigCallOptions { + instanceName: string; + clk?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class FTrigCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - clk: IOperationOrSignal | null = null, - q: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('F_TRIG', instanceName, eno); + constructor(options: FTrigCallOptions) { + const { instanceName, clk = null, q = null, eno = null } = options; + super({ functionName: 'F_TRIG', instanceName, eno }); this.iface['CLK'] = new IOperationOrSignalDirectionWrapper(clk, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Functions/NTrigCall.ts b/TiaCodegen-ts/src/Commands/Functions/NTrigCall.ts index fbd4ed0..c63caf8 100644 --- a/TiaCodegen-ts/src/Commands/Functions/NTrigCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/NTrigCall.ts @@ -1,11 +1,16 @@ -import { Signal } from '../Signals/Signal'; -import { IPartName } from '../../Interfaces/IPartName'; -import { BaseNPCoil } from '../Coils/BaseNPCoil'; +import { Signal } from '../Signals/Signal.js'; +import { IPartName } from '../../Interfaces/IPartName.js'; +import { BaseNPCoil } from '../Coils/BaseNPCoil.js'; + +export interface NTrigCallOptions { + signal: Signal; +} export class NTrigCall extends BaseNPCoil implements IPartName { partName: string; - constructor(signal: Signal) { + constructor(options: NTrigCallOptions) { + const { signal } = options; super(signal, null, null); this.partName = 'NBox'; } diff --git a/TiaCodegen-ts/src/Commands/Functions/PTrigCall.ts b/TiaCodegen-ts/src/Commands/Functions/PTrigCall.ts index 22e4b89..d4e5942 100644 --- a/TiaCodegen-ts/src/Commands/Functions/PTrigCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/PTrigCall.ts @@ -1,11 +1,16 @@ -import { Signal } from '../Signals/Signal'; -import { IPartName } from '../../Interfaces/IPartName'; -import { BaseNPCoil } from '../Coils/BaseNPCoil'; +import { Signal } from '../Signals/Signal.js'; +import { IPartName } from '../../Interfaces/IPartName.js'; +import { BaseNPCoil } from '../Coils/BaseNPCoil.js'; + +export interface PTrigCallOptions { + signal: Signal; +} export class PTrigCall extends BaseNPCoil implements IPartName { partName: string; - constructor(signal: Signal) { + constructor(options: PTrigCallOptions) { + const { signal } = options; super(signal, null, null); this.partName = 'PBox'; } diff --git a/TiaCodegen-ts/src/Commands/Functions/RTrigCall.ts b/TiaCodegen-ts/src/Commands/Functions/RTrigCall.ts index 2f9d8f7..eef1f34 100644 --- a/TiaCodegen-ts/src/Commands/Functions/RTrigCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/RTrigCall.ts @@ -1,16 +1,19 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface RTrigCallOptions { + instanceName: string; + clk?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + eno?: IOperationOrSignal | null; +} export class RTrigCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - clk: IOperationOrSignal | null = null, - q: IOperationOrSignal | null = null, - eno: IOperationOrSignal | null = null, - ) { - super('R_TRIG', instanceName, eno); + constructor(options: RTrigCallOptions) { + const { instanceName, clk = null, q = null, eno = null } = options; + super({ functionName: 'R_TRIG', instanceName, eno }); this.iface['CLK'] = new IOperationOrSignalDirectionWrapper(clk, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Functions/TOFCall.ts b/TiaCodegen-ts/src/Commands/Functions/TOFCall.ts index 26ecf1e..6e333e4 100644 --- a/TiaCodegen-ts/src/Commands/Functions/TOFCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/TOFCall.ts @@ -1,17 +1,19 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; -export class TOFCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - pt: IOperationOrSignal | null = null, +export interface TOFCallOptions { + instanceName: string; + pt?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + et?: IOperationOrSignal | null; +} - q: IOperationOrSignal | null = null, - et: IOperationOrSignal | null = null, - ) { - super('TOF', instanceName, null); +export class TOFCall extends SystemFunctionBlockCall { + constructor(options: TOFCallOptions) { + const { instanceName, pt = null, q = null, et = null } = options; + super({ functionName: 'TOF', instanceName }); this.iface['PT'] = new IOperationOrSignalDirectionWrapper(pt, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Functions/TONCall.ts b/TiaCodegen-ts/src/Commands/Functions/TONCall.ts index 29178f6..4184e23 100644 --- a/TiaCodegen-ts/src/Commands/Functions/TONCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/TONCall.ts @@ -1,17 +1,19 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; -export class TONCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - pt: IOperationOrSignal | null = null, +export interface TONCallOptions { + instanceName: string; + pt?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + et?: IOperationOrSignal | null; +} - q: IOperationOrSignal | null = null, - et: IOperationOrSignal | null = null, - ) { - super('TON', instanceName, null); +export class TONCall extends SystemFunctionBlockCall { + constructor(options: TONCallOptions) { + const { instanceName, pt = null, q = null, et = null } = options; + super({ functionName: 'TON', instanceName }); this.iface['PT'] = new IOperationOrSignalDirectionWrapper(pt, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Functions/TONRCall.ts b/TiaCodegen-ts/src/Commands/Functions/TONRCall.ts index d9c5a77..16247d6 100644 --- a/TiaCodegen-ts/src/Commands/Functions/TONRCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/TONRCall.ts @@ -1,17 +1,20 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; + +export interface TONRCallOptions { + instanceName: string; + pt?: IOperationOrSignal | null; + r?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + et?: IOperationOrSignal | null; +} export class TONRCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - pt: IOperationOrSignal | null = null, - r: IOperationOrSignal | null = null, - q: IOperationOrSignal | null = null, - et: IOperationOrSignal | null = null, - ) { - super('TONR', instanceName, null); + constructor(options: TONRCallOptions) { + const { instanceName, pt = null, r = null, q = null, et = null } = options; + super({ functionName: 'TONR', instanceName }); this.iface['PT'] = new IOperationOrSignalDirectionWrapper(pt, Direction.Input); this.iface['R'] = new IOperationOrSignalDirectionWrapper(r, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Functions/TPCall.ts b/TiaCodegen-ts/src/Commands/Functions/TPCall.ts index 6591e3d..6740a11 100644 --- a/TiaCodegen-ts/src/Commands/Functions/TPCall.ts +++ b/TiaCodegen-ts/src/Commands/Functions/TPCall.ts @@ -1,17 +1,19 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper'; -import { Direction } from '../../Enums/Direction'; -import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { IOperationOrSignalDirectionWrapper } from '../../Interfaces/IOperationOrSignalDirectionWrapper.js'; +import { Direction } from '../../Enums/Direction.js'; +import { SystemFunctionBlockCall } from './Base/SystemFunctionBlockCall.js'; -export class TPCall extends SystemFunctionBlockCall { - constructor( - instanceName: string, - pt: IOperationOrSignal | null = null, +export interface TPCallOptions { + instanceName: string; + pt?: IOperationOrSignal | null; + q?: IOperationOrSignal | null; + et?: IOperationOrSignal | null; +} - q: IOperationOrSignal | null = null, - et: IOperationOrSignal | null = null, - ) { - super('TP', instanceName, null); +export class TPCall extends SystemFunctionBlockCall { + constructor(options: TPCallOptions) { + const { instanceName, pt = null, q = null, et = null } = options; + super({ functionName: 'TP', instanceName }); this.iface['PT'] = new IOperationOrSignalDirectionWrapper(pt, Direction.Input); this.iface['Q'] = new IOperationOrSignalDirectionWrapper(q, Direction.Output); diff --git a/TiaCodegen-ts/src/Commands/Move.ts b/TiaCodegen-ts/src/Commands/Move.ts index 441979a..177f1ba 100644 --- a/TiaCodegen-ts/src/Commands/Move.ts +++ b/TiaCodegen-ts/src/Commands/Move.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { IFunctionOperation } from '../Interfaces/IFunctionOperation'; -import { BaseOperationOrSignal } from './BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { IFunctionOperation } from '../Interfaces/IFunctionOperation.js'; +import { BaseOperationOrSignal } from './BaseOperationOrSignal.js'; export class Move extends BaseOperationOrSignal implements IFunctionOperation { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/NCoil.ts b/TiaCodegen-ts/src/Commands/NCoil.ts index c557cb6..c230353 100644 --- a/TiaCodegen-ts/src/Commands/NCoil.ts +++ b/TiaCodegen-ts/src/Commands/NCoil.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { Signal } from './Signals/Signal'; -import { BaseNPCoil } from './Coils/BaseNPCoil'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { Signal } from './Signals/Signal.js'; +import { BaseNPCoil } from './Coils/BaseNPCoil.js'; export class NCoil extends BaseNPCoil { constructor(signal: Signal, helpSignal: Signal, op: IOperationOrSignal | null = null) { diff --git a/TiaCodegen-ts/src/Commands/Not.ts b/TiaCodegen-ts/src/Commands/Not.ts index f218584..d623c1a 100644 --- a/TiaCodegen-ts/src/Commands/Not.ts +++ b/TiaCodegen-ts/src/Commands/Not.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { Signal } from './Signals/Signal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { Signal } from './Signals/Signal.js'; export class Not implements IOperationOrSignal { debugInfo: string | null = null; diff --git a/TiaCodegen-ts/src/Commands/Or.ts b/TiaCodegen-ts/src/Commands/Or.ts index e6a6ad7..6d74a09 100644 --- a/TiaCodegen-ts/src/Commands/Or.ts +++ b/TiaCodegen-ts/src/Commands/Or.ts @@ -1,5 +1,5 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { BaseOperationOrSignal } from './BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { BaseOperationOrSignal } from './BaseOperationOrSignal.js'; export class Or extends BaseOperationOrSignal { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/S_Move.ts b/TiaCodegen-ts/src/Commands/S_Move.ts index 89d9700..875420e 100644 --- a/TiaCodegen-ts/src/Commands/S_Move.ts +++ b/TiaCodegen-ts/src/Commands/S_Move.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; -import { IFunctionOperation } from '../Interfaces/IFunctionOperation'; -import { BaseOperationOrSignal } from './BaseOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; +import { IFunctionOperation } from '../Interfaces/IFunctionOperation.js'; +import { BaseOperationOrSignal } from './BaseOperationOrSignal.js'; export class S_Move extends BaseOperationOrSignal implements IFunctionOperation { constructor(...operationOrSignals: IOperationOrSignal[]) { diff --git a/TiaCodegen-ts/src/Commands/Signals/FixedSignal.ts b/TiaCodegen-ts/src/Commands/Signals/FixedSignal.ts index 02b4479..e9d68bf 100644 --- a/TiaCodegen-ts/src/Commands/Signals/FixedSignal.ts +++ b/TiaCodegen-ts/src/Commands/Signals/FixedSignal.ts @@ -1 +1 @@ -export { Signal, FixedSignal, FixedPeripherySignal } from './Signal'; +export { Signal, FixedSignal, FixedPeripherySignal } from './Signal.js'; diff --git a/TiaCodegen-ts/src/Commands/Signals/Signal.ts b/TiaCodegen-ts/src/Commands/Signals/Signal.ts index ab48da7..bfb92ea 100644 --- a/TiaCodegen-ts/src/Commands/Signals/Signal.ts +++ b/TiaCodegen-ts/src/Commands/Signals/Signal.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal'; -import { SignalType } from '../../Enums/SignalType'; -import { StringBuilder } from '../../utils/StringBuilder'; +import { IOperationOrSignal } from '../../Interfaces/IOperationOrSignal.js'; +import { SignalType } from '../../Enums/SignalType.js'; +import { StringBuilder } from '../../utils/StringBuilder.js'; export class Signal implements IOperationOrSignal { debugInfo: string | null = null; diff --git a/TiaCodegen-ts/src/Enums/SignalType.ts b/TiaCodegen-ts/src/Enums/SignalType.ts index 6a40546..ec61ed1 100644 --- a/TiaCodegen-ts/src/Enums/SignalType.ts +++ b/TiaCodegen-ts/src/Enums/SignalType.ts @@ -2,9 +2,13 @@ export enum SignalType { Bool = 'Bool', Byte = 'Byte', Int = 'Int', + SInt = 'Int', DInt = 'DInt', + LInt = 'LInt', UInt = 'UInt', + USInt = 'USInt', UDInt = 'UDInt', + ULInt = 'ULInt', Time = 'Time', UDT = 'UDT', String = 'String', diff --git a/TiaCodegen-ts/src/Extensions/OperationOrSignalExtensions.ts b/TiaCodegen-ts/src/Extensions/OperationOrSignalExtensions.ts index 8db6bc9..667aaef 100644 --- a/TiaCodegen-ts/src/Extensions/OperationOrSignalExtensions.ts +++ b/TiaCodegen-ts/src/Extensions/OperationOrSignalExtensions.ts @@ -1,4 +1,4 @@ -import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal'; +import { IOperationOrSignal } from '../Interfaces/IOperationOrSignal.js'; export function tryGetParent( op: IOperationOrSignal, diff --git a/TiaCodegen-ts/src/Interfaces/IOperationOrSignalDirectionWrapper.ts b/TiaCodegen-ts/src/Interfaces/IOperationOrSignalDirectionWrapper.ts index 00224d2..0a2d35a 100644 --- a/TiaCodegen-ts/src/Interfaces/IOperationOrSignalDirectionWrapper.ts +++ b/TiaCodegen-ts/src/Interfaces/IOperationOrSignalDirectionWrapper.ts @@ -1,6 +1,6 @@ -import { IOperationOrSignal } from './IOperationOrSignal'; -import { Direction } from '../Enums/Direction'; -import { SignalType } from '../Enums/SignalType'; +import { IOperationOrSignal } from './IOperationOrSignal.js'; +import { Direction } from '../Enums/Direction.js'; +import { SignalType } from '../Enums/SignalType.js'; export class IOperationOrSignalDirectionWrapper { operationOrSignal: IOperationOrSignal | null; diff --git a/TiaCodegen-ts/src/index.ts b/TiaCodegen-ts/src/index.ts index 4a3ae21..3a4f52e 100644 --- a/TiaCodegen-ts/src/index.ts +++ b/TiaCodegen-ts/src/index.ts @@ -1,90 +1,90 @@ // Enums -export { Direction } from './Enums/Direction'; -export { SignalType } from './Enums/SignalType'; +export { Direction } from './Enums/Direction.js'; +export { SignalType } from './Enums/SignalType.js'; // Interfaces -export { IOperationOrSignal } from './Interfaces/IOperationOrSignal'; -export { ICoil } from './Interfaces/ICoil'; -export { IFunctionOperation } from './Interfaces/IFunctionOperation'; -export { IPartName } from './Interfaces/IPartName'; -export { IOperationOrSignalDirectionWrapper } from './Interfaces/IOperationOrSignalDirectionWrapper'; +export type { IOperationOrSignal } from './Interfaces/IOperationOrSignal.js'; +export type { ICoil } from './Interfaces/ICoil.js'; +export type { IFunctionOperation } from './Interfaces/IFunctionOperation.js'; +export type { IPartName } from './Interfaces/IPartName.js'; +export { IOperationOrSignalDirectionWrapper } from './Interfaces/IOperationOrSignalDirectionWrapper.js'; // Utils -export { StringBuilder } from './utils/StringBuilder'; +export { StringBuilder } from './utils/StringBuilder.js'; // Internal -export { flatten } from './Internal/IEnumerableExtensions'; +export { flatten } from './Internal/IEnumerableExtensions.js'; // Extensions -export { NaturalComparer } from './Extensions/NaturalComparer'; -export { tryGetParent } from './Extensions/OperationOrSignalExtensions'; +export { NaturalComparer } from './Extensions/NaturalComparer.js'; +export { tryGetParent } from './Extensions/OperationOrSignalExtensions.js'; // Commands -export { BaseOperationOrSignal } from './Commands/BaseOperationOrSignal'; -export { And } from './Commands/And'; -export { Or } from './Commands/Or'; -export { Not } from './Commands/Not'; -export { Distributor } from './Commands/Distributor'; -export { Move } from './Commands/Move'; -export { Convert } from './Commands/Convert'; -export { S_Move } from './Commands/S_Move'; -export { NCoil } from './Commands/NCoil'; +export { BaseOperationOrSignal } from './Commands/BaseOperationOrSignal.js'; +export { And } from './Commands/And.js'; +export { Or } from './Commands/Or.js'; +export { Not } from './Commands/Not.js'; +export { Distributor } from './Commands/Distributor.js'; +export { Move } from './Commands/Move.js'; +export { Convert } from './Commands/Convert.js'; +export { S_Move } from './Commands/S_Move.js'; +export { NCoil } from './Commands/NCoil.js'; // Signals -export { Signal, FixedSignal, FixedPeripherySignal } from './Commands/Signals/Signal'; +export { Signal, FixedSignal, FixedPeripherySignal } from './Commands/Signals/Signal.js'; // Coils -export { BaseCoil } from './Commands/Coils/BaseCoil'; -export { BaseNPCoil } from './Commands/Coils/BaseNPCoil'; -export { Coil } from './Commands/Coils/Coil'; -export { PCoil } from './Commands/Coils/PCoil'; -export { RCoil } from './Commands/Coils/RCoil'; -export { SCoil } from './Commands/Coils/SCoil'; +export { BaseCoil } from './Commands/Coils/BaseCoil.js'; +export { BaseNPCoil } from './Commands/Coils/BaseNPCoil.js'; +export { Coil } from './Commands/Coils/Coil.js'; +export { PCoil } from './Commands/Coils/PCoil.js'; +export { RCoil } from './Commands/Coils/RCoil.js'; +export { SCoil } from './Commands/Coils/SCoil.js'; // Comparisons -export { CompareOperator } from './Commands/Comparisons/CompareOperator'; -export { Eq } from './Commands/Comparisons/Eq'; -export { Ne } from './Commands/Comparisons/Ne'; -export { Ge } from './Commands/Comparisons/Ge'; -export { Gt } from './Commands/Comparisons/Gt'; -export { Le } from './Commands/Comparisons/Le'; -export { Lt } from './Commands/Comparisons/Lt'; -export { InRangeCall } from './Commands/Comparisons/InRangeCall'; -export { OutRangeCall } from './Commands/Comparisons/OutRangeCall'; +export { CompareOperator } from './Commands/Comparisons/CompareOperator.js'; +export { Eq } from './Commands/Comparisons/Eq.js'; +export { Ne } from './Commands/Comparisons/Ne.js'; +export { Ge } from './Commands/Comparisons/Ge.js'; +export { Gt } from './Commands/Comparisons/Gt.js'; +export { Le } from './Commands/Comparisons/Le.js'; +export { Lt } from './Commands/Comparisons/Lt.js'; +export { InRangeCall } from './Commands/Comparisons/InRangeCall.js'; +export { OutRangeCall } from './Commands/Comparisons/OutRangeCall.js'; // Function Base -export { FunctionCall } from './Commands/Functions/Base/FunctionCall'; -export { FunctionBlockCall } from './Commands/Functions/Base/FunctionBlockCall'; -export { SystemFunctionCall } from './Commands/Functions/Base/SystemFunctionCall'; -export { SystemFunctionBlockCall } from './Commands/Functions/Base/SystemFunctionBlockCall'; +export { FunctionCall, type FunctionCallOptions } from './Commands/Functions/Base/FunctionCall.js'; +export { FunctionBlockCall, type FunctionBlockCallOptions } from './Commands/Functions/Base/FunctionBlockCall.js'; +export { SystemFunctionCall, type SystemFunctionCallOptions } from './Commands/Functions/Base/SystemFunctionCall.js'; +export { SystemFunctionBlockCall, type SystemFunctionBlockCallOptions } from './Commands/Functions/Base/SystemFunctionBlockCall.js'; // Arithmetic -export { ArithmeticCall } from './Commands/Functions/Arithmetic/ArithmeticCall'; -export { VariableArithmeticCall } from './Commands/Functions/Arithmetic/VariableArithmeticCall'; -export { AddCall } from './Commands/Functions/Arithmetic/AddCall'; -export { MulCall } from './Commands/Functions/Arithmetic/MulCall'; -export { SubCall } from './Commands/Functions/Arithmetic/SubCall'; -export { DivCall } from './Commands/Functions/Arithmetic/DivCall'; -export { ModCall } from './Commands/Functions/Arithmetic/ModCall'; +export { ArithmeticCall, type ArithmeticCallOptions } from './Commands/Functions/Arithmetic/ArithmeticCall.js'; +export { VariableArithmeticCall, type VariableArithmeticCallOptions } from './Commands/Functions/Arithmetic/VariableArithmeticCall.js'; +export { AddCall, type AddCallOptions } from './Commands/Functions/Arithmetic/AddCall.js'; +export { MulCall, type MulCallOptions } from './Commands/Functions/Arithmetic/MulCall.js'; +export { SubCall, type SubCallOptions } from './Commands/Functions/Arithmetic/SubCall.js'; +export { DivCall, type DivCallOptions } from './Commands/Functions/Arithmetic/DivCall.js'; +export { ModCall, type ModCallOptions } from './Commands/Functions/Arithmetic/ModCall.js'; // Functions -export { AckGlCall } from './Commands/Functions/AckGlCall'; -export { CTUCall } from './Commands/Functions/CTUCall'; -export { CTUDCall } from './Commands/Functions/CTUDCall'; -export { FDBACKCall } from './Commands/Functions/FDBACKCall'; -export { FTrigCall } from './Commands/Functions/FTrigCall'; -export { NTrigCall } from './Commands/Functions/NTrigCall'; -export { PTrigCall } from './Commands/Functions/PTrigCall'; -export { RTrigCall } from './Commands/Functions/RTrigCall'; -export { TOFCall } from './Commands/Functions/TOFCall'; -export { TONCall } from './Commands/Functions/TONCall'; -export { TONRCall } from './Commands/Functions/TONRCall'; -export { TPCall } from './Commands/Functions/TPCall'; +export { AckGlCall, type AckGlCallOptions } from './Commands/Functions/AckGlCall.js'; +export { CTUCall, type CTUCallOptions } from './Commands/Functions/CTUCall.js'; +export { CTUDCall, type CTUDCallOptions } from './Commands/Functions/CTUDCall.js'; +export { FDBACKCall, type FDBACKCallOptions } from './Commands/Functions/FDBACKCall.js'; +export { FTrigCall, type FTrigCallOptions } from './Commands/Functions/FTrigCall.js'; +export { NTrigCall, type NTrigCallOptions } from './Commands/Functions/NTrigCall.js'; +export { PTrigCall, type PTrigCallOptions } from './Commands/Functions/PTrigCall.js'; +export { RTrigCall, type RTrigCallOptions } from './Commands/Functions/RTrigCall.js'; +export { TOFCall, type TOFCallOptions } from './Commands/Functions/TOFCall.js'; +export { TONCall, type TONCallOptions } from './Commands/Functions/TONCall.js'; +export { TONRCall, type TONRCallOptions } from './Commands/Functions/TONRCall.js'; +export { TPCall, type TPCallOptions } from './Commands/Functions/TPCall.js'; // Blocks -export { CodeBlock } from './Blocks/CodeBlock'; -export { Network } from './Blocks/Network'; -export { Block } from './Blocks/Block'; +export { CodeBlock } from './Blocks/CodeBlock.js'; +export { Network } from './Blocks/Network.js'; +export { Block } from './Blocks/Block.js'; // CodeGen -export { KopCodeHelper } from './CodeGen/KopCodeHelper'; +export { KopCodeHelper } from './CodeGen/KopCodeHelper.js'; diff --git a/TiaCodegen-ts/tests/SampleTests.test.ts b/TiaCodegen-ts/tests/SampleTests.test.ts index ac7f8db..8301589 100644 --- a/TiaCodegen-ts/tests/SampleTests.test.ts +++ b/TiaCodegen-ts/tests/SampleTests.test.ts @@ -12,11 +12,14 @@ import { Signal, FixedSignal, FixedPeripherySignal } from '../src/Commands/Signa import { Coil } from '../src/Commands/Coils/Coil'; import { SCoil } from '../src/Commands/Coils/SCoil'; import { RCoil } from '../src/Commands/Coils/RCoil'; +import { Eq } from '../src/Commands/Comparisons/Eq'; import { Gt } from '../src/Commands/Comparisons/Gt'; import { InRangeCall } from '../src/Commands/Comparisons/InRangeCall'; import { FunctionBlockCall } from '../src/Commands/Functions/Base/FunctionBlockCall'; import { SystemFunctionCall } from '../src/Commands/Functions/Base/SystemFunctionCall'; import { TONCall } from '../src/Commands/Functions/TONCall'; +import { CTUCall } from '../src/Commands/Functions/CTUCall'; +import { TPCall } from '../src/Commands/Functions/TPCall'; import { IOperationOrSignalDirectionWrapper } from '../src/Interfaces/IOperationOrSignalDirectionWrapper'; import { Direction } from '../src/Enums/Direction'; import { SignalType } from '../src/Enums/SignalType'; @@ -148,7 +151,7 @@ describe('SampleTests', () => { const codeblock = new CodeBlock(); const nw = new Network('Test2', 'Test2en'); - const f = new FunctionBlockCall('CheckContour', 'CheckContourInstance'); + const f = new FunctionBlockCall({ functionName: 'CheckContour', instanceName: 'CheckContourInstance' }); f.iface['BoolPar'] = new IOperationOrSignalDirectionWrapper( new Or(new Signal('P1'), new Signal('P2')), Direction.InOut, @@ -165,6 +168,30 @@ describe('SampleTests', () => { expect(xml).toBeTruthy(); }); + test('FunctionBlockCallWithArrayInstance', () => { + const codeblock = new CodeBlock(); + const nw = new Network('Test', 'Test'); + nw.add(new FunctionBlockCall({ functionName: 'OrganiseSlot', instanceName: 'OrganiseSlot["S0001"]' })); + codeblock.add(nw); + + const xml = new Block('Test', 'Test', codeblock).getCode(); + + expect(xml).toContain(''); + expect(xml).toContain(''); + }); + + test('SystemFunctionBlockCallWithArrayInstance', () => { + const codeblock = new CodeBlock(); + const nw = new Network('Test', 'Test'); + nw.add(new TONCall({ instanceName: 'Timer[1]' })); + codeblock.add(nw); + + const xml = new Block('Test', 'Test', codeblock).getCode(); + + expect(xml).toContain(''); + expect(xml).toContain('1'); + }); + test('TestDistributor', () => { const codeblock = new CodeBlock(); const nw = new Network('Test2', 'Test2en'); @@ -174,7 +201,7 @@ describe('SampleTests', () => { new Distributor( new And(new Coil(new Signal('#monitoringSignal'))), new And( - new TONCall('OnDelaySafetyDoorSDA11N13', new Signal('T#60s', SignalType.ConstantTime)), + new TONCall({ instanceName: 'OnDelaySafetyDoorSDA11N13', pt: new Signal('T#60s', SignalType.ConstantTime) }), ), ), ), @@ -211,7 +238,7 @@ describe('SampleTests', () => { codeblock.safety = true; const nw = new Network('Test2', 'Test2en'); - const f = new TONCall('Hallo', new Signal('T#4m', SignalType.ConstantTime)); + const f = new TONCall({ instanceName: 'Hallo', pt: new Signal('T#4m', SignalType.ConstantTime) }); nw.add(f); codeblock.add(nw); @@ -221,6 +248,106 @@ describe('SampleTests', () => { expect(xml).toContain('F_LAD'); }); + test('TestCallWithCTU', () => { + const codeblock = new CodeBlock(); + codeblock.safety = false; + const nw = new Network('Test2', 'Test2en'); + + const f = new And( + new Signal('aa'), + new CTUCall({ instanceName: 'Hallo', r: new Signal('bbb', SignalType.Bool), pv: new Signal('2', SignalType.ConstantInt), q: new Coil(new Signal('ccc', SignalType.Bool)) }), + ); + nw.add(f); + codeblock.add(nw); + + const block = new Block('Test', 'blabla', codeblock); + block.blockInterface = TestInterface; + const xml = block.getCode(); + expect(xml).toBeTruthy(); + }); + + test('TestCallWithTPAndDistributor', () => { + const codeblock = new CodeBlock(); + codeblock.safety = false; + const nw = new Network('Test2', 'Test2en'); + + const and = new And( + new Signal('#aaa'), + new TPCall({ + instanceName: 'PulseStartPrint', + pt: new Signal('T#100ms', SignalType.ConstantTime), + q: new Distributor( + new Coil(new Signal('#bbbb')), + new RCoil(new Signal('#cccc')), + new SCoil(new Signal('#dddd')), + ), + }), + ); + nw.add(and); + codeblock.add(nw); + + const block = new Block('Test', 'blabla', codeblock); + block.blockInterface = TestInterface; + const xml = block.getCode(); + expect(xml).toBeTruthy(); + }); + + test('DistributorWithOr', () => { + const codeblock = new CodeBlock(); + codeblock.safety = false; + const nw = new Network('Test2', 'Test2en'); + + nw.add( + new And( + new Signal('asd'), + new Distributor( + new SCoil(new Signal('x')), + new And( + new Or( + new And(new Signal('a'), new Signal('h')), + new And(new Signal('b'), new Signal('f')), + ), + new SCoil(new Signal('c')), + ), + ), + ), + ); + codeblock.add(nw); + + const block = new Block('Test', 'blabla', codeblock); + block.blockInterface = TestInterface; + const xml = block.getCode(); + expect(xml).toBeTruthy(); + }); + + test('MultipleOr', () => { + const codeblock = new CodeBlock(); + codeblock.safety = false; + const nw = new Network('Test2', 'Test2en'); + + nw.add( + new Coil( + new Signal('a'), + new And( + new Signal('1'), + new Or( + new And( + new Or(new Signal('b'), new Signal('c')), + new Signal('d'), + ), + new Signal('e'), + ), + ), + ), + ); + codeblock.add(nw); + + const block = new Block('Test', 'blabla', codeblock); + block.blockInterface = TestInterface; + const xml = block.getCode(); + expect(xml).toBeTruthy(); + }); + test('FixedPeripherySignalTest', () => { const codeblock = new CodeBlock(); const nw = new Network('Test3', 'Test3en'); @@ -270,7 +397,7 @@ describe('SampleTests', () => { codeblock.safety = false; const nw = new Network('TestDPXX_DAT', 'TestDPXX_DATen'); - const sf1 = new SystemFunctionCall('DPRD_DAT'); + const sf1 = new SystemFunctionCall({ functionName: 'DPRD_DAT' }); sf1.iface['LADDR'] = new IOperationOrSignalDirectionWrapper( new Signal('#Configuration.GeneralMoviC.ModuleHardwareID'), Direction.Input, @@ -326,6 +453,49 @@ describe('SampleTests', () => { expect(xml).toBeTruthy(); }); + test('ComplexOr2', () => { + const codeblock = new CodeBlock(); + codeblock.safety = false; + const nw = new Network('T1', 'T1'); + + nw.add( + new Coil( + new Signal('Test11'), + new Or( + new Signal('Test12'), + new Or( + new And( + new Signal('Test1'), + new Or( + new And( + new Signal('Test2'), + new Or(new Signal('Test3'), new Signal('Test4')), + ), + new Signal('Test5'), + ), + ), + new And( + new Signal('Test6'), + new Or( + new And( + new Signal('Test7'), + new Or(new Signal('Test8'), new Signal('Test9')), + ), + new Signal('Test10'), + ), + ), + ), + ), + ), + ); + codeblock.add(nw); + + const block = new Block('Test', 'blabla', codeblock); + block.blockInterface = TestInterface; + const xml = block.getCode(); + expect(xml).toBeTruthy(); + }); + test('Complex3', () => { const codeblock = new CodeBlock(); codeblock.safety = false; @@ -344,4 +514,37 @@ describe('SampleTests', () => { const xml = block.getCode(); expect(xml).toBeTruthy(); }); + + test('DoubleCarrierTest', () => { + const codeblock = new CodeBlock(); + codeblock.safety = false; + const nw = new Network('Test', 'Testen'); + + nw.add( + new And( + new Eq(new Signal('#Configuration.General.SingleDoubleCarrier', SignalType.Int), new Signal(2)), + new Distributor( + new And( + new Or( + new Signal('#DoubleCarrier.Sensors.V[#Configuration.General.CoordinationAxisConveyor, 1]'), + new Signal('#DoubleCarrier.Sensors.R[#Configuration.General.CoordinationAxisConveyor, 1]'), + ), + new Coil(new Signal('#CarrierGeneral.States.CarriageOccupied[2]')), + ), + new And( + new Signal('#DoubleCarrierData.MOrder.DataPresent'), + new Coil(new Signal('#CarrierGeneral.States.CarriageDataPresent[2]')), + ), + ), + ), + ); + + codeblock.add(nw); + + const block = new Block('Test', 'blabla', codeblock); + const xml = block.getCode(); + + const expectedXml = ' General 1.0 Optimized Test LAD DInt2DInt2DInt1DInt1Int2Int2 LADde-DEen-GBde-DETesten-GBTesten de-DE blabla en-GB de-DE en-GB '; + expect(xml.replace(/\r?\n/g, '')).toEqual(expectedXml.replace(/\r?\n/g, '')); + }); }); diff --git a/TiaCodegen-ts/tsconfig.json b/TiaCodegen-ts/tsconfig.json index 0ad54fe..0e93982 100644 --- a/TiaCodegen-ts/tsconfig.json +++ b/TiaCodegen-ts/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { "target": "ES2020", - "module": "commonjs", + "module": "NodeNext", + "moduleResolution": "NodeNext", "lib": ["ES2020"], "outDir": "./dist", "rootDir": "./src", @@ -9,6 +10,7 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, + "isolatedModules": true, "declaration": true, "declarationMap": true, "sourceMap": true diff --git a/TiaCodegen/Commands/Comparisons/InRangeCall.cs b/TiaCodegen/Commands/Comparisons/InRangeCall.cs index 5f4ae01..cd15239 100644 --- a/TiaCodegen/Commands/Comparisons/InRangeCall.cs +++ b/TiaCodegen/Commands/Comparisons/InRangeCall.cs @@ -17,7 +17,7 @@ public InRangeCall( DisableEno = false; Interface["min"] = new IOperationOrSignalDirectionWrapper(min, Direction.Input); Interface["in"] = new IOperationOrSignalDirectionWrapper(@in, Direction.Input); - Interface["max"] = new IOperationOrSignalDirectionWrapper(max, Direction.Output); + Interface["max"] = new IOperationOrSignalDirectionWrapper(max, Direction.Input); Interface["out"] = new IOperationOrSignalDirectionWrapper(@out, Direction.Output); Children.AddRange(Interface.Values.Where(x => x.OperationOrSignal != null).Select(x => x.OperationOrSignal)); diff --git a/TiaCodegen/Commands/Comparisons/OutRangeCall.cs b/TiaCodegen/Commands/Comparisons/OutRangeCall.cs index 51fb5ec..a50f984 100644 --- a/TiaCodegen/Commands/Comparisons/OutRangeCall.cs +++ b/TiaCodegen/Commands/Comparisons/OutRangeCall.cs @@ -17,7 +17,7 @@ public OutRangeCall( DisableEno = false; Interface["min"] = new IOperationOrSignalDirectionWrapper(min, Direction.Input); Interface["in"] = new IOperationOrSignalDirectionWrapper(@in, Direction.Input); - Interface["max"] = new IOperationOrSignalDirectionWrapper(max, Direction.Output); + Interface["max"] = new IOperationOrSignalDirectionWrapper(max, Direction.Input); Interface["out"] = new IOperationOrSignalDirectionWrapper(@out, Direction.Output); Children.AddRange(Interface.Values.Where(x => x.OperationOrSignal != null).Select(x => x.OperationOrSignal)); diff --git a/TiaCodegen/Commands/Functions/Arithmetic/AddCall.cs b/TiaCodegen/Commands/Functions/Arithmetic/AddCall.cs index 101e686..b56d6f6 100644 --- a/TiaCodegen/Commands/Functions/Arithmetic/AddCall.cs +++ b/TiaCodegen/Commands/Functions/Arithmetic/AddCall.cs @@ -4,9 +4,9 @@ namespace TiaCodegen.Commands.Functions.Arithmetic { - public class MulCall : VariableArithmeticCall + public class AddCall : VariableArithmeticCall { - public MulCall(string type, + public AddCall(string type, IOperationOrSignal in1, IOperationOrSignal in2, IOperationOrSignal in3 = null, @@ -58,7 +58,7 @@ public MulCall(string type, IOperationOrSignal in49 = null, IOperationOrSignal in50 = null, IOperationOrSignal out1 = null, - IOperationOrSignal eno = null) : base("Mul", eno) + IOperationOrSignal eno = null) : base("Add", eno) { DisableEno = true; Type = type; diff --git a/TiaCodegen/Commands/Functions/Arithmetic/MulCall.cs b/TiaCodegen/Commands/Functions/Arithmetic/MulCall.cs index b56d6f6..101e686 100644 --- a/TiaCodegen/Commands/Functions/Arithmetic/MulCall.cs +++ b/TiaCodegen/Commands/Functions/Arithmetic/MulCall.cs @@ -4,9 +4,9 @@ namespace TiaCodegen.Commands.Functions.Arithmetic { - public class AddCall : VariableArithmeticCall + public class MulCall : VariableArithmeticCall { - public AddCall(string type, + public MulCall(string type, IOperationOrSignal in1, IOperationOrSignal in2, IOperationOrSignal in3 = null, @@ -58,7 +58,7 @@ public AddCall(string type, IOperationOrSignal in49 = null, IOperationOrSignal in50 = null, IOperationOrSignal out1 = null, - IOperationOrSignal eno = null) : base("Add", eno) + IOperationOrSignal eno = null) : base("Mul", eno) { DisableEno = true; Type = type; diff --git a/TiaCodegen/Enums/SignalType.cs b/TiaCodegen/Enums/SignalType.cs index 1bb89ec..c41a3a5 100644 --- a/TiaCodegen/Enums/SignalType.cs +++ b/TiaCodegen/Enums/SignalType.cs @@ -5,9 +5,13 @@ public enum SignalType Bool, Byte, Int, + SInt, DInt, + LInt, UInt, + USInt, UDInt, + ULInt, Time, UDT, String,