Skip to content

Commit

Permalink
suport SystemFunction CTU
Browse files Browse the repository at this point in the history
  • Loading branch information
sripp committed Apr 15, 2024
1 parent 3fbd8f3 commit cea2c0c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions TiaCodeGen.Tests/SampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions TiaCodegen/CodeGen/KopCodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ private void AddWires(IOperationOrSignal op)
{
_sb.AppendLine("<NameCon UId=\"" + next.OperationId + "\" Name=\"pre\" />" + " <!-- " + dstName + " -->");
}
else if (next is CTUCall)
{
_sb.AppendLine("<NameCon UId=\"" + next.OperationId + "\" Name=\"CU\" />" + " <!-- " + dstName + " -->");
}
else if (next is FunctionCall)
{
_sb.AppendLine("<NameCon UId=\"" + next.OperationId + "\" Name=\"" + (((FunctionCall)next).HasNoEn ? "in" : "en") + "\" />" + " <!-- " + dstName + " -->");
Expand Down
2 changes: 0 additions & 2 deletions TiaCodegen/Commands/Functions/CTUCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cea2c0c

Please sign in to comment.