Skip to content

Commit

Permalink
In examples - allow IPlcMapper to Configure Tag prior to Initializati…
Browse files Browse the repository at this point in the history
…on (#212)
  • Loading branch information
timyhac authored Jul 27, 2024
1 parent 605f792 commit e91496e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/CSharp DotNetCore/PlcMapper/ExampleListPlc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public void Encode(Tag tag, TagInfo[] value)
//TODO: We know this value after we decode once. SHould we trigger a decode or cache the value after first decode?
return null;
}

public virtual void Configure(Tag tag)
{
// Do nothing
}
}

public class UdtFieldInfo
Expand Down Expand Up @@ -302,5 +307,10 @@ public void Encode(Tag tag, UdtInfo value)
//TODO: We know this value after we decode once. SHould we trigger a decode or cache the value after first decode?
return null;
}

public virtual void Configure(Tag tag)
{
// Do nothing
}
}
}
10 changes: 10 additions & 0 deletions examples/CSharp DotNetCore/PlcMapper/ExampleMappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public abstract class PlcMapperBase<T> : IPlcMapper<T>, IPlcMapper<T[]>, IPlcMap
//Multiply all the dimensions to get total elements
virtual public int? GetElementCount() => ArrayDimensions?.Aggregate(1, (x, y) => x * y);

public virtual void Configure(Tag tag)
{
// Do nothing
}

virtual protected T[] DecodeArray(Tag tag)
{
if (ElementSize is null)
Expand Down Expand Up @@ -99,6 +104,11 @@ public class BoolPlcMapper : IPlcMapper<bool>, IPlcMapper<bool[]>, IPlcMapper<bo
return (int)Math.Ceiling((double)totalElements / 32.0);
}

public virtual void Configure(Tag tag)
{
// Do nothing
}

public int? SetArrayLength(int? elementCount) => (int)Math.Ceiling((double)elementCount.Value / 32.0);

virtual protected bool[] DecodeArray(Tag tag)
Expand Down
6 changes: 6 additions & 0 deletions examples/CSharp DotNetCore/PlcMapper/TagOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ public interface IPlcMapper<T>
/// </summary>
int? GetElementCount();

/// <summary>
/// This allows the implementer to configure Tag properties prior to tag Initialization
/// </summary>
/// <param name="tag"></param>
void Configure(Tag tag);

/// <summary>
/// This is the method that reads/unpacks the underlying value of the tag
/// and returns it as a C# type
Expand Down

0 comments on commit e91496e

Please sign in to comment.