From 897801018cd7aa992521d02d5991225afcc8424f Mon Sep 17 00:00:00 2001 From: PTKu Date: Fri, 8 Sep 2023 12:18:51 +0200 Subject: [PATCH 1/3] Create draft PR for #217 From e5c00cf520f32e9cd4a662232864f6fc288099f8 Mon Sep 17 00:00:00 2001 From: PTKu <61538034+PTKu@users.noreply.github.com> Date: Sat, 9 Sep 2023 07:39:22 +0200 Subject: [PATCH 2/3] wip --- .../BuiltInWrappers/WebApiBool.cs | 5 ++++- .../BuiltInWrappers/WebApiByte.cs | 8 ++++++-- .../BuiltInWrappers/WebApiChar.cs | 5 ++++- .../BuiltInWrappers/WebApiDInt.cs | 5 ++++- .../BuiltInWrappers/WebApiDWord.cs | 5 ++++- .../BuiltInWrappers/WebApiDate.cs | 8 ++++++-- .../BuiltInWrappers/WebApiDateTime.cs | 10 ++++++++-- .../BuiltInWrappers/WebApiInt.cs | 5 ++++- .../BuiltInWrappers/WebApiLDate.cs | 3 +-- .../BuiltInWrappers/WebApiLDateTime.cs | 5 +++-- .../BuiltInWrappers/WebApiLInt.cs | 5 ++++- .../BuiltInWrappers/WebApiLReal.cs | 8 ++++++-- .../BuiltInWrappers/WebApiLTime.cs | 7 +++++-- .../BuiltInWrappers/WebApiLTimeOfDay.cs | 5 ++++- .../BuiltInWrappers/WebApiLWord.cs | 8 ++++++-- .../BuiltInWrappers/WebApiReal.cs | 8 ++++++-- .../BuiltInWrappers/WebApiSInt.cs | 8 ++++++-- .../BuiltInWrappers/WebApiTime.cs | 8 ++++++-- .../BuiltInWrappers/WebApiTimeOfDay.cs | 8 ++++++-- .../BuiltInWrappers/WebApiUInt.cs | 5 ++++- .../BuiltInWrappers/WebApiULInt.cs | 5 ++++- .../BuiltInWrappers/WebApiUSInt.cs | 5 ++++- .../BuiltInWrappers/WebApiUdInt.cs | 5 ++++- .../BuiltInWrappers/WebApiWChar.cs | 5 ++++- .../BuiltInWrappers/WebApiWord.cs | 5 ++++- .../AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs | 3 +++ 26 files changed, 120 insertions(+), 37 deletions(-) diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiBool.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiBool.cs index 0c8eb111..e2e86f72 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiBool.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiBool.cs @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(bool.Parse(value)); + if (bool.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiByte.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiByte.cs index 5dee6310..9936b5ea 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiByte.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiByte.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -64,9 +65,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(byte.Parse(result)); + if (byte.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiChar.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiChar.cs index 9b9ec09b..239cdd0a 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiChar.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiChar.cs @@ -71,7 +71,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(char.Parse(value)); + if (char.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDInt.cs index ef06c264..c9ae0ab2 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDInt.cs @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(int.Parse(value)); + if (int.TryParse(value, out var val)) + { + UpdateRead(val); + } } diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDWord.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDWord.cs index c978b14e..2bf16f5d 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDWord.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDWord.cs @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(uint.Parse(value)); + if (uint.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDate.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDate.cs index 36ac1b9c..aee78090 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDate.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDate.cs @@ -77,8 +77,12 @@ public override async Task GetAsync() private DateOnly GetFromBinary(string value) { - var val = long.Parse(value); - return GetFromBinary(val); + if (long.TryParse(value, out var val)) + { + return GetFromBinary(val); + } + + return DateOnly.MinValue; } private DateOnly GetFromBinary(long value) diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDateTime.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDateTime.cs index 172b011a..0f605e79 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDateTime.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiDateTime.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -75,9 +76,14 @@ public override async Task GetAsync() return await _webApiConnector.ReadAsync(this); } - private DateTime GetFromBinary(string val) + private DateTime GetFromBinary(string value) { - return GetFromBinary(long.Parse(val)); + if (long.TryParse(value, out var val)) + { + return GetFromBinary(val); + } + + return DateTime.MinValue; } private DateTime GetFromBinary(long val) diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiInt.cs index 405141d4..28d6fc00 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiInt.cs @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(short.Parse(value)); + if (short.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDate.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDate.cs index ff543163..5333aa38 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDate.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDate.cs @@ -78,8 +78,7 @@ public override async Task GetAsync() private DateOnly GetFromBinary(string value) { - var val = long.Parse(value); - return GetFromBinary(val); + return long.TryParse(value, out var val) ? GetFromBinary(val) : DateOnly.MinValue; } private DateOnly GetFromBinary(long value) diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDateTime.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDateTime.cs index 35390ab2..426605ca 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDateTime.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLDateTime.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -75,9 +76,9 @@ public override async Task GetAsync() return await _webApiConnector.ReadAsync(this); } - private DateTime GetFromBinary(string val) + private DateTime GetFromBinary(string value) { - return GetFromBinary(long.Parse(val)); + return long.TryParse(value, out var val) ? GetFromBinary(val) : DateTime.MinValue; } private DateTime GetFromBinary(long val) diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLInt.cs index 2edb1eed..e3791218 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLInt.cs @@ -73,7 +73,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(long.Parse(value)); + if (long.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLReal.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLReal.cs index 3f55c360..3ed12f0a 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLReal.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLReal.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(double.Parse(result)); + if (double.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTime.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTime.cs index ca2bf1df..2252e3f0 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTime.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTime.cs @@ -66,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(long.Parse(result)))); + if (long.TryParse(value, out var val)) + { + UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(val))); + } } diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTimeOfDay.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTimeOfDay.cs index 36dbd5f9..192d5e77 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTimeOfDay.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLTimeOfDay.cs @@ -68,7 +68,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(TimeSpan.FromMilliseconds(long.Parse(value) / 1000000)); + if (long.TryParse(value, out var val)) + { + UpdateRead(TimeSpan.FromMilliseconds(val / 1000000)); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLWord.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLWord.cs index 3df3edce..1d1088a0 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLWord.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiLWord.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(ulong.Parse(result)); + if (ulong.TryParse(value, out var val)) + { + UpdateRead(val); + } } diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiReal.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiReal.cs index 68efccdd..a8d23b31 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiReal.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiReal.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -64,9 +65,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(float.Parse(result)); + if (float.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiSInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiSInt.cs index 199ad7c5..08c4390a 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiSInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiSInt.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -64,9 +65,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(sbyte.Parse(result)); + if (sbyte.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTime.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTime.cs index 42b8fb80..1d638751 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTime.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTime.cs @@ -6,6 +6,7 @@ // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(long.Parse(result)))); + if (long.TryParse(value, out var val)) + { + UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(val))); + } } diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTimeOfDay.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTimeOfDay.cs index 8cee0b52..9ad2404f 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTimeOfDay.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiTimeOfDay.cs @@ -7,6 +7,7 @@ using System.Globalization; using AXSharp.Connector.ValueTypes; +using Newtonsoft.Json.Linq; namespace AXSharp.Connector.S71500.WebApi; @@ -65,9 +66,12 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData } /// - public void Read(string result) + public void Read(string value) { - UpdateRead(TimeSpan.FromMilliseconds(long.Parse(result) / 1000000)); + if (long.TryParse(value, out var val)) + { + UpdateRead(TimeSpan.FromMilliseconds(val / 1000000)); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUInt.cs index 55205931..e24c9b95 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUInt.cs @@ -65,7 +65,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(ushort.Parse(value)); + if (ushort.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiULInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiULInt.cs index 3f04d188..bfc01843 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiULInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiULInt.cs @@ -68,7 +68,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(ulong.Parse(value)); + if (ulong.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUSInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUSInt.cs index 38d3b07f..13c92d6c 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUSInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUSInt.cs @@ -67,7 +67,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(byte.Parse(value)); + if (byte.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUdInt.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUdInt.cs index 5a16c509..d58267e2 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUdInt.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiUdInt.cs @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(uint.Parse(value)); + if (uint.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWChar.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWChar.cs index 4466bd23..ba390b01 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWChar.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWChar.cs @@ -72,7 +72,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(char.Parse(value)); + if (char.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWord.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWord.cs index d407e6f2..399ef292 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWord.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/BuiltInWrappers/WebApiWord.cs @@ -66,7 +66,10 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData /// public void Read(string value) { - UpdateRead(ushort.Parse(value)); + if (ushort.TryParse(value, out var val)) + { + UpdateRead(val); + } } /// diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs index b1845b87..e3e8f69c 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs @@ -20,6 +20,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Net; +using System.Xml.Serialization; using Polly; using Polly.Retry; using Newtonsoft.Json.Linq; @@ -288,6 +289,8 @@ public override async Task ReadBatchAsync(IEnumerable? primitive { await RetryPolicy.ExecuteAsync(async () => responseData = await RequestHandler.ApiBulkAsync(segment)); + + var position = 0; apiPrimitives.ToList() .ForEach(p => From 4519891bcfad90fb444f0b2414c014b7c3e9e602 Mon Sep 17 00:00:00 2001 From: PTKu <61538034+PTKu@users.noreply.github.com> Date: Mon, 11 Sep 2023 09:52:37 +0200 Subject: [PATCH 3/3] adds response check due to unassigned CHAR and WCHAR not appearing in the resutls when reading --- .../WebApiConnector.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs index e3e8f69c..266685ba 100644 --- a/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs +++ b/src/AXSharp.connectors/src/AXSharp.Connector.S71500.WebAPI/WebApiConnector.cs @@ -289,15 +289,28 @@ public override async Task ReadBatchAsync(IEnumerable? primitive { await RetryPolicy.ExecuteAsync(async () => responseData = await RequestHandler.ApiBulkAsync(segment)); - - - var position = 0; - apiPrimitives.ToList() - .ForEach(p => + // This is needed when unassigned CHAR or WCHAR are read; they won't be present in the response. + if (responseData.SuccessfulResponses.Count() != apiPrimitives.Length) + { + foreach (var response in responseData.SuccessfulResponses) { - p.Read(responseData.SuccessfulResponses.ElementAt(position++).Result.ToString()); - p.AccessStatus.Update(RwCycleCount); - }); + var a = apiPrimitives.FirstOrDefault(p => p.PeekPlcReadRequestData.Id == response.Id); + if (a == null) continue; + a.Read(response.Result.ToString()); + a.AccessStatus.Update(RwCycleCount); + } + } + else + { + var position = 0; + apiPrimitives.ToList() + .ForEach(p => + { + p.Read(responseData.SuccessfulResponses.ElementAt(position++).Result.ToString()); + p.AccessStatus.Update(RwCycleCount); + }); + } + } catch (ApiBulkRequestException apiException) {