diff --git a/src/Examples/VB.NET DotNetCore/VB.NET DotNetCore.vbproj b/src/Examples/VB.NET DotNetCore/VB.NET DotNetCore.vbproj
index 59297548..e824a0d4 100644
--- a/src/Examples/VB.NET DotNetCore/VB.NET DotNetCore.vbproj
+++ b/src/Examples/VB.NET DotNetCore/VB.NET DotNetCore.vbproj
@@ -3,7 +3,7 @@
Exe
VB.NET_DotNetCore
- netcoreapp3.1
+ netcoreapp3.1
diff --git a/src/libplctag.Tests/AsyncTests.cs b/src/libplctag.Tests/AsyncTests.cs
index 92720a9a..a29eb2d1 100644
--- a/src/libplctag.Tests/AsyncTests.cs
+++ b/src/libplctag.Tests/AsyncTests.cs
@@ -65,7 +65,7 @@ public async Task Timeout_throws_a_LibPlcTagException()
};
// Act
- var ex = await Assert.ThrowsAsync(async () => {
+ var ex = await Assert.ThrowsAsync(async () => {
await tag.InitializeAsync();
});
@@ -73,6 +73,58 @@ public async Task Timeout_throws_a_LibPlcTagException()
Assert.Equal(Status.ErrorTimeout.ToString(), ex.Message);
}
+ [Fact]
+ public async Task TryInitialize_returns_an_ErrorTimeout()
+ {
+ // 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(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);
+
+ var tag = new NativeTagWrapper(nativeTag.Object)
+ {
+ Timeout = REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS
+ };
+
+ // Act
+ var result = await tag.TryInitializeAsync();
+
+ // Assert
+ Assert.Equal(Status.ErrorTimeout, result);
+ }
+
+ [Fact]
+ public async Task TryInitialize_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(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);
+
+ var tag = new NativeTagWrapper(nativeTag.Object);
+ var cts = new CancellationTokenSource();
+
+ // Act
+ cts.CancelAfter(REALISTIC_TIMEOUT_FOR_ALL_OPERATIONS);
+
+ // Assert
+ await Assert.ThrowsAsync(async () => {
+ await tag.TryInitializeAsync(cts.Token);
+ });
+ }
+
[Fact]
public async Task Timeout_returns_pending_but_eventually_ok()
{
diff --git a/src/libplctag/ITag.cs b/src/libplctag/ITag.cs
index 5da8bb50..82a483fa 100644
--- a/src/libplctag/ITag.cs
+++ b/src/libplctag/ITag.cs
@@ -41,10 +41,18 @@ public interface ITag : IDisposable
Status GetStatus();
void Initialize();
Task InitializeAsync(CancellationToken token = default);
+ bool TryInitialize();
+ Task TryInitializeAsync(CancellationToken token = default);
+
object Read();
Task