From c45b779b48ff00f7a8c248236a0fca515b226954 Mon Sep 17 00:00:00 2001 From: parallelbgls Date: Wed, 24 May 2017 16:48:44 +0800 Subject: [PATCH] Fix a bug in LRC --- Modbus.Net/src/Base.Common/CRC16.cs | 2 ++ .../Modbus.Net.Tests/Modbus.Net.Tests.csproj | 5 +++ Tests/Modbus.Net.Tests/Modbus.Net.orderedtest | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 Tests/Modbus.Net.Tests/Modbus.Net.orderedtest diff --git a/Modbus.Net/src/Base.Common/CRC16.cs b/Modbus.Net/src/Base.Common/CRC16.cs index 478d6e2..16e19b2 100644 --- a/Modbus.Net/src/Base.Common/CRC16.cs +++ b/Modbus.Net/src/Base.Common/CRC16.cs @@ -176,6 +176,8 @@ namespace Modbus.Net } hexTotal = string.Concat(hexByte, hexTotal); } + if (hexTotal.Length == 0) hexTotal = "00" + hexTotal; + if (hexTotal.Length == 1) hexTotal = "0" + hexTotal; return hexTotal == checkString; } diff --git a/Tests/Modbus.Net.Tests/Modbus.Net.Tests.csproj b/Tests/Modbus.Net.Tests/Modbus.Net.Tests.csproj index 82f82f2..0d888dc 100644 --- a/Tests/Modbus.Net.Tests/Modbus.Net.Tests.csproj +++ b/Tests/Modbus.Net.Tests/Modbus.Net.Tests.csproj @@ -79,6 +79,11 @@ Modbus.Net + + + PreserveNewest + + diff --git a/Tests/Modbus.Net.Tests/Modbus.Net.orderedtest b/Tests/Modbus.Net.Tests/Modbus.Net.orderedtest new file mode 100644 index 0000000..cb74ea2 --- /dev/null +++ b/Tests/Modbus.Net.Tests/Modbus.Net.orderedtest @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file