From cea2c0c92b6b78fb8b6c7103f86b8090b68ff470 Mon Sep 17 00:00:00 2001 From: sripp Date: Mon, 15 Apr 2024 16:34:01 +0200 Subject: [PATCH] suport SystemFunction CTU --- TiaCodeGen.Tests/SampleTests.cs | 17 +++++++++++++++++ TiaCodegen/CodeGen/KopCodeHelper.cs | 4 ++++ TiaCodegen/Commands/Functions/CTUCall.cs | 2 -- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/TiaCodeGen.Tests/SampleTests.cs b/TiaCodeGen.Tests/SampleTests.cs index 795d5f7..a5ae804 100644 --- a/TiaCodeGen.Tests/SampleTests.cs +++ b/TiaCodeGen.Tests/SampleTests.cs @@ -222,6 +222,23 @@ public void TestCallWithTOn() 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() { diff --git a/TiaCodegen/CodeGen/KopCodeHelper.cs b/TiaCodegen/CodeGen/KopCodeHelper.cs index 0b467f8..eda620c 100644 --- a/TiaCodegen/CodeGen/KopCodeHelper.cs +++ b/TiaCodegen/CodeGen/KopCodeHelper.cs @@ -691,6 +691,10 @@ private void AddWires(IOperationOrSignal op) { _sb.AppendLine("" + " "); } + else if (next is CTUCall) + { + _sb.AppendLine("" + " "); + } else if (next is FunctionCall) { _sb.AppendLine("" + " "); diff --git a/TiaCodegen/Commands/Functions/CTUCall.cs b/TiaCodegen/Commands/Functions/CTUCall.cs index 6330078..33ff962 100644 --- a/TiaCodegen/Commands/Functions/CTUCall.cs +++ b/TiaCodegen/Commands/Functions/CTUCall.cs @@ -8,13 +8,11 @@ namespace TiaCodegen.Commands.Functions public class CTUCall : SystemFunctionBlockCall { public CTUCall(string instanceName, - IOperationOrSignal cu = null, IOperationOrSignal r = null, IOperationOrSignal pv = null, IOperationOrSignal q = null, IOperationOrSignal cv = null) : base("CTU", instanceName, null) { - Interface["CU"] = new IOperationOrSignalDirectionWrapper(cu, Direction.Input); Interface["R"] = new IOperationOrSignalDirectionWrapper(r, Direction.Input); Interface["PV"] = new IOperationOrSignalDirectionWrapper(pv, Direction.Input); Interface["Q"] = new IOperationOrSignalDirectionWrapper(q, Direction.Output);