Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose GetByteArrayAttribute(...) #378

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libplctag/INativeTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface INativeTag
sbyte plc_tag_get_int8(int tag, int offset);
int plc_tag_get_int_attribute(int tag, string attrib_name, int default_value);
int plc_tag_set_int_attribute(int tag, string attrib_name, int new_value);
int plc_tag_get_byte_array_attribute(int tag, string attrib_name, byte[] buffer, int buffer_length);
int plc_tag_get_size(int tag);
int plc_tag_set_size(int tag, int new_size);
ushort plc_tag_get_uint16(int tag, int offset);
Expand Down
1 change: 1 addition & 0 deletions src/libplctag/NativeTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class NativeTag : INativeTag
public int plc_tag_abort(Int32 tag) => plctag.plc_tag_abort(tag);
public int plc_tag_get_int_attribute(Int32 tag, string attrib_name, int default_value) => plctag.plc_tag_get_int_attribute(tag, attrib_name, default_value);
public int plc_tag_set_int_attribute(Int32 tag, string attrib_name, int new_value) => plctag.plc_tag_set_int_attribute(tag, attrib_name, new_value);
public int plc_tag_get_byte_array_attribute(Int32 tag, string attrib_name, byte[] buffer, int buffer_length) => plctag.plc_tag_get_byte_array_attribute(tag, attrib_name, buffer, buffer_length);
public UInt64 plc_tag_get_uint64(Int32 tag, int offset) => plctag.plc_tag_get_uint64(tag, offset);
public Int64 plc_tag_get_int64(Int32 tag, int offset) => plctag.plc_tag_get_int64(tag, offset);
public int plc_tag_set_uint64(Int32 tag, int offset, UInt64 val) => plctag.plc_tag_set_uint64(tag, offset, val);
Expand Down
14 changes: 14 additions & 0 deletions src/libplctag/NativeTagWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,20 @@ private void SetIntAttribute(string attributeName, int value)
ThrowIfStatusNotOk(result);
}

public byte[] GetByteArrayAttribute(string attributeName)
{
ThrowIfAlreadyDisposed();

var bufferLengthAttributeName = attributeName + ".length";
var bufferLength = GetIntAttribute(bufferLengthAttributeName);
var buffer = new byte[bufferLength];

var result = (Status)_native.plc_tag_get_byte_array_attribute(nativeTagHandle, attributeName, buffer, buffer.Length);
ThrowIfStatusNotOk(result);

return buffer;
}

private void SetDebugLevel(DebugLevel level)
{
_native.plc_tag_set_debug_level((int)level);
Expand Down
4 changes: 4 additions & 0 deletions src/libplctag/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ public uint? StringTotalLength
public void GetBuffer(byte[] buffer) => _tag.GetBuffer(buffer);
public void SetBuffer(byte[] newBuffer) => _tag.SetBuffer(newBuffer);

/// <summary>
/// This function retrieves an attribute of the raw tag byte array.
/// </summary>
public byte[] GetByteArrayAttribute(string attributeName) => _tag.GetByteArrayAttribute(attributeName);
public int GetSize() => _tag.GetSize();
public void SetSize(int newSize) => _tag.SetSize(newSize);

Expand Down
2 changes: 1 addition & 1 deletion src/libplctag/libplctag.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="libplctag.NativeImport" Version="1.0.37" />
<PackageReference Include="libplctag.NativeImport" Version="1.0.39" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading