From eee3ebd5fdb35dccb1f5b8a48363d217303a8c82 Mon Sep 17 00:00:00 2001 From: timyhac Date: Sat, 15 Jun 2024 13:12:51 +1000 Subject: [PATCH 1/2] Revert "Temporarilily revert additions in libplctag.NET so that NativeImport can be built and released" This reverts commit 39621c17b993111145489b1da32ddc6cfae6b472. --- src/libplctag/INativeTag.cs | 1 + src/libplctag/NativeTag.cs | 1 + src/libplctag/NativeTagWrapper.cs | 14 ++++++++++++++ src/libplctag/Tag.cs | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/src/libplctag/INativeTag.cs b/src/libplctag/INativeTag.cs index adebe3ef..3f889052 100644 --- a/src/libplctag/INativeTag.cs +++ b/src/libplctag/INativeTag.cs @@ -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); diff --git a/src/libplctag/NativeTag.cs b/src/libplctag/NativeTag.cs index 99045602..282823d7 100644 --- a/src/libplctag/NativeTag.cs +++ b/src/libplctag/NativeTag.cs @@ -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); diff --git a/src/libplctag/NativeTagWrapper.cs b/src/libplctag/NativeTagWrapper.cs index 068b372a..a0482c48 100644 --- a/src/libplctag/NativeTagWrapper.cs +++ b/src/libplctag/NativeTagWrapper.cs @@ -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); diff --git a/src/libplctag/Tag.cs b/src/libplctag/Tag.cs index d9ce568e..71e6a9ed 100644 --- a/src/libplctag/Tag.cs +++ b/src/libplctag/Tag.cs @@ -405,6 +405,10 @@ public uint? StringTotalLength public void GetBuffer(byte[] buffer) => _tag.GetBuffer(buffer); public void SetBuffer(byte[] newBuffer) => _tag.SetBuffer(newBuffer); + /// + /// This function retrieves an attribute of the raw tag byte array. + /// + public byte[] GetByteArrayAttribute(string attributeName) => _tag.GetByteArrayAttribute(attributeName); public int GetSize() => _tag.GetSize(); public void SetSize(int newSize) => _tag.SetSize(newSize); From 919d766cc47f797ac6592b3cd4d8382e94f4cada Mon Sep 17 00:00:00 2001 From: timyhac Date: Sat, 15 Jun 2024 13:16:22 +1000 Subject: [PATCH 2/2] Update to libplctag.NativeImport 1.0.39 --- src/libplctag/libplctag.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libplctag/libplctag.csproj b/src/libplctag/libplctag.csproj index 07bac8ca..ba7a9e98 100644 --- a/src/libplctag/libplctag.csproj +++ b/src/libplctag/libplctag.csproj @@ -18,7 +18,7 @@ - +