From b1678db8b7a728a66fdaf94a6e67d71f6dccf350 Mon Sep 17 00:00:00 2001
From: Mitch Razga <74954528+MitchRazga@users.noreply.github.com>
Date: Mon, 1 Jun 2026 19:55:58 +1000
Subject: [PATCH 1/3] Add LangVersion to Directory.Build.props Update
.editorconfig to default to file-scoped namespaces
---
Directory.Build.props | 7 +++++++
src/.editorconfig | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 Directory.Build.props
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 00000000..8c1d5a32
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,7 @@
+
+
+
+ latest
+
+
+
\ No newline at end of file
diff --git a/src/.editorconfig b/src/.editorconfig
index 9b4acce9..cdf9366c 100644
--- a/src/.editorconfig
+++ b/src/.editorconfig
@@ -110,7 +110,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter
# Code-block preferences
csharp_prefer_braces = true
csharp_prefer_simple_using_statement = true
-csharp_style_namespace_declarations = block_scoped
+csharp_style_namespace_declarations = file_scoped
csharp_style_prefer_method_group_conversion = true
csharp_style_prefer_top_level_statements = true
From 6f3eaa095316b4bd60cd2f4b8ae5cb69e2ec2eae Mon Sep 17 00:00:00 2001
From: Mitch Razga <74954528+MitchRazga@users.noreply.github.com>
Date: Tue, 2 Jun 2026 07:50:19 +1000
Subject: [PATCH 2/3] Convert to file-scoped namespaces
---
src/libplctag.NativeImport/CONN_STATUS.cs | 7 +++----
src/libplctag.NativeImport/DEBUG_LEVEL.cs | 7 +++----
src/libplctag.NativeImport/DEBUG_MODULE.cs | 7 +++----
src/libplctag.NativeImport/EVENT.cs | 7 +++----
src/libplctag.NativeImport/NativeMethods.cs | 7 +++----
src/libplctag.NativeImport/STATUS.cs | 7 +++----
src/libplctag.NativeImport/plctag.cs | 7 +++----
src/libplctag.Tests/AsyncTests.cs | 7 +++----
src/libplctag.Tests/DisposeTests.cs | 7 +++----
src/libplctag.Tests/OtherTests.cs | 7 +++----
src/libplctag/DataTypes/BoolPlcMapper.cs | 6 ++----
src/libplctag/DataTypes/DintPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/Extensions/ArrayExtensions.cs | 7 +++----
src/libplctag/DataTypes/IPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/IntPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/LintPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/LrealPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/PlcMapperBase.cs | 8 +++-----
src/libplctag/DataTypes/RealPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/Simple/Definitions.cs | 7 ++-----
src/libplctag/DataTypes/SintPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/StringPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/TagInfoPlcMapper.cs | 7 ++-----
src/libplctag/DataTypes/TimerPlcMapper.cs | 7 +++----
src/libplctag/DataTypes/UdtInfoPlcMapper.cs | 7 ++-----
src/libplctag/DebugLevel.cs | 7 +++----
src/libplctag/Event.cs | 7 +++----
src/libplctag/INative.cs | 7 +++----
src/libplctag/ITag.cs | 7 +++----
src/libplctag/LibPlcTag.cs | 7 +++----
src/libplctag/LibPlcTagException.cs | 6 ++----
src/libplctag/LogEventArgs.cs | 7 +++----
src/libplctag/Native.cs | 7 +++----
src/libplctag/PlcType.cs | 7 +++----
src/libplctag/Protocol.cs | 7 +++----
src/libplctag/Status.cs | 7 +++----
src/libplctag/Tag.cs | 7 ++-----
src/libplctag/TagEventArgs.cs | 7 +++----
src/libplctag/TagOfT.cs | 7 +++----
39 files changed, 111 insertions(+), 161 deletions(-)
diff --git a/src/libplctag.NativeImport/CONN_STATUS.cs b/src/libplctag.NativeImport/CONN_STATUS.cs
index bdd43efd..de5413c4 100644
--- a/src/libplctag.NativeImport/CONN_STATUS.cs
+++ b/src/libplctag.NativeImport/CONN_STATUS.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
///
/// You can query the connection status of a tag using the connection_status attribute
/// with :
@@ -50,5 +50,4 @@ public enum CONN_STATUS
/// Waiting to retry after error.
///
PLCTAG_CONN_STATUS_ERR_WAIT = 5
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/DEBUG_LEVEL.cs b/src/libplctag.NativeImport/DEBUG_LEVEL.cs
index 4bb28e6f..84e5da0c 100644
--- a/src/libplctag.NativeImport/DEBUG_LEVEL.cs
+++ b/src/libplctag.NativeImport/DEBUG_LEVEL.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
///
/// The library provides debugging output when enabled.
/// There are three ways to set the debug level (for historical reasons):
@@ -52,5 +52,4 @@ public enum DEBUG_LEVEL
/// You have been warned!
///
PLCTAG_DEBUG_SPEW = 5
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/DEBUG_MODULE.cs b/src/libplctag.NativeImport/DEBUG_MODULE.cs
index 1f2fd51c..d8714143 100644
--- a/src/libplctag.NativeImport/DEBUG_MODULE.cs
+++ b/src/libplctag.NativeImport/DEBUG_MODULE.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
///
/// The library supports setting debug levels for individual modules.
/// This allows for fine-grained control over which subsystems produce debug output.
@@ -41,5 +41,4 @@ public enum DEBUG_MODULE
PLCTAG_MODULE_AB_CONNECTION = 24,
PLCTAG_MODULE_MB_CONNECTION = 25,
PLCTAG_MODULE_OMRON_CONNECTION = 26,
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/EVENT.cs b/src/libplctag.NativeImport/EVENT.cs
index 703d693f..6f2ad72b 100644
--- a/src/libplctag.NativeImport/EVENT.cs
+++ b/src/libplctag.NativeImport/EVENT.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
///
/// The library provides functions to register a callback on a tag.
/// These events generate a call to that callback.
@@ -85,5 +85,4 @@ public enum EVENT
/// Waiting to reconnect after an error.
///
PLCTAG_EVENT_CONN_STATUS_ERR_WAIT = 105,
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/NativeMethods.cs b/src/libplctag.NativeImport/NativeMethods.cs
index 00958089..1336756d 100644
--- a/src/libplctag.NativeImport/NativeMethods.cs
+++ b/src/libplctag.NativeImport/NativeMethods.cs
@@ -10,8 +10,8 @@
using System.Text;
using static libplctag.NativeImport.plctag;
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
static class NativeMethods
{
@@ -263,5 +263,4 @@ static NativeMethods()
[DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public unsafe static extern int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/STATUS.cs b/src/libplctag.NativeImport/STATUS.cs
index 0abdcc8d..ee76c201 100644
--- a/src/libplctag.NativeImport/STATUS.cs
+++ b/src/libplctag.NativeImport/STATUS.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
///
/// Most functions return a status code.
/// It will be one of these.
@@ -218,5 +218,4 @@ public enum STATUS
/// The operation cannot be performed as some other operation is taking place.
///
PLCTAG_ERR_BUSY = -39
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/plctag.cs b/src/libplctag.NativeImport/plctag.cs
index 1afbdd09..d8d1ad2b 100644
--- a/src/libplctag.NativeImport/plctag.cs
+++ b/src/libplctag.NativeImport/plctag.cs
@@ -9,8 +9,8 @@
using System.Runtime.InteropServices;
using System.Text;
-namespace libplctag.NativeImport
-{
+namespace libplctag.NativeImport;
+
///
/// This class provides low-level (raw) access to the native libplctag library (which is written in C).
/// The purpose of this package is to expose the API for this native library, and handle platform and configuration issues.
@@ -331,5 +331,4 @@ public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, ReadOnly
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.Tests/AsyncTests.cs b/src/libplctag.Tests/AsyncTests.cs
index 028f6a15..9a9f5d92 100644
--- a/src/libplctag.Tests/AsyncTests.cs
+++ b/src/libplctag.Tests/AsyncTests.cs
@@ -11,8 +11,8 @@
using System.Threading;
using System.Threading.Tasks;
-namespace libplctag.Tests
-{
+namespace libplctag.Tests;
+
public class AsyncTests
{
@@ -156,5 +156,4 @@ Mock GetMock()
return nativeTag;
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.Tests/DisposeTests.cs b/src/libplctag.Tests/DisposeTests.cs
index 32532d2d..8b718036 100644
--- a/src/libplctag.Tests/DisposeTests.cs
+++ b/src/libplctag.Tests/DisposeTests.cs
@@ -11,8 +11,8 @@
using System.Threading.Tasks;
using System.Threading;
-namespace libplctag.Tests
-{
+namespace libplctag.Tests;
+
public class DisposeTests
{
@@ -88,5 +88,4 @@ public void Can_not_use_if_already_disposed()
Assert.Throws(() => tag.GetStatus());
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag.Tests/OtherTests.cs b/src/libplctag.Tests/OtherTests.cs
index d1b908c5..ef14c2e3 100644
--- a/src/libplctag.Tests/OtherTests.cs
+++ b/src/libplctag.Tests/OtherTests.cs
@@ -9,8 +9,8 @@
using Xunit;
using Moq;
-namespace libplctag.Tests
-{
+namespace libplctag.Tests;
+
public class OtherTests
{
@@ -68,5 +68,4 @@ public void Attribute_string_does_not_contain_unset_properties()
nativeTag.Verify(m => m.plc_tag_create_ex(expectedAttributeString, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/BoolPlcMapper.cs b/src/libplctag/DataTypes/BoolPlcMapper.cs
index e57ba0b1..252ed471 100644
--- a/src/libplctag/DataTypes/BoolPlcMapper.cs
+++ b/src/libplctag/DataTypes/BoolPlcMapper.cs
@@ -9,8 +9,7 @@
using System;
using System.Linq;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class BoolPlcMapper : IPlcMapper, IPlcMapper, IPlcMapper, IPlcMapper
@@ -70,5 +69,4 @@ virtual protected void EncodeArray(Tag tag, bool[] values)
void IPlcMapper.Encode(Tag tag, bool[,,] value) => EncodeArray(tag, value.To1DArray());
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/DintPlcMapper.cs b/src/libplctag/DataTypes/DintPlcMapper.cs
index 48e7a7e0..c5fa615f 100644
--- a/src/libplctag/DataTypes/DintPlcMapper.cs
+++ b/src/libplctag/DataTypes/DintPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class DintPlcMapper : PlcMapperBase
{
@@ -18,5 +18,4 @@ public class DintPlcMapper : PlcMapperBase
override public void Encode(Tag tag, int offset, int value) => tag.SetInt32(offset, value);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs b/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs
index 74fc0005..e8e46a3c 100644
--- a/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs
+++ b/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs
@@ -9,8 +9,8 @@
using System.Collections.Generic;
using System.Text;
-namespace libplctag.DataTypes.Extensions
-{
+namespace libplctag.DataTypes.Extensions;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public static class ArrayExtensions
{
@@ -115,5 +115,4 @@ public static T[] To1DArray(this T[,,] input)
return output;
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/IPlcMapper.cs b/src/libplctag/DataTypes/IPlcMapper.cs
index 40e4e04f..3c5f31ef 100644
--- a/src/libplctag/DataTypes/IPlcMapper.cs
+++ b/src/libplctag/DataTypes/IPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public interface IPlcMapper
{
@@ -53,5 +53,4 @@ public interface IPlcMapper
/// Tag to be encoded to
/// C# value to be transformed
void Encode(Tag tag, T value);
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/IntPlcMapper.cs b/src/libplctag/DataTypes/IntPlcMapper.cs
index 45256803..ece59304 100644
--- a/src/libplctag/DataTypes/IntPlcMapper.cs
+++ b/src/libplctag/DataTypes/IntPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class IntPlcMapper : PlcMapperBase
{
@@ -18,5 +18,4 @@ public class IntPlcMapper : PlcMapperBase
override public void Encode(Tag tag, int offset, short value) => tag.SetInt16(offset, value);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/LintPlcMapper.cs b/src/libplctag/DataTypes/LintPlcMapper.cs
index 49643ed2..8bfb4244 100644
--- a/src/libplctag/DataTypes/LintPlcMapper.cs
+++ b/src/libplctag/DataTypes/LintPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class LintPlcMapper : PlcMapperBase
{
@@ -18,5 +18,4 @@ public class LintPlcMapper : PlcMapperBase
override public void Encode(Tag tag, int offset, long value) => tag.SetInt64(offset, value);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/LrealPlcMapper.cs b/src/libplctag/DataTypes/LrealPlcMapper.cs
index cb970210..fdeef378 100644
--- a/src/libplctag/DataTypes/LrealPlcMapper.cs
+++ b/src/libplctag/DataTypes/LrealPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class LrealPlcMapper : PlcMapperBase
{
@@ -18,5 +18,4 @@ public class LrealPlcMapper : PlcMapperBase
override public double Decode(Tag tag, int offset) => tag.GetFloat64(offset);
override public void Encode(Tag tag, int offset, double value)=> tag.SetFloat64(offset, value);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/PlcMapperBase.cs b/src/libplctag/DataTypes/PlcMapperBase.cs
index ea210a8e..14b25f43 100644
--- a/src/libplctag/DataTypes/PlcMapperBase.cs
+++ b/src/libplctag/DataTypes/PlcMapperBase.cs
@@ -11,8 +11,8 @@
using System.Threading.Tasks;
using libplctag.DataTypes.Extensions;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public abstract class PlcMapperBase : IPlcMapper, IPlcMapper, IPlcMapper, IPlcMapper
{
@@ -80,6 +80,4 @@ virtual protected void EncodeArray(Tag tag, T[] values)
T[,,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To3DArray(ArrayDimensions[0], ArrayDimensions[1], ArrayDimensions[2]);
void IPlcMapper.Encode(Tag tag, T[,,] value) => EncodeArray(tag, value.To1DArray());
- }
-
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/RealPlcMapper.cs b/src/libplctag/DataTypes/RealPlcMapper.cs
index fe770019..a349a197 100644
--- a/src/libplctag/DataTypes/RealPlcMapper.cs
+++ b/src/libplctag/DataTypes/RealPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class RealPlcMapper : PlcMapperBase
{
@@ -19,5 +19,4 @@ public class RealPlcMapper : PlcMapperBase
override public void Encode(Tag tag, int offset, float value) => tag.SetFloat32(offset, value);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/Simple/Definitions.cs b/src/libplctag/DataTypes/Simple/Definitions.cs
index 87426efb..709582b6 100644
--- a/src/libplctag/DataTypes/Simple/Definitions.cs
+++ b/src/libplctag/DataTypes/Simple/Definitions.cs
@@ -9,8 +9,7 @@
using System.Collections.Generic;
using System.Text;
-namespace libplctag.DataTypes.Simple
-{
+namespace libplctag.DataTypes.Simple;
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class TagBool : Tag { }
@@ -99,6 +98,4 @@ public class TagTagInfo : Tag { }
public class TagTimer : Tag { }
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class TagUdtInfo : Tag { }
-
-}
+ public class TagUdtInfo : Tag { }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/SintPlcMapper.cs b/src/libplctag/DataTypes/SintPlcMapper.cs
index ba0a99ef..3d43e32b 100644
--- a/src/libplctag/DataTypes/SintPlcMapper.cs
+++ b/src/libplctag/DataTypes/SintPlcMapper.cs
@@ -7,8 +7,8 @@
using System;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class SintPlcMapper : PlcMapperBase
{
@@ -19,5 +19,4 @@ public class SintPlcMapper : PlcMapperBase
override public void Encode(Tag tag, int offset, sbyte value) => tag.SetInt8(offset, value);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/StringPlcMapper.cs b/src/libplctag/DataTypes/StringPlcMapper.cs
index b5da622f..5bf95cd0 100644
--- a/src/libplctag/DataTypes/StringPlcMapper.cs
+++ b/src/libplctag/DataTypes/StringPlcMapper.cs
@@ -9,8 +9,8 @@
using System.Collections.Generic;
using System.Text;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class StringPlcMapper : PlcMapperBase
{
@@ -36,5 +36,4 @@ override public int? ElementSize
override public string Decode(Tag tag, int offset) => tag.GetString(offset);
override public void Encode(Tag tag, int offset, string value) => tag.SetString(offset, value);
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/TagInfoPlcMapper.cs b/src/libplctag/DataTypes/TagInfoPlcMapper.cs
index c26049b7..d994acfd 100644
--- a/src/libplctag/DataTypes/TagInfoPlcMapper.cs
+++ b/src/libplctag/DataTypes/TagInfoPlcMapper.cs
@@ -10,8 +10,7 @@
using System.Linq;
using System.Text;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class TagInfo
@@ -97,6 +96,4 @@ 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;
}
- }
-
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/TimerPlcMapper.cs b/src/libplctag/DataTypes/TimerPlcMapper.cs
index 46547ea3..044c652a 100644
--- a/src/libplctag/DataTypes/TimerPlcMapper.cs
+++ b/src/libplctag/DataTypes/TimerPlcMapper.cs
@@ -10,8 +10,8 @@
using System.Collections.Generic;
using System.Text;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
+
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class TimerPlcMapper : PlcMapperBase
{
@@ -80,5 +80,4 @@ public class AbTimer
public bool Enabled { get; set; }
public bool InProgress { get; set; }
public bool Done { get; set; }
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/UdtInfoPlcMapper.cs b/src/libplctag/DataTypes/UdtInfoPlcMapper.cs
index 5b82ab96..0c53fe4e 100644
--- a/src/libplctag/DataTypes/UdtInfoPlcMapper.cs
+++ b/src/libplctag/DataTypes/UdtInfoPlcMapper.cs
@@ -10,8 +10,7 @@
using System.Linq;
using System.Text;
-namespace libplctag.DataTypes
-{
+namespace libplctag.DataTypes;
[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
public class UdtFieldInfo
@@ -107,6 +106,4 @@ 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;
}
- }
-
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/DebugLevel.cs b/src/libplctag/DebugLevel.cs
index 5396f011..45bed688 100644
--- a/src/libplctag/DebugLevel.cs
+++ b/src/libplctag/DebugLevel.cs
@@ -7,8 +7,8 @@
using libplctag.NativeImport;
-namespace libplctag
-{
+namespace libplctag;
+
///
/// Debug levels available in the base libplctag library
///
@@ -31,5 +31,4 @@ public enum DebugLevel
///
Spew = DEBUG_LEVEL.PLCTAG_DEBUG_SPEW
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/Event.cs b/src/libplctag/Event.cs
index 46a1d8a5..905b8e52 100644
--- a/src/libplctag/Event.cs
+++ b/src/libplctag/Event.cs
@@ -7,8 +7,8 @@
using libplctag.NativeImport;
-namespace libplctag
-{
+namespace libplctag;
+
///
/// Events returned by the base libplctag library
///
@@ -34,5 +34,4 @@ public enum Event
///
Created = EVENT.PLCTAG_EVENT_CREATED
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/INative.cs b/src/libplctag/INative.cs
index ebc82cd9..79c0e42f 100644
--- a/src/libplctag/INative.cs
+++ b/src/libplctag/INative.cs
@@ -14,8 +14,8 @@
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
-namespace libplctag
-{
+namespace libplctag;
+
interface INative
{
int plc_tag_abort(int tag);
@@ -69,5 +69,4 @@ interface INative
int plc_tag_get_string_total_length(int tag, int string_start_offset);
int plc_tag_get_string_capacity(int tag, int string_start_offset);
int plc_tag_set_string(int tag, int string_start_offset, string string_val);
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/ITag.cs b/src/libplctag/ITag.cs
index 48c14a25..3bf88b76 100644
--- a/src/libplctag/ITag.cs
+++ b/src/libplctag/ITag.cs
@@ -9,8 +9,8 @@
using System.Threading;
using System.Threading.Tasks;
-namespace libplctag
-{
+namespace libplctag;
+
///
/// An interface to represent any generic tag without
/// exposing its value
@@ -48,5 +48,4 @@ public interface ITag : IDisposable
Task WriteAsync(CancellationToken token = default);
object Value { get; set; }
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/LibPlcTag.cs b/src/libplctag/LibPlcTag.cs
index 30f05ce1..6581ec85 100644
--- a/src/libplctag/LibPlcTag.cs
+++ b/src/libplctag/LibPlcTag.cs
@@ -8,8 +8,8 @@
using System;
using static libplctag.NativeImport.plctag;
-namespace libplctag
-{
+namespace libplctag;
+
///
/// A static class used to access some additional features of the libplctag base library
///
@@ -118,5 +118,4 @@ static public void Shutdown()
_native.plc_tag_shutdown();
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/LibPlcTagException.cs b/src/libplctag/LibPlcTagException.cs
index 8c430168..f83869fa 100644
--- a/src/libplctag/LibPlcTagException.cs
+++ b/src/libplctag/LibPlcTagException.cs
@@ -7,8 +7,7 @@
using System;
-namespace libplctag
-{
+namespace libplctag;
///
/// An exception thrown by the underlying libplctag library
@@ -36,5 +35,4 @@ public LibPlcTagException(Status status)
{
Status = status;
}
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/LogEventArgs.cs b/src/libplctag/LogEventArgs.cs
index 55565cd4..3d6d8a6a 100644
--- a/src/libplctag/LogEventArgs.cs
+++ b/src/libplctag/LogEventArgs.cs
@@ -7,11 +7,10 @@
using System;
-namespace libplctag
-{
+namespace libplctag;
+
public class LogEventArgs : EventArgs
{
public DebugLevel DebugLevel { get; set; }
public string Message { get; set; }
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/Native.cs b/src/libplctag/Native.cs
index 9a2d2f78..3389cabd 100644
--- a/src/libplctag/Native.cs
+++ b/src/libplctag/Native.cs
@@ -10,8 +10,8 @@
using libplctag.NativeImport;
using static libplctag.NativeImport.plctag;
-namespace libplctag
-{
+namespace libplctag;
+
class Native : INative
{
public int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch) => plctag.plc_tag_check_lib_version(req_major, req_minor, req_patch);
@@ -65,5 +65,4 @@ class Native : INative
public int plc_tag_get_string_total_length(int tag, int string_start_offset) => plctag.plc_tag_get_string_total_length(tag, string_start_offset);
public int plc_tag_get_string_capacity(int tag, int string_start_offset) => plctag.plc_tag_get_string_capacity(tag, string_start_offset);
public int plc_tag_set_string(int tag, int string_start_offset, string string_val) => plctag.plc_tag_set_string(tag, string_start_offset, string_val);
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/PlcType.cs b/src/libplctag/PlcType.cs
index f2f77af2..43cfe9cf 100644
--- a/src/libplctag/PlcType.cs
+++ b/src/libplctag/PlcType.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag
-{
+namespace libplctag;
+
public enum PlcType
{
///
@@ -43,5 +43,4 @@ public enum PlcType
/// Omron PLC. Synonym for omron-njnx, omron-nj, omron-nx, njnx, nx1p2
///
Omron,
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/Protocol.cs b/src/libplctag/Protocol.cs
index 58cffb01..d9c59211 100644
--- a/src/libplctag/Protocol.cs
+++ b/src/libplctag/Protocol.cs
@@ -5,8 +5,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
-namespace libplctag
-{
+namespace libplctag;
+
public enum Protocol
{
///
@@ -18,5 +18,4 @@ public enum Protocol
/// A Modbus TCP implementation used by many PLCs
///
modbus_tcp
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/Status.cs b/src/libplctag/Status.cs
index 1a0f152b..cb86dd2e 100644
--- a/src/libplctag/Status.cs
+++ b/src/libplctag/Status.cs
@@ -7,8 +7,8 @@
using libplctag.NativeImport;
-namespace libplctag
-{
+namespace libplctag;
+
public enum Status
{
///
@@ -133,5 +133,4 @@ public enum Status
///
ErrorBusy = STATUS.PLCTAG_ERR_BUSY
- }
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/src/libplctag/Tag.cs b/src/libplctag/Tag.cs
index 730b346f..f8168775 100644
--- a/src/libplctag/Tag.cs
+++ b/src/libplctag/Tag.cs
@@ -18,8 +18,7 @@
[assembly: InternalsVisibleTo("libplctag.Tests")]
-namespace libplctag
-{
+namespace libplctag;
public sealed class Tag : IDisposable
{
@@ -1337,6 +1336,4 @@ void coreLibEventCallback(int eventTagHandle, int eventCode, int statusCode, Int
}
}
- }
-
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/TagEventArgs.cs b/src/libplctag/TagEventArgs.cs
index c053d122..8f3efee0 100644
--- a/src/libplctag/TagEventArgs.cs
+++ b/src/libplctag/TagEventArgs.cs
@@ -7,10 +7,9 @@
using System;
-namespace libplctag
-{
+namespace libplctag;
+
public class TagEventArgs : EventArgs
{
public Status Status { get; set; }
- }
-}
+ }
\ No newline at end of file
diff --git a/src/libplctag/TagOfT.cs b/src/libplctag/TagOfT.cs
index 40214523..9e4c2f2a 100644
--- a/src/libplctag/TagOfT.cs
+++ b/src/libplctag/TagOfT.cs
@@ -10,8 +10,8 @@
using System.Threading;
using System.Threading.Tasks;
-namespace libplctag
-{
+namespace libplctag;
+
///
/// A class that allows for strongly-typed objects tied to PLC tags
///
@@ -257,5 +257,4 @@ void EncodeAll()
public event EventHandler Aborted;
public event EventHandler Destroyed;
- }
-}
+ }
\ No newline at end of file
From 6192351d5799f238384bde2776c54876eaa77713 Mon Sep 17 00:00:00 2001
From: Mitch Razga <74954528+MitchRazga@users.noreply.github.com>
Date: Tue, 2 Jun 2026 07:56:56 +1000
Subject: [PATCH 3/3] Fix indentation
---
src/libplctag.NativeImport/CONN_STATUS.cs | 74 +--
src/libplctag.NativeImport/DEBUG_LEVEL.cs | 78 +--
src/libplctag.NativeImport/DEBUG_MODULE.cs | 70 +--
src/libplctag.NativeImport/EVENT.cs | 130 ++---
src/libplctag.NativeImport/NativeMethods.cs | 266 +++++-----
src/libplctag.NativeImport/STATUS.cs | 422 +++++++--------
src/libplctag.NativeImport/plctag.cs | 502 +++++++++---------
src/libplctag.Tests/AsyncTests.cs | 242 ++++-----
src/libplctag.Tests/DisposeTests.cs | 124 ++---
src/libplctag.Tests/OtherTests.cs | 86 +--
src/libplctag/DataTypes/BoolPlcMapper.cs | 80 +--
src/libplctag/DataTypes/DintPlcMapper.cs | 14 +-
.../DataTypes/Extensions/ArrayExtensions.cs | 160 +++---
src/libplctag/DataTypes/IPlcMapper.cs | 90 ++--
src/libplctag/DataTypes/IntPlcMapper.cs | 14 +-
src/libplctag/DataTypes/LintPlcMapper.cs | 14 +-
src/libplctag/DataTypes/LrealPlcMapper.cs | 14 +-
src/libplctag/DataTypes/PlcMapperBase.cs | 88 +--
src/libplctag/DataTypes/RealPlcMapper.cs | 14 +-
src/libplctag/DataTypes/SintPlcMapper.cs | 14 +-
src/libplctag/DataTypes/StringPlcMapper.cs | 36 +-
src/libplctag/DataTypes/TimerPlcMapper.cs | 110 ++--
src/libplctag/DebugLevel.cs | 36 +-
src/libplctag/Event.cs | 40 +-
src/libplctag/INative.cs | 108 ++--
src/libplctag/ITag.cs | 70 +--
src/libplctag/LibPlcTag.cs | 180 +++----
src/libplctag/LogEventArgs.cs | 10 +-
src/libplctag/Native.cs | 108 ++--
src/libplctag/PlcType.cs | 74 +--
src/libplctag/Protocol.cs | 22 +-
src/libplctag/Status.cs | 170 +++---
src/libplctag/TagEventArgs.cs | 8 +-
src/libplctag/TagOfT.cs | 414 +++++++--------
34 files changed, 1941 insertions(+), 1941 deletions(-)
diff --git a/src/libplctag.NativeImport/CONN_STATUS.cs b/src/libplctag.NativeImport/CONN_STATUS.cs
index de5413c4..9f8caab2 100644
--- a/src/libplctag.NativeImport/CONN_STATUS.cs
+++ b/src/libplctag.NativeImport/CONN_STATUS.cs
@@ -7,47 +7,47 @@
namespace libplctag.NativeImport;
+///
+/// You can query the connection status of a tag using the connection_status attribute
+/// with :
+///
+/// int status = plc_tag_get_int_attribute(tag, "connection_status", PLCTAG_CONN_STATUS_DOWN);
+///
+///
+/// This attribute is read-only and can be queried at any time after tag creation.
+/// It is useful for determining the current state of the connection to the PLC
+/// and can be used in conjunction with callbacks to monitor connection lifecycle events.
+///
+///
+public enum CONN_STATUS
+{
///
- /// You can query the connection status of a tag using the connection_status attribute
- /// with :
- ///
- /// int status = plc_tag_get_int_attribute(tag, "connection_status", PLCTAG_CONN_STATUS_DOWN);
- ///
- ///
- /// This attribute is read-only and can be queried at any time after tag creation.
- /// It is useful for determining the current state of the connection to the PLC
- /// and can be used in conjunction with callbacks to monitor connection lifecycle events.
- ///
+ /// Connected and ready for communication.
///
- public enum CONN_STATUS
- {
- ///
- /// Connected and ready for communication.
- ///
- PLCTAG_CONN_STATUS_UP = 0,
+ PLCTAG_CONN_STATUS_UP = 0,
- ///
- /// Not connected.
- ///
- PLCTAG_CONN_STATUS_DOWN = 1,
+ ///
+ /// Not connected.
+ ///
+ PLCTAG_CONN_STATUS_DOWN = 1,
- ///
- /// Disconnection in progress.
- ///
- PLCTAG_CONN_STATUS_DISCONNECTING = 2,
+ ///
+ /// Disconnection in progress.
+ ///
+ PLCTAG_CONN_STATUS_DISCONNECTING = 2,
- ///
- /// Connection in progress.
- ///
- PLCTAG_CONN_STATUS_CONNECTING = 3,
+ ///
+ /// Connection in progress.
+ ///
+ PLCTAG_CONN_STATUS_CONNECTING = 3,
- ///
- /// Waiting to reconnect after disconnect.
- ///
- PLCTAG_CONN_STATUS_IDLE_WAIT = 4,
+ ///
+ /// Waiting to reconnect after disconnect.
+ ///
+ PLCTAG_CONN_STATUS_IDLE_WAIT = 4,
- ///
- /// Waiting to retry after error.
- ///
- PLCTAG_CONN_STATUS_ERR_WAIT = 5
- }
\ No newline at end of file
+ ///
+ /// Waiting to retry after error.
+ ///
+ PLCTAG_CONN_STATUS_ERR_WAIT = 5
+}
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/DEBUG_LEVEL.cs b/src/libplctag.NativeImport/DEBUG_LEVEL.cs
index 84e5da0c..86b246a4 100644
--- a/src/libplctag.NativeImport/DEBUG_LEVEL.cs
+++ b/src/libplctag.NativeImport/DEBUG_LEVEL.cs
@@ -7,49 +7,49 @@
namespace libplctag.NativeImport;
+///
+/// The library provides debugging output when enabled.
+/// There are three ways to set the debug level (for historical reasons):
+///
+/// Adding a debug attribute to the attribute string when creating a tag: "protocol=XXX&...&debug=4".
+/// Using the function to set the debug attribute.
+/// Using the function.
+///
+/// The preferred method in code is the last one.
+///
+public enum DEBUG_LEVEL
+{
///
- /// The library provides debugging output when enabled.
- /// There are three ways to set the debug level (for historical reasons):
- ///
- /// Adding a debug attribute to the attribute string when creating a tag: "protocol=XXX&...&debug=4".
- /// Using the function to set the debug attribute.
- /// Using the function.
- ///
- /// The preferred method in code is the last one.
+ /// Disables debugging output.
///
- public enum DEBUG_LEVEL
- {
- ///
- /// Disables debugging output.
- ///
- PLCTAG_DEBUG_NONE = 0,
+ PLCTAG_DEBUG_NONE = 0,
- ///
- /// Only output errors. Generally these are fatal to the functioning of the library.
- ///
- PLCTAG_DEBUG_ERROR = 1,
+ ///
+ /// Only output errors. Generally these are fatal to the functioning of the library.
+ ///
+ PLCTAG_DEBUG_ERROR = 1,
- ///
- /// Outputs warnings such as error found when checking a malformed tag attribute string or when unexpected problems are reported from the PLC.
- ///
- PLCTAG_DEBUG_WARN = 2,
+ ///
+ /// Outputs warnings such as error found when checking a malformed tag attribute string or when unexpected problems are reported from the PLC.
+ ///
+ PLCTAG_DEBUG_WARN = 2,
- ///
- /// Outputs diagnostic information about the internal calls within the library.
- /// Includes some packet dumps.
- ///
- PLCTAG_DEBUG_INFO = 3,
+ ///
+ /// Outputs diagnostic information about the internal calls within the library.
+ /// Includes some packet dumps.
+ ///
+ PLCTAG_DEBUG_INFO = 3,
- ///
- /// Outputs detailed diagnostic information about the code executing within the library including packet dumps.
- ///
- PLCTAG_DEBUG_DETAIL = 4,
+ ///
+ /// Outputs detailed diagnostic information about the code executing within the library including packet dumps.
+ ///
+ PLCTAG_DEBUG_DETAIL = 4,
- ///
- /// Outputs extremely detailed information.
- /// Do not use this unless you are trying to debug detailed information about every mutex lock and release.
- /// Will output many lines of output per millisecond.
- /// You have been warned!
- ///
- PLCTAG_DEBUG_SPEW = 5
- }
\ No newline at end of file
+ ///
+ /// Outputs extremely detailed information.
+ /// Do not use this unless you are trying to debug detailed information about every mutex lock and release.
+ /// Will output many lines of output per millisecond.
+ /// You have been warned!
+ ///
+ PLCTAG_DEBUG_SPEW = 5
+}
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/DEBUG_MODULE.cs b/src/libplctag.NativeImport/DEBUG_MODULE.cs
index d8714143..a769ae3e 100644
--- a/src/libplctag.NativeImport/DEBUG_MODULE.cs
+++ b/src/libplctag.NativeImport/DEBUG_MODULE.cs
@@ -7,38 +7,38 @@
namespace libplctag.NativeImport;
- ///
- /// The library supports setting debug levels for individual modules.
- /// This allows for fine-grained control over which subsystems produce debug output.
- /// Used with and .
- ///
- public enum DEBUG_MODULE
- {
- PLCTAG_MODULE_LIB = 0,
- PLCTAG_MODULE_INIT = 1,
- PLCTAG_MODULE_VERSION = 2,
- PLCTAG_MODULE_UTILS = 3,
- PLCTAG_MODULE_AB_SESSION = 4,
- PLCTAG_MODULE_AB_PCCC = 5,
- PLCTAG_MODULE_AB_CIP = 6,
- PLCTAG_MODULE_AB_COMMON = 7,
- PLCTAG_MODULE_AB_EIP_CIP = 8,
- PLCTAG_MODULE_AB_EIP_CIP_SPECIAL = 9,
- PLCTAG_MODULE_AB_EIP_LGX_PCCC = 10,
- PLCTAG_MODULE_AB_EIP_PLC5_PCCC = 11,
- PLCTAG_MODULE_AB_EIP_PLC5_DHP = 12,
- PLCTAG_MODULE_AB_EIP_SLC_PCCC = 13,
- PLCTAG_MODULE_AB_EIP_SLC_DHP = 14,
- PLCTAG_MODULE_AB_ERROR = 15,
- PLCTAG_MODULE_OMRON_CONN = 16,
- PLCTAG_MODULE_OMRON_CIP = 17,
- PLCTAG_MODULE_OMRON_COMMON = 18,
- PLCTAG_MODULE_OMRON_STANDARD_TAG = 19,
- PLCTAG_MODULE_OMRON_RAW_TAG = 20,
- PLCTAG_MODULE_MODBUS = 21,
- PLCTAG_MODULE_SYSTEM = 22,
- PLCTAG_MODULE_PLATFORM = 23,
- PLCTAG_MODULE_AB_CONNECTION = 24,
- PLCTAG_MODULE_MB_CONNECTION = 25,
- PLCTAG_MODULE_OMRON_CONNECTION = 26,
- }
\ No newline at end of file
+///
+/// The library supports setting debug levels for individual modules.
+/// This allows for fine-grained control over which subsystems produce debug output.
+/// Used with and .
+///
+public enum DEBUG_MODULE
+{
+ PLCTAG_MODULE_LIB = 0,
+ PLCTAG_MODULE_INIT = 1,
+ PLCTAG_MODULE_VERSION = 2,
+ PLCTAG_MODULE_UTILS = 3,
+ PLCTAG_MODULE_AB_SESSION = 4,
+ PLCTAG_MODULE_AB_PCCC = 5,
+ PLCTAG_MODULE_AB_CIP = 6,
+ PLCTAG_MODULE_AB_COMMON = 7,
+ PLCTAG_MODULE_AB_EIP_CIP = 8,
+ PLCTAG_MODULE_AB_EIP_CIP_SPECIAL = 9,
+ PLCTAG_MODULE_AB_EIP_LGX_PCCC = 10,
+ PLCTAG_MODULE_AB_EIP_PLC5_PCCC = 11,
+ PLCTAG_MODULE_AB_EIP_PLC5_DHP = 12,
+ PLCTAG_MODULE_AB_EIP_SLC_PCCC = 13,
+ PLCTAG_MODULE_AB_EIP_SLC_DHP = 14,
+ PLCTAG_MODULE_AB_ERROR = 15,
+ PLCTAG_MODULE_OMRON_CONN = 16,
+ PLCTAG_MODULE_OMRON_CIP = 17,
+ PLCTAG_MODULE_OMRON_COMMON = 18,
+ PLCTAG_MODULE_OMRON_STANDARD_TAG = 19,
+ PLCTAG_MODULE_OMRON_RAW_TAG = 20,
+ PLCTAG_MODULE_MODBUS = 21,
+ PLCTAG_MODULE_SYSTEM = 22,
+ PLCTAG_MODULE_PLATFORM = 23,
+ PLCTAG_MODULE_AB_CONNECTION = 24,
+ PLCTAG_MODULE_MB_CONNECTION = 25,
+ PLCTAG_MODULE_OMRON_CONNECTION = 26,
+}
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/EVENT.cs b/src/libplctag.NativeImport/EVENT.cs
index 6f2ad72b..58a1bea2 100644
--- a/src/libplctag.NativeImport/EVENT.cs
+++ b/src/libplctag.NativeImport/EVENT.cs
@@ -7,82 +7,82 @@
namespace libplctag.NativeImport;
+///
+/// The library provides functions to register a callback on a tag.
+/// These events generate a call to that callback.
+///
+public enum EVENT
+{
///
- /// The library provides functions to register a callback on a tag.
- /// These events generate a call to that callback.
+ /// A read of the tag has been requested.
+ /// The callback is called immediately before the underlying protocol implementation is called.
///
- public enum EVENT
- {
- ///
- /// A read of the tag has been requested.
- /// The callback is called immediately before the underlying protocol implementation is called.
- ///
- PLCTAG_EVENT_READ_STARTED = 1,
+ PLCTAG_EVENT_READ_STARTED = 1,
- ///
- /// The callback is called after a read completes.
- /// The final status of the read is passed to the callback as well.
- ///
- PLCTAG_EVENT_READ_COMPLETED = 2,
+ ///
+ /// The callback is called after a read completes.
+ /// The final status of the read is passed to the callback as well.
+ ///
+ PLCTAG_EVENT_READ_COMPLETED = 2,
- ///
- /// As with reads, the callback is called when a write is requested.
- /// The callback can change the data in the tag and the changes will be sent to the PLC.
- ///
- PLCTAG_EVENT_WRITE_STARTED = 3,
+ ///
+ /// As with reads, the callback is called when a write is requested.
+ /// The callback can change the data in the tag and the changes will be sent to the PLC.
+ ///
+ PLCTAG_EVENT_WRITE_STARTED = 3,
- ///
- /// The callback is called when the PLC indicates that the write has completed.
- /// The status of the write is passed to the callback.
- ///
- PLCTAG_EVENT_WRITE_COMPLETED = 4,
+ ///
+ /// The callback is called when the PLC indicates that the write has completed.
+ /// The status of the write is passed to the callback.
+ ///
+ PLCTAG_EVENT_WRITE_COMPLETED = 4,
- ///
- /// The callback function is called when something calls on the tag.
- ///
- PLCTAG_EVENT_ABORTED = 5,
+ ///
+ /// The callback function is called when something calls on the tag.
+ ///
+ PLCTAG_EVENT_ABORTED = 5,
- ///
- /// The callback function is called when the tag is being destroyed.
- /// It is not safe to call any API functions on the tag at this time.
- /// This is purely for the callback to manage any application state.
- ///
- PLCTAG_EVENT_DESTROYED = 6,
+ ///
+ /// The callback function is called when the tag is being destroyed.
+ /// It is not safe to call any API functions on the tag at this time.
+ /// This is purely for the callback to manage any application state.
+ ///
+ PLCTAG_EVENT_DESTROYED = 6,
- ///
- /// The callback is called after a tag creation completes.
- /// The final status of the creation is passed to the callback as well.
- /// This is not as well supported in some cases, so only depend on this for normal tags and not tags like @tags.
- ///
- PLCTAG_EVENT_CREATED = 7,
+ ///
+ /// The callback is called after a tag creation completes.
+ /// The final status of the creation is passed to the callback as well.
+ /// This is not as well supported in some cases, so only depend on this for normal tags and not tags like @tags.
+ ///
+ PLCTAG_EVENT_CREATED = 7,
- ///
- /// The underlying connection is established and ready for operations.
- ///
- PLCTAG_EVENT_CONN_STATUS_UP = 100,
+ ///
+ /// The underlying connection is established and ready for operations.
+ ///
+ PLCTAG_EVENT_CONN_STATUS_UP = 100,
- ///
- /// The connection is not established.
- ///
- PLCTAG_EVENT_CONN_STATUS_DOWN = 101,
+ ///
+ /// The connection is not established.
+ ///
+ PLCTAG_EVENT_CONN_STATUS_DOWN = 101,
- ///
- /// The connection is in the process of disconnecting.
- ///
- PLCTAG_EVENT_CONN_STATUS_DISCONNECTING = 102,
+ ///
+ /// The connection is in the process of disconnecting.
+ ///
+ PLCTAG_EVENT_CONN_STATUS_DISCONNECTING = 102,
- ///
- /// The connection is in the process of being established.
- ///
- PLCTAG_EVENT_CONN_STATUS_CONNECTING = 103,
+ ///
+ /// The connection is in the process of being established.
+ ///
+ PLCTAG_EVENT_CONN_STATUS_CONNECTING = 103,
- ///
- /// Waiting to reconnect after an idle disconnect.
- ///
- PLCTAG_EVENT_CONN_STATUS_IDLE_WAIT = 104,
+ ///
+ /// Waiting to reconnect after an idle disconnect.
+ ///
+ PLCTAG_EVENT_CONN_STATUS_IDLE_WAIT = 104,
- ///
- /// Waiting to reconnect after an error.
- ///
- PLCTAG_EVENT_CONN_STATUS_ERR_WAIT = 105,
- }
\ No newline at end of file
+ ///
+ /// Waiting to reconnect after an error.
+ ///
+ PLCTAG_EVENT_CONN_STATUS_ERR_WAIT = 105,
+}
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/NativeMethods.cs b/src/libplctag.NativeImport/NativeMethods.cs
index 1336756d..f0b1c9ff 100644
--- a/src/libplctag.NativeImport/NativeMethods.cs
+++ b/src/libplctag.NativeImport/NativeMethods.cs
@@ -12,255 +12,255 @@
namespace libplctag.NativeImport;
- static class NativeMethods
- {
+static class NativeMethods
+{
- const string DLL_NAME = "plctag";
+ const string DLL_NAME = "plctag";
- static NativeMethods()
- {
+ static NativeMethods()
+ {
#if NET472_OR_GREATER
- // Assume we're running on Windows because .NET Framework is not supported on other platforms
- string executingDirectory = System.IO.Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location);
- string system = Environment.Is64BitProcess ? "X64" : "X86";
- string libDirectory = System.IO.Path.Combine (executingDirectory, system);
- if (System.IO.Directory.Exists(libDirectory))
- {
- SetDllDirectory(libDirectory);
- }
- else
- {
- SetDllDirectory(executingDirectory);
- }
-#endif
+ // Assume we're running on Windows because .NET Framework is not supported on other platforms
+ string executingDirectory = System.IO.Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location);
+ string system = Environment.Is64BitProcess ? "X64" : "X86";
+ string libDirectory = System.IO.Path.Combine (executingDirectory, system);
+ if (System.IO.Directory.Exists(libDirectory))
+ {
+ SetDllDirectory(libDirectory);
+ }
+ else
+ {
+ SetDllDirectory(executingDirectory);
}
+#endif
+ }
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool SetDllDirectory(string lpPathName);
+ [DllImport("kernel32.dll", SetLastError = true)]
+ private static extern bool SetDllDirectory(string lpPathName);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_check_lib_version), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_check_lib_version), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern Int32 plc_tag_create([MarshalAs(UnmanagedType.LPStr)] string lpString, int timeout);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern Int32 plc_tag_create([MarshalAs(UnmanagedType.LPStr)] string lpString, int timeout);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create_ex), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern Int32 plc_tag_create_ex([MarshalAs(UnmanagedType.LPStr)] string lpString, callback_func_ex func, IntPtr userdata, int timeout);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create_ex), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern Int32 plc_tag_create_ex([MarshalAs(UnmanagedType.LPStr)] string lpString, callback_func_ex func, IntPtr userdata, int timeout);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create_from_tag), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern Int32 plc_tag_create_from_tag(Int32 src_tag_id, [MarshalAs(UnmanagedType.LPStr)] string attrib_str, callback_func_ex func, IntPtr userdata, int timeout);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create_from_tag), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern Int32 plc_tag_create_from_tag(Int32 src_tag_id, [MarshalAs(UnmanagedType.LPStr)] string attrib_str, callback_func_ex func, IntPtr userdata, int timeout);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_destroy), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_destroy(Int32 tag);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_destroy), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_destroy(Int32 tag);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_shutdown), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void plc_tag_shutdown();
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_shutdown), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern void plc_tag_shutdown();
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_callback), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_register_callback(Int32 tag_id, callback_func func);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_callback), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_register_callback(Int32 tag_id, callback_func func);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_callback_ex), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_register_callback_ex(Int32 tag_id, callback_func_ex func, IntPtr userdata);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_callback_ex), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_register_callback_ex(Int32 tag_id, callback_func_ex func, IntPtr userdata);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unregister_callback), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_unregister_callback(Int32 tag_id);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unregister_callback), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_unregister_callback(Int32 tag_id);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_logger), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_register_logger(log_callback_func func);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_logger), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_register_logger(log_callback_func func);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unregister_logger), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_unregister_logger();
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unregister_logger), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_unregister_logger();
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_lock), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_lock(Int32 tag);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_lock), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_lock(Int32 tag);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unlock), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_unlock(Int32 tag);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unlock), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_unlock(Int32 tag);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_status), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_status(Int32 tag);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_status), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_status(Int32 tag);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_decode_error), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern IntPtr plc_tag_decode_error(int err);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_decode_error), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern IntPtr plc_tag_decode_error(int err);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_read), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_read(Int32 tag, int timeout);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_read), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_read(Int32 tag, int timeout);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_write), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_write(Int32 tag, int timeout);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_write), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_write(Int32 tag, int timeout);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_size), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_size(Int32 tag);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_size), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_size(Int32 tag);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_size), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_size(Int32 tag, int new_size);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_size), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_size(Int32 tag, int new_size);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_abort), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_abort(Int32 tag);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_abort), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_abort(Int32 tag);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int_attribute), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern int plc_tag_get_int_attribute(Int32 tag, [MarshalAs(UnmanagedType.LPStr)] string attrib_name, int default_value);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int_attribute), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern int plc_tag_get_int_attribute(Int32 tag, [MarshalAs(UnmanagedType.LPStr)] string attrib_name, int default_value);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int_attribute), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern int plc_tag_set_int_attribute(Int32 tag, [MarshalAs(UnmanagedType.LPStr)] string attrib_name, int new_value);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int_attribute), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern int plc_tag_set_int_attribute(Int32 tag, [MarshalAs(UnmanagedType.LPStr)] string attrib_name, int new_value);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_byte_array_attribute), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern int plc_tag_get_byte_array_attribute(Int32 tag, [MarshalAs(UnmanagedType.LPStr)] string attrib_name, [In] byte[] buffer, int buffer_length);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_byte_array_attribute), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern int plc_tag_get_byte_array_attribute(Int32 tag, [MarshalAs(UnmanagedType.LPStr)] string attrib_name, [In] byte[] buffer, int buffer_length);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern UInt64 plc_tag_get_uint64(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern UInt64 plc_tag_get_uint64(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Int64 plc_tag_get_int64(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern Int64 plc_tag_get_int64(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_uint64(Int32 tag, int offset, UInt64 val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_uint64(Int32 tag, int offset, UInt64 val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_int64(Int32 tag, int offset, Int64 val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_int64(Int32 tag, int offset, Int64 val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_float64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern double plc_tag_get_float64(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_float64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern double plc_tag_get_float64(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_float64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_float64(Int32 tag, int offset, double val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_float64), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_float64(Int32 tag, int offset, double val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern UInt32 plc_tag_get_uint32(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern UInt32 plc_tag_get_uint32(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Int32 plc_tag_get_int32(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern Int32 plc_tag_get_int32(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_uint32(Int32 tag, int offset, UInt32 val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_uint32(Int32 tag, int offset, UInt32 val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_int32(Int32 tag, int offset, Int32 val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_int32(Int32 tag, int offset, Int32 val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_float32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern float plc_tag_get_float32(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_float32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern float plc_tag_get_float32(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_float32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_float32(Int32 tag, int offset, float val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_float32), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_float32(Int32 tag, int offset, float val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern UInt16 plc_tag_get_uint16(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern UInt16 plc_tag_get_uint16(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Int16 plc_tag_get_int16(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern Int16 plc_tag_get_int16(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_uint16(Int32 tag, int offset, UInt16 val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_uint16(Int32 tag, int offset, UInt16 val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_int16(Int32 tag, int offset, Int16 val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int16), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_int16(Int32 tag, int offset, Int16 val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern byte plc_tag_get_uint8(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_uint8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern byte plc_tag_get_uint8(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern sbyte plc_tag_get_int8(Int32 tag, int offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_int8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern sbyte plc_tag_get_int8(Int32 tag, int offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_uint8(Int32 tag, int offset, byte val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_uint8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_uint8(Int32 tag, int offset, byte val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_int8(Int32 tag, int offset, sbyte val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_int8), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_int8(Int32 tag, int offset, sbyte val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_bit), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_bit(Int32 tag, int offset_bit);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_bit), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_bit(Int32 tag, int offset_bit);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_bit), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_bit(Int32 tag, int offset_bit, int val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_bit), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_bit(Int32 tag, int offset_bit, int val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_debug_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void plc_tag_set_debug_level(int debug_level);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_debug_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern void plc_tag_set_debug_level(int debug_level);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_debug_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_debug_level();
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_debug_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_debug_level();
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_debug_module_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_debug_module_level(int module, int debug_level);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_debug_module_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_set_debug_module_level(int module, int debug_level);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_debug_module_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_debug_module_level(int module);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_debug_module_level), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_debug_module_level(int module);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern int plc_tag_get_string(Int32 tag_id, int string_start_offset, StringBuilder buffer, int buffer_length);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern int plc_tag_get_string(Int32 tag_id, int string_start_offset, StringBuilder buffer, int buffer_length);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_string), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
- public static extern int plc_tag_set_string(Int32 tag_id, int string_start_offset, [MarshalAs(UnmanagedType.LPStr)] string string_val);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_string), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+ public static extern int plc_tag_set_string(Int32 tag_id, int string_start_offset, [MarshalAs(UnmanagedType.LPStr)] string string_val);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string_length), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_string_length(Int32 tag_id, int string_start_offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string_length), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_string_length(Int32 tag_id, int string_start_offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string_capacity), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_string_capacity(Int32 tag_id, int string_start_offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string_capacity), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_string_capacity(Int32 tag_id, int string_start_offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string_total_length), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_string_total_length(Int32 tag_id, int string_start_offset);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_string_total_length), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern int plc_tag_get_string_total_length(Int32 tag_id, int string_start_offset);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public unsafe static extern int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public unsafe static extern int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
- [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public unsafe static extern int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
- }
\ No newline at end of file
+ [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public unsafe static extern int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
+}
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/STATUS.cs b/src/libplctag.NativeImport/STATUS.cs
index ee76c201..c6f18bc5 100644
--- a/src/libplctag.NativeImport/STATUS.cs
+++ b/src/libplctag.NativeImport/STATUS.cs
@@ -7,215 +7,215 @@
namespace libplctag.NativeImport;
+///
+/// Most functions return a status code.
+/// It will be one of these.
+///
+public enum STATUS
+{
///
- /// Most functions return a status code.
- /// It will be one of these.
- ///
- public enum STATUS
- {
- ///
- /// Operation in progress. Not an error.
- ///
- PLCTAG_STATUS_PENDING = 1,
-
- ///
- /// No error.
- ///
- PLCTAG_STATUS_OK = 0,
-
- ///
- /// The operation was aborted.
- ///
- PLCTAG_ERR_ABORT = -1,
-
- ///
- /// The operation failed due to incorrect configuration. Usually returned from a remote system.
- ///
- PLCTAG_ERR_BAD_CONFIG = -2,
-
- ///
- /// The connection failed for some reason. This can mean that the remote PLC was power cycled, for instance.
- ///
- PLCTAG_ERR_BAD_CONNECTION = -3,
-
- ///
- /// The data received from the remote PLC was undecipherable or otherwise not able to be processed.
- /// Can also be returned from a remote system that cannot process the data sent to it.
- ///
- PLCTAG_ERR_BAD_DATA = -4,
-
- ///
- /// Usually returned from a remote system when something addressed does not exist.
- ///
- PLCTAG_ERR_BAD_DEVICE = -5,
-
- ///
- /// Usually returned when the library is unable to connect to a remote system.
- ///
- PLCTAG_ERR_BAD_GATEWAY = -6,
-
- ///
- /// A common error return when something is not correct with the tag creation attribute string.
- ///
- PLCTAG_ERR_BAD_PARAM = -7,
-
- ///
- /// Usually returned when the remote system returned an unexpected response.
- ///
- PLCTAG_ERR_BAD_REPLY = -8,
-
- ///
- /// Usually returned by a remote system when something is not in a good state.
- ///
- PLCTAG_ERR_BAD_STATUS = -9,
-
- ///
- /// An error occurred trying to close some resource.
- ///
- PLCTAG_ERR_CLOSE = -10,
-
- ///
- /// An error occurred trying to create some internal resource.
- ///
- PLCTAG_ERR_CREATE = -11,
-
- ///
- /// An error returned by a remote system when something is incorrectly duplicated (i.e. a duplicate connection ID).
- ///
- PLCTAG_ERR_DUPLICATE = -12,
-
- ///
- /// An error was returned when trying to encode some data such as a tag name.
- ///
- PLCTAG_ERR_ENCODE = -13,
-
- ///
- /// An internal library error. It would be very unusual to see this.
- ///
- PLCTAG_ERR_MUTEX_DESTROY = -14,
-
- ///
- /// An internal library error. It would be very unusual to see this.
- ///
- PLCTAG_ERR_MUTEX_INIT = -15,
-
- ///
- /// An internal library error. It would be very unusual to see this.
- ///
- PLCTAG_ERR_MUTEX_LOCK = -16,
-
- ///
- /// An internal library error. It would be very unusual to see this.
- ///
- PLCTAG_ERR_MUTEX_UNLOCK = -17,
-
- ///
- /// Often returned from the remote system when an operation is not permitted.
- ///
- PLCTAG_ERR_NOT_ALLOWED = -18,
-
- ///
- /// Often returned from the remote system when something is not found.
- ///
- PLCTAG_ERR_NOT_FOUND = -19,
-
- ///
- /// returned when a valid operation is not implemented.
- ///
- PLCTAG_ERR_NOT_IMPLEMENTED = -20,
-
- ///
- /// Returned when expected data is not present.
- ///
- PLCTAG_ERR_NO_DATA = -21,
-
- ///
- /// Similar to
- ///
- PLCTAG_ERR_NO_MATCH = -22,
-
- ///
- /// Returned by the library when memory allocation fails.
- ///
- PLCTAG_ERR_NO_MEM = -23,
-
- ///
- /// Returned by the remote system when some resource allocation fails.
- ///
- PLCTAG_ERR_NO_RESOURCES = -24,
-
- ///
- /// Usually an internal error, but can be returned when an invalid handle is used with an API call.
- ///
- PLCTAG_ERR_NULL_PTR = -25,
-
- ///
- /// Returned when an error occurs opening a resource such as a socket.
- ///
- PLCTAG_ERR_OPEN = -26,
-
- ///
- /// Usually returned when trying to write a value into a tag outside of the tag data bounds.
- ///
- PLCTAG_ERR_OUT_OF_BOUNDS = -27,
-
- ///
- /// Returned when an error occurs during a read operation. Usually related to socket problems.
- ///
- PLCTAG_ERR_READ = -28,
-
- ///
- /// An unspecified or untranslatable remote error causes this.
- ///
- PLCTAG_ERR_REMOTE_ERR = -29,
-
- ///
- /// An internal library error. If you see this, it is likely that everything is about to crash.
- ///
- PLCTAG_ERR_THREAD_CREATE = -30,
-
- ///
- /// Another internal library error. It is very unlikely that you will see this.
- ///
- PLCTAG_ERR_THREAD_JOIN = -31,
-
- ///
- /// An operation took too long and timed out.
- ///
- PLCTAG_ERR_TIMEOUT = -32,
-
- ///
- /// More data was returned than was expected.
- ///
- PLCTAG_ERR_TOO_LARGE = -33,
-
- ///
- /// Insufficient data was returned from the remote system.
- ///
- PLCTAG_ERR_TOO_SMALL = -34,
-
- ///
- /// The operation is not supported on the remote system.
- ///
- PLCTAG_ERR_UNSUPPORTED = -35,
-
- ///
- /// A Winsock-specific error occurred (only on Windows).
- ///
- PLCTAG_ERR_WINSOCK = -36,
-
- ///
- /// An error occurred trying to write, usually to a socket.
- ///
- PLCTAG_ERR_WRITE = -37,
-
- ///
- /// Partial data was received or something was unexpectedly incomplete.
- ///
- PLCTAG_ERR_PARTIAL = -38,
-
- ///
- /// The operation cannot be performed as some other operation is taking place.
- ///
- PLCTAG_ERR_BUSY = -39
- }
\ No newline at end of file
+ /// Operation in progress. Not an error.
+ ///
+ PLCTAG_STATUS_PENDING = 1,
+
+ ///
+ /// No error.
+ ///
+ PLCTAG_STATUS_OK = 0,
+
+ ///
+ /// The operation was aborted.
+ ///
+ PLCTAG_ERR_ABORT = -1,
+
+ ///
+ /// The operation failed due to incorrect configuration. Usually returned from a remote system.
+ ///
+ PLCTAG_ERR_BAD_CONFIG = -2,
+
+ ///
+ /// The connection failed for some reason. This can mean that the remote PLC was power cycled, for instance.
+ ///
+ PLCTAG_ERR_BAD_CONNECTION = -3,
+
+ ///
+ /// The data received from the remote PLC was undecipherable or otherwise not able to be processed.
+ /// Can also be returned from a remote system that cannot process the data sent to it.
+ ///
+ PLCTAG_ERR_BAD_DATA = -4,
+
+ ///
+ /// Usually returned from a remote system when something addressed does not exist.
+ ///
+ PLCTAG_ERR_BAD_DEVICE = -5,
+
+ ///
+ /// Usually returned when the library is unable to connect to a remote system.
+ ///
+ PLCTAG_ERR_BAD_GATEWAY = -6,
+
+ ///
+ /// A common error return when something is not correct with the tag creation attribute string.
+ ///
+ PLCTAG_ERR_BAD_PARAM = -7,
+
+ ///
+ /// Usually returned when the remote system returned an unexpected response.
+ ///
+ PLCTAG_ERR_BAD_REPLY = -8,
+
+ ///
+ /// Usually returned by a remote system when something is not in a good state.
+ ///
+ PLCTAG_ERR_BAD_STATUS = -9,
+
+ ///
+ /// An error occurred trying to close some resource.
+ ///
+ PLCTAG_ERR_CLOSE = -10,
+
+ ///
+ /// An error occurred trying to create some internal resource.
+ ///
+ PLCTAG_ERR_CREATE = -11,
+
+ ///
+ /// An error returned by a remote system when something is incorrectly duplicated (i.e. a duplicate connection ID).
+ ///
+ PLCTAG_ERR_DUPLICATE = -12,
+
+ ///
+ /// An error was returned when trying to encode some data such as a tag name.
+ ///
+ PLCTAG_ERR_ENCODE = -13,
+
+ ///
+ /// An internal library error. It would be very unusual to see this.
+ ///
+ PLCTAG_ERR_MUTEX_DESTROY = -14,
+
+ ///
+ /// An internal library error. It would be very unusual to see this.
+ ///
+ PLCTAG_ERR_MUTEX_INIT = -15,
+
+ ///
+ /// An internal library error. It would be very unusual to see this.
+ ///
+ PLCTAG_ERR_MUTEX_LOCK = -16,
+
+ ///
+ /// An internal library error. It would be very unusual to see this.
+ ///
+ PLCTAG_ERR_MUTEX_UNLOCK = -17,
+
+ ///
+ /// Often returned from the remote system when an operation is not permitted.
+ ///
+ PLCTAG_ERR_NOT_ALLOWED = -18,
+
+ ///
+ /// Often returned from the remote system when something is not found.
+ ///
+ PLCTAG_ERR_NOT_FOUND = -19,
+
+ ///
+ /// returned when a valid operation is not implemented.
+ ///
+ PLCTAG_ERR_NOT_IMPLEMENTED = -20,
+
+ ///
+ /// Returned when expected data is not present.
+ ///
+ PLCTAG_ERR_NO_DATA = -21,
+
+ ///
+ /// Similar to
+ ///
+ PLCTAG_ERR_NO_MATCH = -22,
+
+ ///
+ /// Returned by the library when memory allocation fails.
+ ///
+ PLCTAG_ERR_NO_MEM = -23,
+
+ ///
+ /// Returned by the remote system when some resource allocation fails.
+ ///
+ PLCTAG_ERR_NO_RESOURCES = -24,
+
+ ///
+ /// Usually an internal error, but can be returned when an invalid handle is used with an API call.
+ ///
+ PLCTAG_ERR_NULL_PTR = -25,
+
+ ///
+ /// Returned when an error occurs opening a resource such as a socket.
+ ///
+ PLCTAG_ERR_OPEN = -26,
+
+ ///
+ /// Usually returned when trying to write a value into a tag outside of the tag data bounds.
+ ///
+ PLCTAG_ERR_OUT_OF_BOUNDS = -27,
+
+ ///
+ /// Returned when an error occurs during a read operation. Usually related to socket problems.
+ ///
+ PLCTAG_ERR_READ = -28,
+
+ ///
+ /// An unspecified or untranslatable remote error causes this.
+ ///
+ PLCTAG_ERR_REMOTE_ERR = -29,
+
+ ///
+ /// An internal library error. If you see this, it is likely that everything is about to crash.
+ ///
+ PLCTAG_ERR_THREAD_CREATE = -30,
+
+ ///
+ /// Another internal library error. It is very unlikely that you will see this.
+ ///
+ PLCTAG_ERR_THREAD_JOIN = -31,
+
+ ///
+ /// An operation took too long and timed out.
+ ///
+ PLCTAG_ERR_TIMEOUT = -32,
+
+ ///
+ /// More data was returned than was expected.
+ ///
+ PLCTAG_ERR_TOO_LARGE = -33,
+
+ ///
+ /// Insufficient data was returned from the remote system.
+ ///
+ PLCTAG_ERR_TOO_SMALL = -34,
+
+ ///
+ /// The operation is not supported on the remote system.
+ ///
+ PLCTAG_ERR_UNSUPPORTED = -35,
+
+ ///
+ /// A Winsock-specific error occurred (only on Windows).
+ ///
+ PLCTAG_ERR_WINSOCK = -36,
+
+ ///
+ /// An error occurred trying to write, usually to a socket.
+ ///
+ PLCTAG_ERR_WRITE = -37,
+
+ ///
+ /// Partial data was received or something was unexpectedly incomplete.
+ ///
+ PLCTAG_ERR_PARTIAL = -38,
+
+ ///
+ /// The operation cannot be performed as some other operation is taking place.
+ ///
+ PLCTAG_ERR_BUSY = -39
+}
\ No newline at end of file
diff --git a/src/libplctag.NativeImport/plctag.cs b/src/libplctag.NativeImport/plctag.cs
index d8d1ad2b..7a7fde98 100644
--- a/src/libplctag.NativeImport/plctag.cs
+++ b/src/libplctag.NativeImport/plctag.cs
@@ -11,324 +11,324 @@
namespace libplctag.NativeImport;
- ///
- /// This class provides low-level (raw) access to the native libplctag library (which is written in C).
- /// The purpose of this package is to expose the API for this native library, and handle platform and configuration issues.
- ///
- /// See for documentation.
- ///
- public static class plctag
- {
+///
+/// This class provides low-level (raw) access to the native libplctag library (which is written in C).
+/// The purpose of this package is to expose the API for this native library, and handle platform and configuration issues.
+///
+/// See for documentation.
+///
+public static class plctag
+{
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void callback_func(Int32 tag_id, Int32 event_id, Int32 status);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate void callback_func(Int32 tag_id, Int32 event_id, Int32 status);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void callback_func_ex(Int32 tag_id, Int32 event_id, Int32 status, IntPtr userdata);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ public delegate void callback_func_ex(Int32 tag_id, Int32 event_id, Int32 status, IntPtr userdata);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
- public delegate void log_callback_func(Int32 tag_id, int debug_level, [MarshalAs(UnmanagedType.LPStr)] string message);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public delegate void log_callback_func(Int32 tag_id, int debug_level, [MarshalAs(UnmanagedType.LPStr)] string message);
- public static int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch)
- {
- return NativeMethods.plc_tag_check_lib_version(req_major, req_minor, req_patch);
- }
+ public static int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch)
+ {
+ return NativeMethods.plc_tag_check_lib_version(req_major, req_minor, req_patch);
+ }
- public static Int32 plc_tag_create(string lpString, int timeout)
- {
- return NativeMethods.plc_tag_create(lpString, timeout);
- }
+ public static Int32 plc_tag_create(string lpString, int timeout)
+ {
+ return NativeMethods.plc_tag_create(lpString, timeout);
+ }
- public static Int32 plc_tag_create_ex(string lpString, callback_func_ex func, IntPtr userdata, int timeout)
- {
- return NativeMethods.plc_tag_create_ex(lpString, func, userdata, timeout);
- }
+ public static Int32 plc_tag_create_ex(string lpString, callback_func_ex func, IntPtr userdata, int timeout)
+ {
+ return NativeMethods.plc_tag_create_ex(lpString, func, userdata, timeout);
+ }
- public static Int32 plc_tag_create_from_tag(Int32 src_tag_id, string attrib_str, callback_func_ex func, IntPtr userdata, int timeout)
- {
- return NativeMethods.plc_tag_create_from_tag(src_tag_id, attrib_str, func, userdata, timeout);
- }
+ public static Int32 plc_tag_create_from_tag(Int32 src_tag_id, string attrib_str, callback_func_ex func, IntPtr userdata, int timeout)
+ {
+ return NativeMethods.plc_tag_create_from_tag(src_tag_id, attrib_str, func, userdata, timeout);
+ }
- public static int plc_tag_destroy(Int32 tag)
- {
- return NativeMethods.plc_tag_destroy(tag);
- }
+ public static int plc_tag_destroy(Int32 tag)
+ {
+ return NativeMethods.plc_tag_destroy(tag);
+ }
- public static void plc_tag_shutdown()
- {
- NativeMethods.plc_tag_shutdown();
- }
+ public static void plc_tag_shutdown()
+ {
+ NativeMethods.plc_tag_shutdown();
+ }
- public static int plc_tag_register_callback(Int32 tag_id, callback_func func)
- {
- return NativeMethods.plc_tag_register_callback(tag_id, func);
- }
+ public static int plc_tag_register_callback(Int32 tag_id, callback_func func)
+ {
+ return NativeMethods.plc_tag_register_callback(tag_id, func);
+ }
- public static int plc_tag_register_callback_ex(Int32 tag_id, callback_func_ex func, IntPtr userdata)
- {
- return NativeMethods.plc_tag_register_callback_ex(tag_id, func, userdata);
- }
+ public static int plc_tag_register_callback_ex(Int32 tag_id, callback_func_ex func, IntPtr userdata)
+ {
+ return NativeMethods.plc_tag_register_callback_ex(tag_id, func, userdata);
+ }
- public static int plc_tag_unregister_callback(Int32 tag_id)
- {
- return NativeMethods.plc_tag_unregister_callback(tag_id);
- }
+ public static int plc_tag_unregister_callback(Int32 tag_id)
+ {
+ return NativeMethods.plc_tag_unregister_callback(tag_id);
+ }
- public static int plc_tag_register_logger(log_callback_func func)
- {
- return NativeMethods.plc_tag_register_logger(func);
- }
- public static int plc_tag_unregister_logger()
- {
- return NativeMethods.plc_tag_unregister_logger();
- }
+ public static int plc_tag_register_logger(log_callback_func func)
+ {
+ return NativeMethods.plc_tag_register_logger(func);
+ }
+ public static int plc_tag_unregister_logger()
+ {
+ return NativeMethods.plc_tag_unregister_logger();
+ }
- public static int plc_tag_lock(Int32 tag)
- {
- return NativeMethods.plc_tag_lock(tag);
- }
+ public static int plc_tag_lock(Int32 tag)
+ {
+ return NativeMethods.plc_tag_lock(tag);
+ }
- public static int plc_tag_unlock(Int32 tag)
- {
- return NativeMethods.plc_tag_unlock(tag);
- }
- public static int plc_tag_status(Int32 tag)
- {
- return NativeMethods.plc_tag_status(tag);
- }
+ public static int plc_tag_unlock(Int32 tag)
+ {
+ return NativeMethods.plc_tag_unlock(tag);
+ }
+ public static int plc_tag_status(Int32 tag)
+ {
+ return NativeMethods.plc_tag_status(tag);
+ }
- public static string plc_tag_decode_error(int err)
- {
- return Marshal.PtrToStringAnsi(NativeMethods.plc_tag_decode_error(err));
- }
+ public static string plc_tag_decode_error(int err)
+ {
+ return Marshal.PtrToStringAnsi(NativeMethods.plc_tag_decode_error(err));
+ }
- public static int plc_tag_read(Int32 tag, int timeout)
- {
- return NativeMethods.plc_tag_read(tag, timeout);
- }
+ public static int plc_tag_read(Int32 tag, int timeout)
+ {
+ return NativeMethods.plc_tag_read(tag, timeout);
+ }
- public static int plc_tag_write(Int32 tag, int timeout)
- {
- return NativeMethods.plc_tag_write(tag, timeout);
- }
+ public static int plc_tag_write(Int32 tag, int timeout)
+ {
+ return NativeMethods.plc_tag_write(tag, timeout);
+ }
- public static int plc_tag_get_size(Int32 tag)
- {
- return NativeMethods.plc_tag_get_size(tag);
- }
+ public static int plc_tag_get_size(Int32 tag)
+ {
+ return NativeMethods.plc_tag_get_size(tag);
+ }
- public static int plc_tag_set_size(Int32 tag, int new_size)
- {
- return NativeMethods.plc_tag_set_size(tag, new_size);
- }
+ public static int plc_tag_set_size(Int32 tag, int new_size)
+ {
+ return NativeMethods.plc_tag_set_size(tag, new_size);
+ }
- public static int plc_tag_abort(Int32 tag)
- {
- return NativeMethods.plc_tag_abort(tag);
- }
+ public static int plc_tag_abort(Int32 tag)
+ {
+ return NativeMethods.plc_tag_abort(tag);
+ }
- public static int plc_tag_get_int_attribute(Int32 tag, string attrib_name, int default_value)
- {
- return NativeMethods.plc_tag_get_int_attribute(tag, attrib_name, default_value);
- }
+ public static int plc_tag_get_int_attribute(Int32 tag, string attrib_name, int default_value)
+ {
+ return NativeMethods.plc_tag_get_int_attribute(tag, attrib_name, default_value);
+ }
- public static int plc_tag_set_int_attribute(Int32 tag, string attrib_name, int new_value)
- {
- return NativeMethods.plc_tag_set_int_attribute(tag, attrib_name, new_value);
- }
+ public static int plc_tag_set_int_attribute(Int32 tag, string attrib_name, int new_value)
+ {
+ return NativeMethods.plc_tag_set_int_attribute(tag, attrib_name, new_value);
+ }
- public static int plc_tag_get_byte_array_attribute(Int32 tag, string attrib_name, byte[] buffer, int buffer_length)
- {
- return NativeMethods.plc_tag_get_byte_array_attribute(tag, attrib_name, buffer, buffer_length);
- }
+ public static int plc_tag_get_byte_array_attribute(Int32 tag, string attrib_name, byte[] buffer, int buffer_length)
+ {
+ return NativeMethods.plc_tag_get_byte_array_attribute(tag, attrib_name, buffer, buffer_length);
+ }
- public static UInt64 plc_tag_get_uint64(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_uint64(tag, offset);
- }
+ public static UInt64 plc_tag_get_uint64(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_uint64(tag, offset);
+ }
- public static Int64 plc_tag_get_int64(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_int64(tag, offset);
- }
+ public static Int64 plc_tag_get_int64(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_int64(tag, offset);
+ }
- public static int plc_tag_set_uint64(Int32 tag, int offset, UInt64 val)
- {
- return NativeMethods.plc_tag_set_uint64(tag, offset, val);
- }
+ public static int plc_tag_set_uint64(Int32 tag, int offset, UInt64 val)
+ {
+ return NativeMethods.plc_tag_set_uint64(tag, offset, val);
+ }
- public static int plc_tag_set_int64(Int32 tag, int offset, Int64 val)
- {
- return NativeMethods.plc_tag_set_int64(tag, offset, val);
- }
+ public static int plc_tag_set_int64(Int32 tag, int offset, Int64 val)
+ {
+ return NativeMethods.plc_tag_set_int64(tag, offset, val);
+ }
- public static double plc_tag_get_float64(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_float64(tag, offset);
- }
+ public static double plc_tag_get_float64(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_float64(tag, offset);
+ }
- public static int plc_tag_set_float64(Int32 tag, int offset, double val)
- {
- return NativeMethods.plc_tag_set_float64(tag, offset, val);
- }
- public static UInt32 plc_tag_get_uint32(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_uint32(tag, offset);
- }
+ public static int plc_tag_set_float64(Int32 tag, int offset, double val)
+ {
+ return NativeMethods.plc_tag_set_float64(tag, offset, val);
+ }
+ public static UInt32 plc_tag_get_uint32(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_uint32(tag, offset);
+ }
- public static Int32 plc_tag_get_int32(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_int32(tag, offset);
- }
+ public static Int32 plc_tag_get_int32(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_int32(tag, offset);
+ }
- public static int plc_tag_set_uint32(Int32 tag, int offset, UInt32 val)
- {
- return NativeMethods.plc_tag_set_uint32(tag, offset, val);
- }
+ public static int plc_tag_set_uint32(Int32 tag, int offset, UInt32 val)
+ {
+ return NativeMethods.plc_tag_set_uint32(tag, offset, val);
+ }
- public static int plc_tag_set_int32(Int32 tag, int offset, Int32 val)
- {
- return NativeMethods.plc_tag_set_int32(tag, offset, val);
- }
+ public static int plc_tag_set_int32(Int32 tag, int offset, Int32 val)
+ {
+ return NativeMethods.plc_tag_set_int32(tag, offset, val);
+ }
- public static float plc_tag_get_float32(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_float32(tag, offset);
- }
+ public static float plc_tag_get_float32(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_float32(tag, offset);
+ }
- public static int plc_tag_set_float32(Int32 tag, int offset, float val)
- {
- return NativeMethods.plc_tag_set_float32(tag, offset, val);
- }
+ public static int plc_tag_set_float32(Int32 tag, int offset, float val)
+ {
+ return NativeMethods.plc_tag_set_float32(tag, offset, val);
+ }
- public static UInt16 plc_tag_get_uint16(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_uint16(tag, offset);
- }
+ public static UInt16 plc_tag_get_uint16(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_uint16(tag, offset);
+ }
- public static Int16 plc_tag_get_int16(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_int16(tag, offset);
- }
+ public static Int16 plc_tag_get_int16(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_int16(tag, offset);
+ }
- public static int plc_tag_set_uint16(Int32 tag, int offset, UInt16 val)
- {
- return NativeMethods.plc_tag_set_uint16(tag, offset, val);
- }
+ public static int plc_tag_set_uint16(Int32 tag, int offset, UInt16 val)
+ {
+ return NativeMethods.plc_tag_set_uint16(tag, offset, val);
+ }
- public static int plc_tag_set_int16(Int32 tag, int offset, Int16 val)
- {
- return NativeMethods.plc_tag_set_int16(tag, offset, val);
- }
+ public static int plc_tag_set_int16(Int32 tag, int offset, Int16 val)
+ {
+ return NativeMethods.plc_tag_set_int16(tag, offset, val);
+ }
- public static byte plc_tag_get_uint8(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_uint8(tag, offset);
- }
+ public static byte plc_tag_get_uint8(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_uint8(tag, offset);
+ }
- public static sbyte plc_tag_get_int8(Int32 tag, int offset)
- {
- return NativeMethods.plc_tag_get_int8(tag, offset);
- }
+ public static sbyte plc_tag_get_int8(Int32 tag, int offset)
+ {
+ return NativeMethods.plc_tag_get_int8(tag, offset);
+ }
- public static int plc_tag_set_uint8(Int32 tag, int offset, byte val)
- {
- return NativeMethods.plc_tag_set_uint8(tag, offset, val);
- }
+ public static int plc_tag_set_uint8(Int32 tag, int offset, byte val)
+ {
+ return NativeMethods.plc_tag_set_uint8(tag, offset, val);
+ }
- public static int plc_tag_set_int8(Int32 tag, int offset, sbyte val)
- {
- return NativeMethods.plc_tag_set_int8(tag, offset, val);
- }
+ public static int plc_tag_set_int8(Int32 tag, int offset, sbyte val)
+ {
+ return NativeMethods.plc_tag_set_int8(tag, offset, val);
+ }
- public static int plc_tag_get_bit(Int32 tag, int offset_bit)
- {
- return NativeMethods.plc_tag_get_bit(tag, offset_bit);
- }
+ public static int plc_tag_get_bit(Int32 tag, int offset_bit)
+ {
+ return NativeMethods.plc_tag_get_bit(tag, offset_bit);
+ }
- public static int plc_tag_set_bit(Int32 tag, int offset_bit, int val)
- {
- return NativeMethods.plc_tag_set_bit(tag, offset_bit, val);
- }
- public static void plc_tag_set_debug_level(int debug_level)
- {
- NativeMethods.plc_tag_set_debug_level(debug_level);
- }
+ public static int plc_tag_set_bit(Int32 tag, int offset_bit, int val)
+ {
+ return NativeMethods.plc_tag_set_bit(tag, offset_bit, val);
+ }
+ public static void plc_tag_set_debug_level(int debug_level)
+ {
+ NativeMethods.plc_tag_set_debug_level(debug_level);
+ }
- public static int plc_tag_get_debug_level()
- {
- return NativeMethods.plc_tag_get_debug_level();
- }
+ public static int plc_tag_get_debug_level()
+ {
+ return NativeMethods.plc_tag_get_debug_level();
+ }
- public static int plc_tag_set_debug_module_level(int module, int debug_level)
- {
- return NativeMethods.plc_tag_set_debug_module_level(module, debug_level);
- }
+ public static int plc_tag_set_debug_module_level(int module, int debug_level)
+ {
+ return NativeMethods.plc_tag_set_debug_module_level(module, debug_level);
+ }
- public static int plc_tag_get_debug_module_level(int module)
- {
- return NativeMethods.plc_tag_get_debug_module_level(module);
- }
+ public static int plc_tag_get_debug_module_level(int module)
+ {
+ return NativeMethods.plc_tag_get_debug_module_level(module);
+ }
- public static int plc_tag_get_string(Int32 tag_id, int string_start_offset, StringBuilder buffer, int buffer_length)
- {
- return NativeMethods.plc_tag_get_string(tag_id, string_start_offset, buffer, buffer_length);
- }
+ public static int plc_tag_get_string(Int32 tag_id, int string_start_offset, StringBuilder buffer, int buffer_length)
+ {
+ return NativeMethods.plc_tag_get_string(tag_id, string_start_offset, buffer, buffer_length);
+ }
- public static int plc_tag_set_string(Int32 tag_id, int string_start_offset, string string_val)
- {
- return NativeMethods.plc_tag_set_string(tag_id, string_start_offset, string_val);
- }
+ public static int plc_tag_set_string(Int32 tag_id, int string_start_offset, string string_val)
+ {
+ return NativeMethods.plc_tag_set_string(tag_id, string_start_offset, string_val);
+ }
- public static int plc_tag_get_string_length(Int32 tag_id, int string_start_offset)
- {
- return NativeMethods.plc_tag_get_string_length(tag_id, string_start_offset);
- }
+ public static int plc_tag_get_string_length(Int32 tag_id, int string_start_offset)
+ {
+ return NativeMethods.plc_tag_get_string_length(tag_id, string_start_offset);
+ }
- public static int plc_tag_get_string_capacity(Int32 tag_id, int string_start_offset)
- {
- return NativeMethods.plc_tag_get_string_capacity(tag_id, string_start_offset);
- }
+ public static int plc_tag_get_string_capacity(Int32 tag_id, int string_start_offset)
+ {
+ return NativeMethods.plc_tag_get_string_capacity(tag_id, string_start_offset);
+ }
- public static int plc_tag_get_string_total_length(Int32 tag_id, int string_start_offset)
- {
- return NativeMethods.plc_tag_get_string_total_length(tag_id, string_start_offset);
- }
+ public static int plc_tag_get_string_total_length(Int32 tag_id, int string_start_offset)
+ {
+ return NativeMethods.plc_tag_get_string_total_length(tag_id, string_start_offset);
+ }
- public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length)
- {
- return plc_tag_get_raw_bytes(tag_id, start_offset, buffer.AsSpan(0, buffer_length));
- }
+ public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length)
+ {
+ return plc_tag_get_raw_bytes(tag_id, start_offset, buffer.AsSpan(0, buffer_length));
+ }
- public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, Span buffer)
+ public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, Span buffer)
+ {
+ unsafe
{
- unsafe
+ fixed (byte* ptr = buffer)
{
- fixed (byte* ptr = buffer)
- {
- return NativeMethods.plc_tag_get_raw_bytes(tag_id, start_offset, ptr, buffer.Length);
- }
+ return NativeMethods.plc_tag_get_raw_bytes(tag_id, start_offset, ptr, buffer.Length);
}
}
+ }
- public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length)
- {
- return plc_tag_set_raw_bytes(tag_id, start_offset, new ReadOnlySpan(buffer, 0, buffer_length));
- }
+ public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length)
+ {
+ return plc_tag_set_raw_bytes(tag_id, start_offset, new ReadOnlySpan(buffer, 0, buffer_length));
+ }
- public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, ReadOnlySpan buffer)
+ public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, ReadOnlySpan buffer)
+ {
+ unsafe
{
- unsafe
+ fixed (byte* ptr = buffer)
{
- fixed (byte* ptr = buffer)
- {
- return NativeMethods.plc_tag_set_raw_bytes(tag_id, start_offset, ptr, buffer.Length);
- }
+ return NativeMethods.plc_tag_set_raw_bytes(tag_id, start_offset, ptr, buffer.Length);
}
}
+ }
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag.Tests/AsyncTests.cs b/src/libplctag.Tests/AsyncTests.cs
index 9a9f5d92..8fe0e19f 100644
--- a/src/libplctag.Tests/AsyncTests.cs
+++ b/src/libplctag.Tests/AsyncTests.cs
@@ -13,147 +13,147 @@
namespace libplctag.Tests;
- public class AsyncTests
- {
+public class AsyncTests
+{
- readonly TimeSpan REALISTIC_LATENCY_FOR_CREATE = TimeSpan.FromMilliseconds(50);
- readonly TimeSpan REALISTIC_LATENCY_FOR_READ = TimeSpan.FromMilliseconds(50);
- readonly TimeSpan REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS = TimeSpan.FromMilliseconds(1000);
+ readonly TimeSpan REALISTIC_LATENCY_FOR_CREATE = TimeSpan.FromMilliseconds(50);
+ readonly TimeSpan REALISTIC_LATENCY_FOR_READ = TimeSpan.FromMilliseconds(50);
+ readonly TimeSpan REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS = TimeSpan.FromMilliseconds(1000);
- [Fact]
- public async Task Cancelled_cancellation_token_throws_a_TaskCanceledException()
- {
- // Arrange
- var nativeTag = new Mock();
+ [Fact]
+ public async Task Cancelled_cancellation_token_throws_a_TaskCanceledException()
+ {
+ // Arrange
+ var nativeTag = new Mock();
- nativeTag // The initial creation of the tag object returns a status, so we return pending
- .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
- .Returns((int)Status.Pending);
+ nativeTag // The initial creation of the tag object returns a status, so we return pending
+ .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
+ .Returns((int)Status.Pending);
- nativeTag // Subsequent calls to determine the tag status should still return pending
- .Setup(m => m.plc_tag_status(It.IsAny()))
- .Returns((int)Status.Pending);
+ nativeTag // Subsequent calls to determine the tag status should still return pending
+ .Setup(m => m.plc_tag_status(It.IsAny()))
+ .Returns((int)Status.Pending);
- var tag = new Tag(nativeTag.Object);
- var cts = new CancellationTokenSource();
+ var tag = new Tag(nativeTag.Object);
+ var cts = new CancellationTokenSource();
- // Act, Assert
- cts.CancelAfter(REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS);
- await Assert.ThrowsAsync(async () => {
- await tag.InitializeAsync(cts.Token);
- });
- }
+ // Act, Assert
+ cts.CancelAfter(REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS);
+ await Assert.ThrowsAsync(async () => {
+ await tag.InitializeAsync(cts.Token);
+ });
+ }
- [Fact]
- public async Task Timeout_throws_a_LibPlcTagException()
- {
- // Arrange
- var nativeTag = new Mock();
+ [Fact]
+ public async Task Timeout_throws_a_LibPlcTagException()
+ {
+ // Arrange
+ var nativeTag = new Mock();
- nativeTag // The initial creation of the tag object returns a status, so we return pending
- .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
- .Returns((int)Status.Pending);
+ nativeTag // The initial creation of the tag object returns a status, so we return pending
+ .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
+ .Returns((int)Status.Pending);
- nativeTag // Subsequent calls to determine the tag status should still return pending
- .Setup(m => m.plc_tag_status(It.IsAny()))
- .Returns((int)Status.Pending);
+ nativeTag // Subsequent calls to determine the tag status should still return pending
+ .Setup(m => m.plc_tag_status(It.IsAny()))
+ .Returns((int)Status.Pending);
- var tag = new Tag(nativeTag.Object)
- {
- Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
- };
+ var tag = new Tag(nativeTag.Object)
+ {
+ Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
+ };
- // Act
- var ex = await Assert.ThrowsAsync(async () => {
- await tag.InitializeAsync();
- });
+ // Act
+ var ex = await Assert.ThrowsAsync(async () => {
+ await tag.InitializeAsync();
+ });
- // Assert
- Assert.Equal(Status.ErrorTimeout, ex.Status);
- }
+ // Assert
+ Assert.Equal(Status.ErrorTimeout, ex.Status);
+ }
- [Fact]
- public async Task Timeout_returns_pending_but_eventually_ok()
+ [Fact]
+ public async Task Timeout_returns_pending_but_eventually_ok()
+ {
+ // Arrange
+ var nativeTag = GetMock();
+
+ var tag = new Tag(nativeTag.Object)
{
- // Arrange
- var nativeTag = GetMock();
+ Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
+ };
+
+ // Act
+ var task = tag.InitializeAsync();
+ var statusWhileWaiting = tag.GetStatus();
+ await task;
+ var statusAfterAwaited = tag.GetStatus();
+
+ // Assert
+ Assert.Equal(Status.Pending, statusWhileWaiting);
+ Assert.Equal(Status.Ok, statusAfterAwaited);
+ }
+
+ [Fact]
+ public async Task AsyncRead_completes_within_timeout_period()
+ {
+ // Arrange
+ var nativeTag = GetMock();
- var tag = new Tag(nativeTag.Object)
- {
- Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
- };
-
- // Act
- var task = tag.InitializeAsync();
- var statusWhileWaiting = tag.GetStatus();
- await task;
- var statusAfterAwaited = tag.GetStatus();
-
- // Assert
- Assert.Equal(Status.Pending, statusWhileWaiting);
- Assert.Equal(Status.Ok, statusAfterAwaited);
- }
-
- [Fact]
- public async Task AsyncRead_completes_within_timeout_period()
+ var tag = new Tag(nativeTag.Object)
{
- // Arrange
- var nativeTag = GetMock();
+ Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
+ };
+
+ // Act
+ await tag.ReadAsync();
+
+ // Assert
+ Assert.Equal(Status.Ok, tag.GetStatus());
+ }
+
+
+ Mock GetMock()
+ {
+ const int tagId = 11;
- var tag = new Tag(nativeTag.Object)
+ NativeImport.plctag.callback_func_ex callback = null;
+ Status? status = null;
+
+ var nativeTag = new Mock();
+
+ // The NativeTagWrapper should provide the native tag with a callback.
+ // We will store this locally when a create call occurs, and fire it shortly after ...
+ nativeTag
+ .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
+ .Callback(async (attributeString, callbackFunc, userData, timeout) =>
{
- Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
- };
+ status = Status.Pending;
+ callback = callbackFunc;
+ await Task.Delay(REALISTIC_LATENCY_FOR_CREATE);
+ status = Status.Ok;
+ callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_CREATED, (int)NativeImport.STATUS.PLCTAG_STATUS_OK, IntPtr.Zero);
+ });
- // Act
- await tag.ReadAsync();
+ // ... as well as when a read call occurs
+ nativeTag
+ .Setup(m => m.plc_tag_read(It.IsAny(), 0))
+ .Callback(async (tagId, timeout) =>
+ {
+ status = Status.Pending;
+ callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_READ_STARTED, (int)NativeImport.STATUS.PLCTAG_STATUS_OK, IntPtr.Zero);
+ await Task.Delay(REALISTIC_LATENCY_FOR_READ);
+ status = Status.Ok;
+ callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_READ_COMPLETED, (int)NativeImport.STATUS.PLCTAG_STATUS_OK, IntPtr.Zero);
+ });
- // Assert
- Assert.Equal(Status.Ok, tag.GetStatus());
- }
+ // the status was being tracked, so return it if asked
+ nativeTag
+ .Setup(m => m.plc_tag_status(It.IsAny()))
+ .Returns(() => (int)status.Value);
+ return nativeTag;
+ }
- Mock GetMock()
- {
- const int tagId = 11;
-
- NativeImport.plctag.callback_func_ex callback = null;
- Status? status = null;
-
- var nativeTag = new Mock();
-
- // The NativeTagWrapper should provide the native tag with a callback.
- // We will store this locally when a create call occurs, and fire it shortly after ...
- nativeTag
- .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
- .Callback(async (attributeString, callbackFunc, userData, timeout) =>
- {
- status = Status.Pending;
- callback = callbackFunc;
- await Task.Delay(REALISTIC_LATENCY_FOR_CREATE);
- status = Status.Ok;
- callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_CREATED, (int)NativeImport.STATUS.PLCTAG_STATUS_OK, IntPtr.Zero);
- });
-
- // ... as well as when a read call occurs
- nativeTag
- .Setup(m => m.plc_tag_read(It.IsAny(), 0))
- .Callback(async (tagId, timeout) =>
- {
- status = Status.Pending;
- callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_READ_STARTED, (int)NativeImport.STATUS.PLCTAG_STATUS_OK, IntPtr.Zero);
- await Task.Delay(REALISTIC_LATENCY_FOR_READ);
- status = Status.Ok;
- callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_READ_COMPLETED, (int)NativeImport.STATUS.PLCTAG_STATUS_OK, IntPtr.Zero);
- });
-
- // the status was being tracked, so return it if asked
- nativeTag
- .Setup(m => m.plc_tag_status(It.IsAny()))
- .Returns(() => (int)status.Value);
-
- return nativeTag;
- }
-
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag.Tests/DisposeTests.cs b/src/libplctag.Tests/DisposeTests.cs
index 8b718036..5c0d8b7c 100644
--- a/src/libplctag.Tests/DisposeTests.cs
+++ b/src/libplctag.Tests/DisposeTests.cs
@@ -13,79 +13,79 @@
namespace libplctag.Tests;
- public class DisposeTests
+public class DisposeTests
+{
+
+ [Fact]
+ public void Destroy_is_called_if_initialized_and_disposed()
{
+ // Arrange
+ var nativeTag = new Mock();
+ var tag = new Tag(nativeTag.Object);
- [Fact]
- public void Destroy_is_called_if_initialized_and_disposed()
- {
- // Arrange
- var nativeTag = new Mock();
- var tag = new Tag(nativeTag.Object);
+ // Act
+ tag.Initialize();
+ tag.Dispose();
- // Act
- tag.Initialize();
- tag.Dispose();
+ // Assert
+ nativeTag.Verify(m => m.plc_tag_destroy(It.IsAny()), Times.Once);
+ }
- // Assert
- nativeTag.Verify(m => m.plc_tag_destroy(It.IsAny()), Times.Once);
- }
+ [Fact]
+ public async Task GithubIssue418()
+ {
+ // Arrange
+ const int tagId = 11;
- [Fact]
- public async Task GithubIssue418()
+ NativeImport.plctag.callback_func_ex callback = null;
+ Status? status = null;
+
+ var nativeTag = new Mock();
+
+ nativeTag
+ .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
+ .Callback(async (attributeString, callbackFunc, userData, timeout) =>
+ {
+ status = Status.Pending;
+ callback = callbackFunc;
+ status = Status.ErrorNotFound;
+ callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_CREATED, (int)NativeImport.STATUS.PLCTAG_ERR_NOT_FOUND, IntPtr.Zero);
+ });
+
+ // the status was being tracked, so return it if asked
+ nativeTag
+ .Setup(m => m.plc_tag_status(It.IsAny()))
+ .Returns(() => (int)status.Value);
+
+ // Act
+ using(var tag = new Tag(nativeTag.Object))
{
- // Arrange
- const int tagId = 11;
-
- NativeImport.plctag.callback_func_ex callback = null;
- Status? status = null;
-
- var nativeTag = new Mock();
-
- nativeTag
- .Setup(m => m.plc_tag_create_ex(It.IsAny(), It.IsAny(), It.IsAny(), 0))
- .Callback(async (attributeString, callbackFunc, userData, timeout) =>
- {
- status = Status.Pending;
- callback = callbackFunc;
- status = Status.ErrorNotFound;
- callback?.Invoke(tagId, (int)NativeImport.EVENT.PLCTAG_EVENT_CREATED, (int)NativeImport.STATUS.PLCTAG_ERR_NOT_FOUND, IntPtr.Zero);
- });
-
- // the status was being tracked, so return it if asked
- nativeTag
- .Setup(m => m.plc_tag_status(It.IsAny()))
- .Returns(() => (int)status.Value);
-
- // Act
- using(var tag = new Tag(nativeTag.Object))
+ try
{
- try
- {
- await tag.InitializeAsync();
- }
- catch (LibPlcTagException e) when (e.Status == Status.ErrorNotFound) // we are expecting this exception
- {
- }
+ await tag.InitializeAsync();
}
+ catch (LibPlcTagException e) when (e.Status == Status.ErrorNotFound) // we are expecting this exception
+ {
+ }
+ }
- // Assert
- LibPlcTag.Shutdown();
+ // Assert
+ LibPlcTag.Shutdown();
- }
+ }
- [Fact]
- public void Can_not_use_if_already_disposed()
- {
- // Arrange
- var nativeTag = new Mock();
- var tag = new Tag(nativeTag.Object);
+ [Fact]
+ public void Can_not_use_if_already_disposed()
+ {
+ // Arrange
+ var nativeTag = new Mock();
+ var tag = new Tag(nativeTag.Object);
- // Act
- tag.Dispose();
+ // Act
+ tag.Dispose();
- // Assert
- Assert.Throws(() => tag.GetStatus());
- }
+ // Assert
+ Assert.Throws(() => tag.GetStatus());
+ }
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag.Tests/OtherTests.cs b/src/libplctag.Tests/OtherTests.cs
index ef14c2e3..3d1d12d7 100644
--- a/src/libplctag.Tests/OtherTests.cs
+++ b/src/libplctag.Tests/OtherTests.cs
@@ -11,61 +11,61 @@
namespace libplctag.Tests;
- public class OtherTests
- {
+public class OtherTests
+{
- [Fact]
- public void Status_ok_when_first_created()
- {
- // Arrange
- var nativeTag = new Mock();
- var tag = new Tag(nativeTag.Object);
+ [Fact]
+ public void Status_ok_when_first_created()
+ {
+ // Arrange
+ var nativeTag = new Mock();
+ var tag = new Tag(nativeTag.Object);
- // Act
+ // Act
- // Assert
- var status = tag.GetStatus();
- Assert.Equal(Status.Ok, status);
- }
+ // Assert
+ var status = tag.GetStatus();
+ Assert.Equal(Status.Ok, status);
+ }
- [Fact]
- public void Attribute_string_formatted_correctly()
+ [Fact]
+ public void Attribute_string_formatted_correctly()
+ {
+ // Arrange
+ var nativeTag = new Mock();
+ var tag = new Tag(nativeTag.Object)
{
- // Arrange
- var nativeTag = new Mock();
- var tag = new Tag(nativeTag.Object)
- {
- ElementSize = 4,
- ElementCount = 10,
- PlcType = PlcType.Slc500,
- Name = "TagName",
- };
+ ElementSize = 4,
+ ElementCount = 10,
+ PlcType = PlcType.Slc500,
+ Name = "TagName",
+ };
- // Act
- tag.Initialize();
+ // Act
+ tag.Initialize();
- // Assert
- var expectedAttributeString = "plc=slc500&elem_size=4&elem_count=10&name=TagName";
- nativeTag.Verify(m => m.plc_tag_create_ex(expectedAttributeString, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
+ // Assert
+ var expectedAttributeString = "plc=slc500&elem_size=4&elem_count=10&name=TagName";
+ nativeTag.Verify(m => m.plc_tag_create_ex(expectedAttributeString, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
- }
+ }
- [Fact]
- public void Attribute_string_does_not_contain_unset_properties()
- {
- // Arrange
- var nativeTag = new Mock();
- var tag = new Tag(nativeTag.Object);
+ [Fact]
+ public void Attribute_string_does_not_contain_unset_properties()
+ {
+ // Arrange
+ var nativeTag = new Mock();
+ var tag = new Tag(nativeTag.Object);
- // Act
- tag.Initialize();
+ // Act
+ tag.Initialize();
- // Assert
- var expectedAttributeString = "";
- nativeTag.Verify(m => m.plc_tag_create_ex(expectedAttributeString, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
+ // Assert
+ var expectedAttributeString = "";
+ nativeTag.Verify(m => m.plc_tag_create_ex(expectedAttributeString, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
- }
- }
\ No newline at end of file
+ }
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/BoolPlcMapper.cs b/src/libplctag/DataTypes/BoolPlcMapper.cs
index 252ed471..d06ab808 100644
--- a/src/libplctag/DataTypes/BoolPlcMapper.cs
+++ b/src/libplctag/DataTypes/BoolPlcMapper.cs
@@ -11,62 +11,62 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class BoolPlcMapper : IPlcMapper, IPlcMapper, IPlcMapper, IPlcMapper
- {
- public int? ElementSize => 1;
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class BoolPlcMapper : IPlcMapper, IPlcMapper, IPlcMapper, IPlcMapper
+{
+ public int? ElementSize => 1;
- public PlcType PlcType { get; set; }
- public int[] ArrayDimensions { get; set; }
+ public PlcType PlcType { get; set; }
+ public int[] ArrayDimensions { get; set; }
- public int? GetElementCount()
- {
- if (ArrayDimensions == null)
- return null;
+ public int? GetElementCount()
+ {
+ if (ArrayDimensions == null)
+ return null;
- //TODO: Test -> I'm not confident that the overall bool count is packed as a 1D array and not packed by dimension.
- //Multiply dimensions for total elements
- var totalElements = ArrayDimensions.Aggregate(1, (x, y) => x * y);
- return (int)Math.Ceiling((double)totalElements / 32.0);
- }
+ //TODO: Test -> I'm not confident that the overall bool count is packed as a 1D array and not packed by dimension.
+ //Multiply dimensions for total elements
+ var totalElements = ArrayDimensions.Aggregate(1, (x, y) => x * y);
+ return (int)Math.Ceiling((double)totalElements / 32.0);
+ }
- public int? SetArrayLength(int? elementCount) => (int)Math.Ceiling((double)elementCount.Value / 32.0);
+ public int? SetArrayLength(int? elementCount) => (int)Math.Ceiling((double)elementCount.Value / 32.0);
- virtual protected bool[] DecodeArray(Tag tag)
+ virtual protected bool[] DecodeArray(Tag tag)
+ {
+ if (ElementSize is null)
+ throw new ArgumentNullException($"{nameof(ElementSize)} cannot be null for array decoding");
+
+ var buffer = new bool[tag.ElementCount.Value * 32];
+ for (int ii = 0; ii < tag.ElementCount.Value * 32; ii++)
{
- if (ElementSize is null)
- throw new ArgumentNullException($"{nameof(ElementSize)} cannot be null for array decoding");
-
- var buffer = new bool[tag.ElementCount.Value * 32];
- for (int ii = 0; ii < tag.ElementCount.Value * 32; ii++)
- {
- buffer[ii] = tag.GetBit(ii);
- }
- return buffer;
+ buffer[ii] = tag.GetBit(ii);
}
+ return buffer;
+ }
- virtual protected void EncodeArray(Tag tag, bool[] values)
+ virtual protected void EncodeArray(Tag tag, bool[] values)
+ {
+ for (int ii = 0; ii < tag.ElementCount.Value * 32; ii++)
{
- for (int ii = 0; ii < tag.ElementCount.Value * 32; ii++)
- {
- tag.SetBit(ii, values[ii]);
- }
+ tag.SetBit(ii, values[ii]);
}
+ }
- bool IPlcMapper.Decode(Tag tag) => tag.GetUInt8(0) != 0;
+ bool IPlcMapper.Decode(Tag tag) => tag.GetUInt8(0) != 0;
- void IPlcMapper.Encode(Tag tag, bool value) => tag.SetUInt8(0, value == true ? (byte)255 : (byte)0);
+ void IPlcMapper.Encode(Tag tag, bool value) => tag.SetUInt8(0, value == true ? (byte)255 : (byte)0);
- bool[] IPlcMapper.Decode(Tag tag) => DecodeArray(tag);
+ bool[] IPlcMapper.Decode(Tag tag) => DecodeArray(tag);
- void IPlcMapper.Encode(Tag tag, bool[] value) => EncodeArray(tag, value);
+ void IPlcMapper.Encode(Tag tag, bool[] value) => EncodeArray(tag, value);
- bool[,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To2DArray(ArrayDimensions[0], ArrayDimensions[1]);
+ bool[,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To2DArray(ArrayDimensions[0], ArrayDimensions[1]);
- void IPlcMapper.Encode(Tag tag, bool[,] value) => EncodeArray(tag, value.To1DArray());
+ void IPlcMapper.Encode(Tag tag, bool[,] value) => EncodeArray(tag, value.To1DArray());
- bool[,,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To3DArray(ArrayDimensions[0], ArrayDimensions[1], ArrayDimensions[2]);
+ bool[,,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To3DArray(ArrayDimensions[0], ArrayDimensions[1], ArrayDimensions[2]);
- void IPlcMapper.Encode(Tag tag, bool[,,] value) => EncodeArray(tag, value.To1DArray());
+ void IPlcMapper.Encode(Tag tag, bool[,,] value) => EncodeArray(tag, value.To1DArray());
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/DintPlcMapper.cs b/src/libplctag/DataTypes/DintPlcMapper.cs
index c5fa615f..df4547bb 100644
--- a/src/libplctag/DataTypes/DintPlcMapper.cs
+++ b/src/libplctag/DataTypes/DintPlcMapper.cs
@@ -9,13 +9,13 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class DintPlcMapper : PlcMapperBase
- {
- public override int? ElementSize => 4;
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class DintPlcMapper : PlcMapperBase
+{
+ public override int? ElementSize => 4;
- override public int Decode(Tag tag, int offset) => tag.GetInt32(offset);
+ override public int Decode(Tag tag, int offset) => tag.GetInt32(offset);
- override public void Encode(Tag tag, int offset, int value) => tag.SetInt32(offset, value);
+ override public void Encode(Tag tag, int offset, int value) => tag.SetInt32(offset, value);
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs b/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs
index e8e46a3c..68eb5cfa 100644
--- a/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs
+++ b/src/libplctag/DataTypes/Extensions/ArrayExtensions.cs
@@ -11,108 +11,108 @@
namespace libplctag.DataTypes.Extensions;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public static class ArrayExtensions
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public static class ArrayExtensions
+{
+ ///
+ /// Extension method to flatten a 2D array to a 1D array
+ ///
+ /// Array Type
+ /// 2D array to be flattened
+ /// 1D array
+ public static T[] To1DArray(this T[,] input)
{
- ///
- /// Extension method to flatten a 2D array to a 1D array
- ///
- /// Array Type
- /// 2D array to be flattened
- /// 1D array
- public static T[] To1DArray(this T[,] input)
- {
- // Step 1: get total size of 2D array, and allocate 1D array.
- int size = input.Length;
- T[] result = new T[size];
+ // Step 1: get total size of 2D array, and allocate 1D array.
+ int size = input.Length;
+ T[] result = new T[size];
- // Step 2: copy 2D array elements into a 1D array.
- int write = 0;
- for (int i = 0; i <= input.GetUpperBound(0); i++)
+ // Step 2: copy 2D array elements into a 1D array.
+ int write = 0;
+ for (int i = 0; i <= input.GetUpperBound(0); i++)
+ {
+ for (int z = 0; z <= input.GetUpperBound(1); z++)
{
- for (int z = 0; z <= input.GetUpperBound(1); z++)
- {
- result[write++] = input[i, z];
- }
+ result[write++] = input[i, z];
}
- // Step 3: return the new array.
- return result;
}
+ // Step 3: return the new array.
+ return result;
+ }
- ///
- /// Extension method to flatten a 3D array to a 1D array
- ///
- /// Array Type
- /// 3D array to be flattened
- /// 1D array
- public static T[] To1DArray(this T[,,] input)
- {
- // Step 1: get total size of 3D array, and allocate 1D array.
- int size = input.Length;
- T[] result = new T[size];
+ ///
+ /// Extension method to flatten a 3D array to a 1D array
+ ///
+ /// Array Type
+ /// 3D array to be flattened
+ /// 1D array
+ public static T[] To1DArray(this T[,,] input)
+ {
+ // Step 1: get total size of 3D array, and allocate 1D array.
+ int size = input.Length;
+ T[] result = new T[size];
- // Step 2: copy 3D array elements into a 1D array.
- int write = 0;
- for (int i = 0; i <= input.GetUpperBound(0); i++)
+ // Step 2: copy 3D array elements into a 1D array.
+ int write = 0;
+ for (int i = 0; i <= input.GetUpperBound(0); i++)
+ {
+ for (int j = 0; j <= input.GetUpperBound(1); j++)
{
- for (int j = 0; j <= input.GetUpperBound(1); j++)
+ for (int k = 0; k <= input.GetUpperBound(2); k++)
{
- for (int k = 0; k <= input.GetUpperBound(2); k++)
- {
- result[write++] = input[i, j, k];
- }
+ result[write++] = input[i, j, k];
}
}
- // Step 3: return the new array.
- return result;
}
+ // Step 3: return the new array.
+ return result;
+ }
- ///
- /// Extension method to reshape a 1D array into a 2D array
- ///
- /// Array Type
- /// 1D array to be reshaped
- /// Desired height (first index) of 2D array
- /// Desired width (second index) of 2D array
- /// 2D array
- public static T[,] To2DArray(this T[] input, int height, int width)
- {
- T[,] output = new T[height, width];
+ ///
+ /// Extension method to reshape a 1D array into a 2D array
+ ///
+ /// Array Type
+ /// 1D array to be reshaped
+ /// Desired height (first index) of 2D array
+ /// Desired width (second index) of 2D array
+ /// 2D array
+ public static T[,] To2DArray(this T[] input, int height, int width)
+ {
+ T[,] output = new T[height, width];
- for (int i = 0; i < height; i++)
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
{
- for (int j = 0; j < width; j++)
- {
- output[i, j] = input[i * width + j];
- }
+ output[i, j] = input[i * width + j];
}
- return output;
}
+ return output;
+ }
- ///
- /// Extension method to reshape a 1D array into a 3D array
- ///
- /// Array Type
- /// 1D array to be reshaped
- /// Desired height (first index) of 3D array
- /// Desired width (second index) of 3D array
- /// Desired length (third index) of 3D array
- /// #D array
- public static T[,,] To3DArray(this T[] input, int height, int width, int length)
- {
- T[,,] output = new T[height, width, length];
+ ///
+ /// Extension method to reshape a 1D array into a 3D array
+ ///
+ /// Array Type
+ /// 1D array to be reshaped
+ /// Desired height (first index) of 3D array
+ /// Desired width (second index) of 3D array
+ /// Desired length (third index) of 3D array
+ /// #D array
+ public static T[,,] To3DArray(this T[] input, int height, int width, int length)
+ {
+ T[,,] output = new T[height, width, length];
- for (int i = 0; i < height; i++)
+ for (int i = 0; i < height; i++)
+ {
+ for (int j = 0; j < width; j++)
{
- for (int j = 0; j < width; j++)
+ for (int k = 0; k < length; k++)
{
- for (int k = 0; k < length; k++)
- {
- output[i, j, k] = input[i * width * length + j * length + k];
- }
+ output[i, j, k] = input[i * width * length + j * length + k];
}
}
- return output;
}
+ return output;
+ }
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/IPlcMapper.cs b/src/libplctag/DataTypes/IPlcMapper.cs
index 3c5f31ef..a4566868 100644
--- a/src/libplctag/DataTypes/IPlcMapper.cs
+++ b/src/libplctag/DataTypes/IPlcMapper.cs
@@ -9,48 +9,48 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public interface IPlcMapper
- {
- ///
- /// You can define different marshalling behaviour for different types
- /// The PlcType is injected during PlcMapper instantiation, and
- /// will be available to you in your marshalling logic
- ///
- PlcType PlcType { get; set; }
-
-
- ///
- /// Provide an integer value for ElementSize if you
- /// want to pass this into the tag constructor
- ///
- int? ElementSize { get; }
-
- ///
- /// The dimensions of the array. Null if not an array.
- ///
- int[] ArrayDimensions { get; set; }
-
- ///
- /// This is used to convert the number of array elements
- /// into the raw element count, which is used by the library.
- /// Most of the time, this will be the dimensions multiplied, but occasionally
- /// it is not (e.g. BOOL arrays).
- ///
- int? GetElementCount();
-
- ///
- /// This is the method that reads/unpacks the underlying value of the tag
- /// and returns it as a C# type
- ///
- /// Tag to be Decoded
- /// C# value of tag
- T Decode(Tag tag);
-
- ///
- /// This is the method that transforms the C# type into the underlying value of the tag
- ///
- /// Tag to be encoded to
- /// C# value to be transformed
- void Encode(Tag tag, T value);
- }
\ No newline at end of file
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public interface IPlcMapper
+{
+ ///
+ /// You can define different marshalling behaviour for different types
+ /// The PlcType is injected during PlcMapper instantiation, and
+ /// will be available to you in your marshalling logic
+ ///
+ PlcType PlcType { get; set; }
+
+
+ ///
+ /// Provide an integer value for ElementSize if you
+ /// want to pass this into the tag constructor
+ ///
+ int? ElementSize { get; }
+
+ ///
+ /// The dimensions of the array. Null if not an array.
+ ///
+ int[] ArrayDimensions { get; set; }
+
+ ///
+ /// This is used to convert the number of array elements
+ /// into the raw element count, which is used by the library.
+ /// Most of the time, this will be the dimensions multiplied, but occasionally
+ /// it is not (e.g. BOOL arrays).
+ ///
+ int? GetElementCount();
+
+ ///
+ /// This is the method that reads/unpacks the underlying value of the tag
+ /// and returns it as a C# type
+ ///
+ /// Tag to be Decoded
+ /// C# value of tag
+ T Decode(Tag tag);
+
+ ///
+ /// This is the method that transforms the C# type into the underlying value of the tag
+ ///
+ /// Tag to be encoded to
+ /// C# value to be transformed
+ void Encode(Tag tag, T value);
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/IntPlcMapper.cs b/src/libplctag/DataTypes/IntPlcMapper.cs
index ece59304..b6931d88 100644
--- a/src/libplctag/DataTypes/IntPlcMapper.cs
+++ b/src/libplctag/DataTypes/IntPlcMapper.cs
@@ -9,13 +9,13 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class IntPlcMapper : PlcMapperBase
- {
- public override int? ElementSize => 2;
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class IntPlcMapper : PlcMapperBase
+{
+ public override int? ElementSize => 2;
- override public short Decode(Tag tag, int offset) => tag.GetInt16(offset);
+ override public short Decode(Tag tag, int offset) => tag.GetInt16(offset);
- override public void Encode(Tag tag, int offset, short value) => tag.SetInt16(offset, value);
+ override public void Encode(Tag tag, int offset, short value) => tag.SetInt16(offset, value);
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/LintPlcMapper.cs b/src/libplctag/DataTypes/LintPlcMapper.cs
index 8bfb4244..2d945e96 100644
--- a/src/libplctag/DataTypes/LintPlcMapper.cs
+++ b/src/libplctag/DataTypes/LintPlcMapper.cs
@@ -9,13 +9,13 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class LintPlcMapper : PlcMapperBase
- {
- public override int? ElementSize => 8;
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class LintPlcMapper : PlcMapperBase
+{
+ public override int? ElementSize => 8;
- override public long Decode(Tag tag, int offset) => tag.GetInt64(offset);
+ override public long Decode(Tag tag, int offset) => tag.GetInt64(offset);
- override public void Encode(Tag tag, int offset, long value) => tag.SetInt64(offset, value);
+ override public void Encode(Tag tag, int offset, long value) => tag.SetInt64(offset, value);
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/LrealPlcMapper.cs b/src/libplctag/DataTypes/LrealPlcMapper.cs
index fdeef378..1b1c92b3 100644
--- a/src/libplctag/DataTypes/LrealPlcMapper.cs
+++ b/src/libplctag/DataTypes/LrealPlcMapper.cs
@@ -9,13 +9,13 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class LrealPlcMapper : PlcMapperBase
- {
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class LrealPlcMapper : PlcMapperBase
+{
- override public int? ElementSize => 8;
+ override public int? ElementSize => 8;
- override public double Decode(Tag tag, int offset) => tag.GetFloat64(offset);
+ override public double Decode(Tag tag, int offset) => tag.GetFloat64(offset);
- override public void Encode(Tag tag, int offset, double value)=> tag.SetFloat64(offset, value);
- }
\ No newline at end of file
+ override public void Encode(Tag tag, int offset, double value)=> tag.SetFloat64(offset, value);
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/PlcMapperBase.cs b/src/libplctag/DataTypes/PlcMapperBase.cs
index 14b25f43..8db78b2e 100644
--- a/src/libplctag/DataTypes/PlcMapperBase.cs
+++ b/src/libplctag/DataTypes/PlcMapperBase.cs
@@ -13,71 +13,71 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public abstract class PlcMapperBase : IPlcMapper, IPlcMapper, IPlcMapper, IPlcMapper
- {
- public PlcType PlcType { get; set; }
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public abstract class PlcMapperBase : IPlcMapper, IPlcMapper, IPlcMapper, IPlcMapper
+{
+ public PlcType PlcType { get; set; }
- abstract public int? ElementSize { get; }
+ abstract public int? ElementSize { get; }
- public int[] ArrayDimensions { get; set; }
+ public int[] ArrayDimensions { get; set; }
- //Multiply all the dimensions to get total elements
- virtual public int? GetElementCount() => ArrayDimensions?.Aggregate(1, (x, y) => x * y);
+ //Multiply all the dimensions to get total elements
+ virtual public int? GetElementCount() => ArrayDimensions?.Aggregate(1, (x, y) => x * y);
+
+ virtual protected T[] DecodeArray(Tag tag)
+ {
+ if (ElementSize is null)
+ throw new ArgumentNullException($"{nameof(ElementSize)} cannot be null for array decoding");
- virtual protected T[] DecodeArray(Tag tag)
- {
- if (ElementSize is null)
- throw new ArgumentNullException($"{nameof(ElementSize)} cannot be null for array decoding");
+ var buffer = new List();
- var buffer = new List();
+ var tagSize = tag.GetSize();
- var tagSize = tag.GetSize();
+ int offset = 0;
+ while (offset < tagSize)
+ {
+ buffer.Add(Decode(tag, offset));
+ offset += ElementSize.Value;
+ }
- int offset = 0;
- while (offset < tagSize)
- {
- buffer.Add(Decode(tag, offset));
- offset += ElementSize.Value;
- }
+ return buffer.ToArray();
- return buffer.ToArray();
+ }
+ virtual protected void EncodeArray(Tag tag, T[] values)
+ {
+ if (ElementSize is null)
+ {
+ throw new ArgumentNullException($"{nameof(ElementSize)} cannot be null for array encoding");
}
- virtual protected void EncodeArray(Tag tag, T[] values)
+ int offset = 0;
+ foreach (var item in values)
{
- if (ElementSize is null)
- {
- throw new ArgumentNullException($"{nameof(ElementSize)} cannot be null for array encoding");
- }
-
- int offset = 0;
- foreach (var item in values)
- {
- Encode(tag, offset, item);
- offset += ElementSize.Value;
- }
+ Encode(tag, offset, item);
+ offset += ElementSize.Value;
}
+ }
- virtual public T Decode(Tag tag) => Decode(tag, 0);
- public abstract T Decode(Tag tag, int offset);
+ virtual public T Decode(Tag tag) => Decode(tag, 0);
+ public abstract T Decode(Tag tag, int offset);
- virtual public void Encode(Tag tag, T value) => Encode(tag, 0, value);
- public abstract void Encode(Tag tag, int offset, T value);
+ virtual public void Encode(Tag tag, T value) => Encode(tag, 0, value);
+ public abstract void Encode(Tag tag, int offset, T value);
- virtual public void Encode(Tag tag, T[] value) => EncodeArray(tag, value);
+ virtual public void Encode(Tag tag, T[] value) => EncodeArray(tag, value);
- T[] IPlcMapper.Decode(Tag tag) => DecodeArray(tag);
+ T[] IPlcMapper.Decode(Tag tag) => DecodeArray(tag);
- T[,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To2DArray(ArrayDimensions[0], ArrayDimensions[1]);
+ T[,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To2DArray(ArrayDimensions[0], ArrayDimensions[1]);
- void IPlcMapper.Encode(Tag tag, T[,] value) => EncodeArray(tag, value.To1DArray());
+ void IPlcMapper.Encode(Tag tag, T[,] value) => EncodeArray(tag, value.To1DArray());
- T[,,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To3DArray(ArrayDimensions[0], ArrayDimensions[1], ArrayDimensions[2]);
+ T[,,] IPlcMapper.Decode(Tag tag) => DecodeArray(tag).To3DArray(ArrayDimensions[0], ArrayDimensions[1], ArrayDimensions[2]);
- void IPlcMapper.Encode(Tag tag, T[,,] value) => EncodeArray(tag, value.To1DArray());
- }
\ No newline at end of file
+ void IPlcMapper.Encode(Tag tag, T[,,] value) => EncodeArray(tag, value.To1DArray());
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/RealPlcMapper.cs b/src/libplctag/DataTypes/RealPlcMapper.cs
index a349a197..74ef1f13 100644
--- a/src/libplctag/DataTypes/RealPlcMapper.cs
+++ b/src/libplctag/DataTypes/RealPlcMapper.cs
@@ -9,14 +9,14 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class RealPlcMapper : PlcMapperBase
- {
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class RealPlcMapper : PlcMapperBase
+{
- override public int? ElementSize => 4;
+ override public int? ElementSize => 4;
- override public float Decode(Tag tag, int offset) => tag.GetFloat32(offset);
+ override public float Decode(Tag tag, int offset) => tag.GetFloat32(offset);
- override public void Encode(Tag tag, int offset, float value) => tag.SetFloat32(offset, value);
+ override public void Encode(Tag tag, int offset, float value) => tag.SetFloat32(offset, value);
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/SintPlcMapper.cs b/src/libplctag/DataTypes/SintPlcMapper.cs
index 3d43e32b..2508974c 100644
--- a/src/libplctag/DataTypes/SintPlcMapper.cs
+++ b/src/libplctag/DataTypes/SintPlcMapper.cs
@@ -9,14 +9,14 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class SintPlcMapper : PlcMapperBase
- {
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class SintPlcMapper : PlcMapperBase
+{
- override public int? ElementSize => 1;
+ override public int? ElementSize => 1;
- override public sbyte Decode(Tag tag, int offset) => tag.GetInt8(offset);
+ override public sbyte Decode(Tag tag, int offset) => tag.GetInt8(offset);
- override public void Encode(Tag tag, int offset, sbyte value) => tag.SetInt8(offset, value);
+ override public void Encode(Tag tag, int offset, sbyte value) => tag.SetInt8(offset, value);
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/StringPlcMapper.cs b/src/libplctag/DataTypes/StringPlcMapper.cs
index 5bf95cd0..9f5046d1 100644
--- a/src/libplctag/DataTypes/StringPlcMapper.cs
+++ b/src/libplctag/DataTypes/StringPlcMapper.cs
@@ -11,29 +11,29 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class StringPlcMapper : PlcMapperBase
- {
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class StringPlcMapper : PlcMapperBase
+{
- override public int? ElementSize
+ override public int? ElementSize
+ {
+ get
{
- get
+ switch (PlcType)
{
- switch (PlcType)
- {
- case PlcType.ControlLogix: return 88;
- case PlcType.Plc5: return 84;
- case PlcType.Slc500: return 84;
- case PlcType.LogixPccc: return 84;
- case PlcType.Micro800: return 256; //To be Confirmed
- case PlcType.MicroLogix: return 84;
- default: throw new NotImplementedException();
- }
+ case PlcType.ControlLogix: return 88;
+ case PlcType.Plc5: return 84;
+ case PlcType.Slc500: return 84;
+ case PlcType.LogixPccc: return 84;
+ case PlcType.Micro800: return 256; //To be Confirmed
+ case PlcType.MicroLogix: return 84;
+ default: throw new NotImplementedException();
}
}
+ }
- override public string Decode(Tag tag, int offset) => tag.GetString(offset);
- override public void Encode(Tag tag, int offset, string value) => tag.SetString(offset, value);
+ override public string Decode(Tag tag, int offset) => tag.GetString(offset);
+ override public void Encode(Tag tag, int offset, string value) => tag.SetString(offset, value);
- }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/libplctag/DataTypes/TimerPlcMapper.cs b/src/libplctag/DataTypes/TimerPlcMapper.cs
index 044c652a..0a0ca4fa 100644
--- a/src/libplctag/DataTypes/TimerPlcMapper.cs
+++ b/src/libplctag/DataTypes/TimerPlcMapper.cs
@@ -12,72 +12,72 @@
namespace libplctag.DataTypes;
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class TimerPlcMapper : PlcMapperBase
- {
-
- public override int? ElementSize => 12;
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class TimerPlcMapper : PlcMapperBase
+{
- public override AbTimer Decode(Tag tag, int offset)
- {
+ public override int? ElementSize => 12;
- // Needed to look at RsLogix documentation for structure of TIMER
- var DINT2 = tag.GetInt32(offset);
- var DINT1 = tag.GetInt32(offset + 4);
- var DINT0 = tag.GetInt32(offset + 8);
+ public override AbTimer Decode(Tag tag, int offset)
+ {
- // The third DINT packs a few BOOLs into it
- var bitArray = new BitArray(new int[] { DINT2 });
+ // Needed to look at RsLogix documentation for structure of TIMER
+ var DINT2 = tag.GetInt32(offset);
+ var DINT1 = tag.GetInt32(offset + 4);
+ var DINT0 = tag.GetInt32(offset + 8);
- var timer = new AbTimer
- {
- Accumulated = DINT0, // ACC
- Preset = DINT1, // PRE
- Done = bitArray[29], // DN
- InProgress = bitArray[30], // TT
- Enabled = bitArray[31] // EN
- };
+ // The third DINT packs a few BOOLs into it
+ var bitArray = new BitArray(new int[] { DINT2 });
- return timer;
+ var timer = new AbTimer
+ {
+ Accumulated = DINT0, // ACC
+ Preset = DINT1, // PRE
+ Done = bitArray[29], // DN
+ InProgress = bitArray[30], // TT
+ Enabled = bitArray[31] // EN
+ };
- }
+ return timer;
- public override void Encode(Tag tag, int offset, AbTimer value)
- {
- var DINT0 = value.Accumulated;
- var DINT1 = value.Preset;
+ }
- var asdf = new BitArray(32);
- asdf[29] = value.Done;
- asdf[30] = value.InProgress;
- asdf[31] = value.Enabled;
- var DINT2 = BitArrayToInt(asdf);
+ public override void Encode(Tag tag, int offset, AbTimer value)
+ {
+ var DINT0 = value.Accumulated;
+ var DINT1 = value.Preset;
- tag.SetInt32(offset, DINT2);
- tag.SetInt32(offset + 4, DINT1);
- tag.SetInt32(offset + 8, DINT0);
+ var asdf = new BitArray(32);
+ asdf[29] = value.Done;
+ asdf[30] = value.InProgress;
+ asdf[31] = value.Enabled;
+ var DINT2 = BitArrayToInt(asdf);
- }
+ tag.SetInt32(offset, DINT2);
+ tag.SetInt32(offset + 4, DINT1);
+ tag.SetInt32(offset + 8, DINT0);
- static int BitArrayToInt(BitArray binary)
- {
- if (binary == null)
- throw new ArgumentNullException("binary");
- if (binary.Length > 32)
- throw new ArgumentException("Must be at most 32 bits long");
-
- var result = new int[1];
- binary.CopyTo(result, 0);
- return result[0];
- }
}
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public class AbTimer
+ static int BitArrayToInt(BitArray binary)
{
- public int Preset { get; set; }
- public int Accumulated { get; set; }
- public bool Enabled { get; set; }
- public bool InProgress { get; set; }
- public bool Done { get; set; }
- }
\ No newline at end of file
+ if (binary == null)
+ throw new ArgumentNullException("binary");
+ if (binary.Length > 32)
+ throw new ArgumentException("Must be at most 32 bits long");
+
+ var result = new int[1];
+ binary.CopyTo(result, 0);
+ return result[0];
+ }
+}
+
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public class AbTimer
+{
+ public int Preset { get; set; }
+ public int Accumulated { get; set; }
+ public bool Enabled { get; set; }
+ public bool InProgress { get; set; }
+ public bool Done { get; set; }
+}
\ No newline at end of file
diff --git a/src/libplctag/DebugLevel.cs b/src/libplctag/DebugLevel.cs
index 45bed688..a9d33948 100644
--- a/src/libplctag/DebugLevel.cs
+++ b/src/libplctag/DebugLevel.cs
@@ -9,26 +9,26 @@
namespace libplctag;
- ///
- /// Debug levels available in the base libplctag library
- ///
- public enum DebugLevel
- {
- ///
- None = DEBUG_LEVEL.PLCTAG_DEBUG_NONE,
+///
+/// Debug levels available in the base libplctag library
+///
+public enum DebugLevel
+{
+ ///
+ None = DEBUG_LEVEL.PLCTAG_DEBUG_NONE,
- ///
- Error = DEBUG_LEVEL.PLCTAG_DEBUG_ERROR,
+ ///
+ Error = DEBUG_LEVEL.PLCTAG_DEBUG_ERROR,
- ///
- Warn = DEBUG_LEVEL.PLCTAG_DEBUG_WARN,
+ ///
+ Warn = DEBUG_LEVEL.PLCTAG_DEBUG_WARN,
- ///
- Info = DEBUG_LEVEL.PLCTAG_DEBUG_INFO,
+ ///
+ Info = DEBUG_LEVEL.PLCTAG_DEBUG_INFO,
- ///
- Detail = DEBUG_LEVEL.PLCTAG_DEBUG_DETAIL,
+ ///
+ Detail = DEBUG_LEVEL.PLCTAG_DEBUG_DETAIL,
- ///
- Spew = DEBUG_LEVEL.PLCTAG_DEBUG_SPEW
- }
\ No newline at end of file
+ ///
+ Spew = DEBUG_LEVEL.PLCTAG_DEBUG_SPEW
+}
\ No newline at end of file
diff --git a/src/libplctag/Event.cs b/src/libplctag/Event.cs
index 905b8e52..79698c21 100644
--- a/src/libplctag/Event.cs
+++ b/src/libplctag/Event.cs
@@ -9,29 +9,29 @@
namespace libplctag;
- ///
- /// Events returned by the base libplctag library
- ///
- public enum Event
- {
- ///
- ReadStarted = EVENT.PLCTAG_EVENT_READ_STARTED,
+///
+/// Events returned by the base libplctag library
+///
+public enum Event
+{
+ ///
+ ReadStarted = EVENT.PLCTAG_EVENT_READ_STARTED,
- ///
- ReadCompleted = EVENT.PLCTAG_EVENT_READ_COMPLETED,
+ ///
+ ReadCompleted = EVENT.PLCTAG_EVENT_READ_COMPLETED,
- ///
- WriteStarted = EVENT.PLCTAG_EVENT_WRITE_STARTED,
+ ///
+ WriteStarted = EVENT.PLCTAG_EVENT_WRITE_STARTED,
- ///
- WriteCompleted = EVENT.PLCTAG_EVENT_WRITE_COMPLETED,
+ ///
+ WriteCompleted = EVENT.PLCTAG_EVENT_WRITE_COMPLETED,
- ///
- Aborted = EVENT.PLCTAG_EVENT_ABORTED,
+ ///
+ Aborted = EVENT.PLCTAG_EVENT_ABORTED,
- ///
- Destroyed = EVENT.PLCTAG_EVENT_DESTROYED,
+ ///
+ Destroyed = EVENT.PLCTAG_EVENT_DESTROYED,
- ///
- Created = EVENT.PLCTAG_EVENT_CREATED
- }
\ No newline at end of file
+ ///
+ Created = EVENT.PLCTAG_EVENT_CREATED
+}
\ No newline at end of file
diff --git a/src/libplctag/INative.cs b/src/libplctag/INative.cs
index 79c0e42f..884c9303 100644
--- a/src/libplctag/INative.cs
+++ b/src/libplctag/INative.cs
@@ -16,57 +16,57 @@
namespace libplctag;
- interface INative
- {
- int plc_tag_abort(int tag);
- int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch);
- int plc_tag_create(string lpString, int timeout);
- int plc_tag_create_ex(string lpString, callback_func_ex func, IntPtr userdata, int timeout);
- string plc_tag_decode_error(int err);
- int plc_tag_destroy(int tag);
- int plc_tag_get_bit(int tag, int offset_bit);
- float plc_tag_get_float32(int tag, int offset);
- double plc_tag_get_float64(int tag, int offset);
- short plc_tag_get_int16(int tag, int offset);
- int plc_tag_get_int32(int tag, int offset);
- long plc_tag_get_int64(int tag, int offset);
- 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);
- uint plc_tag_get_uint32(int tag, int offset);
- ulong plc_tag_get_uint64(int tag, int offset);
- byte plc_tag_get_uint8(int tag, int offset);
- int plc_tag_lock(int tag);
- int plc_tag_read(int tag, int timeout);
- int plc_tag_register_callback(int tag_id, callback_func func);
- int plc_tag_register_logger(log_callback_func func);
- int plc_tag_set_bit(int tag, int offset_bit, int val);
- void plc_tag_set_debug_level(int debug_level);
- int plc_tag_set_float32(int tag, int offset, float val);
- int plc_tag_set_float64(int tag, int offset, double val);
- int plc_tag_set_int16(int tag, int offset, short val);
- int plc_tag_set_int32(int tag, int offset, int val);
- int plc_tag_set_int64(int tag, int offset, long val);
- int plc_tag_set_int8(int tag, int offset, sbyte val);
- int plc_tag_set_uint16(int tag, int offset, ushort val);
- int plc_tag_set_uint32(int tag, int offset, uint val);
- int plc_tag_set_uint64(int tag, int offset, ulong val);
- int plc_tag_set_uint8(int tag, int offset, byte val);
- void plc_tag_shutdown();
- int plc_tag_status(int tag);
- int plc_tag_unlock(int tag);
- int plc_tag_unregister_callback(int tag_id);
- int plc_tag_unregister_logger();
- int plc_tag_write(int tag, int timeout);
- int plc_tag_get_raw_bytes(int tag, int start_offset, byte[] buffer, int buffer_length);
- int plc_tag_set_raw_bytes(int tag, int start_offset, byte[] buffer, int buffer_length);
- int plc_tag_get_string_length(int tag, int string_start_offset);
- int plc_tag_get_string(int tag, int string_start_offset, StringBuilder buffer, int buffer_length);
- int plc_tag_get_string_total_length(int tag, int string_start_offset);
- int plc_tag_get_string_capacity(int tag, int string_start_offset);
- int plc_tag_set_string(int tag, int string_start_offset, string string_val);
- }
\ No newline at end of file
+interface INative
+{
+ int plc_tag_abort(int tag);
+ int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch);
+ int plc_tag_create(string lpString, int timeout);
+ int plc_tag_create_ex(string lpString, callback_func_ex func, IntPtr userdata, int timeout);
+ string plc_tag_decode_error(int err);
+ int plc_tag_destroy(int tag);
+ int plc_tag_get_bit(int tag, int offset_bit);
+ float plc_tag_get_float32(int tag, int offset);
+ double plc_tag_get_float64(int tag, int offset);
+ short plc_tag_get_int16(int tag, int offset);
+ int plc_tag_get_int32(int tag, int offset);
+ long plc_tag_get_int64(int tag, int offset);
+ 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);
+ uint plc_tag_get_uint32(int tag, int offset);
+ ulong plc_tag_get_uint64(int tag, int offset);
+ byte plc_tag_get_uint8(int tag, int offset);
+ int plc_tag_lock(int tag);
+ int plc_tag_read(int tag, int timeout);
+ int plc_tag_register_callback(int tag_id, callback_func func);
+ int plc_tag_register_logger(log_callback_func func);
+ int plc_tag_set_bit(int tag, int offset_bit, int val);
+ void plc_tag_set_debug_level(int debug_level);
+ int plc_tag_set_float32(int tag, int offset, float val);
+ int plc_tag_set_float64(int tag, int offset, double val);
+ int plc_tag_set_int16(int tag, int offset, short val);
+ int plc_tag_set_int32(int tag, int offset, int val);
+ int plc_tag_set_int64(int tag, int offset, long val);
+ int plc_tag_set_int8(int tag, int offset, sbyte val);
+ int plc_tag_set_uint16(int tag, int offset, ushort val);
+ int plc_tag_set_uint32(int tag, int offset, uint val);
+ int plc_tag_set_uint64(int tag, int offset, ulong val);
+ int plc_tag_set_uint8(int tag, int offset, byte val);
+ void plc_tag_shutdown();
+ int plc_tag_status(int tag);
+ int plc_tag_unlock(int tag);
+ int plc_tag_unregister_callback(int tag_id);
+ int plc_tag_unregister_logger();
+ int plc_tag_write(int tag, int timeout);
+ int plc_tag_get_raw_bytes(int tag, int start_offset, byte[] buffer, int buffer_length);
+ int plc_tag_set_raw_bytes(int tag, int start_offset, byte[] buffer, int buffer_length);
+ int plc_tag_get_string_length(int tag, int string_start_offset);
+ int plc_tag_get_string(int tag, int string_start_offset, StringBuilder buffer, int buffer_length);
+ int plc_tag_get_string_total_length(int tag, int string_start_offset);
+ int plc_tag_get_string_capacity(int tag, int string_start_offset);
+ int plc_tag_set_string(int tag, int string_start_offset, string string_val);
+}
\ No newline at end of file
diff --git a/src/libplctag/ITag.cs b/src/libplctag/ITag.cs
index 3bf88b76..c0dceb30 100644
--- a/src/libplctag/ITag.cs
+++ b/src/libplctag/ITag.cs
@@ -11,41 +11,41 @@
namespace libplctag;
- ///
- /// An interface to represent any generic tag without
- /// exposing its value
- ///
- [Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
- public interface ITag : IDisposable
- {
- int[] ArrayDimensions { get; set; }
- string Gateway { get; set; }
- string Name { get; set; }
- string Path { get; set; }
- PlcType? PlcType { get; set; }
- Protocol? Protocol { get; set; }
- int? ReadCacheMillisecondDuration { get; set; }
- TimeSpan Timeout { get; set; }
- bool? UseConnectedMessaging { get; set; }
- bool? AllowPacking { get; set; }
- TimeSpan? AutoSyncReadInterval { get; set; }
- TimeSpan? AutoSyncWriteInterval { get; set; }
- DebugLevel DebugLevel { get; set; }
+///
+/// An interface to represent any generic tag without
+/// exposing its value
+///
+[Obsolete("see - https://github.com/libplctag/libplctag.NET/issues/406")]
+public interface ITag : IDisposable
+{
+ int[] ArrayDimensions { get; set; }
+ string Gateway { get; set; }
+ string Name { get; set; }
+ string Path { get; set; }
+ PlcType? PlcType { get; set; }
+ Protocol? Protocol { get; set; }
+ int? ReadCacheMillisecondDuration { get; set; }
+ TimeSpan Timeout { get; set; }
+ bool? UseConnectedMessaging { get; set; }
+ bool? AllowPacking { get; set; }
+ TimeSpan? AutoSyncReadInterval { get; set; }
+ TimeSpan? AutoSyncWriteInterval { get; set; }
+ DebugLevel DebugLevel { get; set; }
- event EventHandler ReadStarted;
- event EventHandler ReadCompleted;
- event EventHandler WriteStarted;
- event EventHandler WriteCompleted;
- event EventHandler Aborted;
- event EventHandler Destroyed;
+ event EventHandler ReadStarted;
+ event EventHandler ReadCompleted;
+ event EventHandler WriteStarted;
+ event EventHandler WriteCompleted;
+ event EventHandler Aborted;
+ event EventHandler Destroyed;
- Status GetStatus();
- void Initialize();
- Task InitializeAsync(CancellationToken token = default);
- object Read();
- Task