diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b36d2..d3924f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changed to this project will be documented in this file. +## [1.1.80] - 18.05.2022 +### Added +### Changed +### Fixed +- Fixed casting in GetIntAt [#29](https://github.com/fbarresi/Sharp7/issues/29) + ## [1.1.79] - 09.02.2021 ### Added - Constant for no errors `S7Consts.ResultOK` diff --git a/Sharp7.Tests/TestUtilities.cs b/Sharp7.Tests/TestUtilities.cs index 5aff84c..8f95fab 100644 --- a/Sharp7.Tests/TestUtilities.cs +++ b/Sharp7.Tests/TestUtilities.cs @@ -100,7 +100,7 @@ namespace Sharp7.Tests [Theory] [InlineData(new byte[] { 1, 1, 0, 0 }, 0, 257)] - public void TestGetIntAt(byte[] buffer, int pos, int expected) { S7.GetIntAt(buffer, pos).ShouldBe(expected); } + public void TestGetIntAt(byte[] buffer, int pos, short expected) { S7.GetIntAt(buffer, pos).ShouldBe(expected); } [Theory] [InlineData(new byte[] { 0, 0, 0, 0 }, 0, 1, new byte[] { 0, 1, 0, 0 })] diff --git a/Sharp7/S7.cs b/Sharp7/S7.cs index 6b91a32..ee24c7a 100644 --- a/Sharp7/S7.cs +++ b/Sharp7/S7.cs @@ -103,9 +103,9 @@ namespace Sharp7 #region Get/Set 16 bit signed value (S7 int) -32768..32767 - public static int GetIntAt(this byte[] buffer, int pos) + public static short GetIntAt(this byte[] buffer, int pos) { - return (buffer[pos] << 8) | buffer[pos + 1]; + return (short)((buffer[pos] << 8) | buffer[pos + 1]); } public static void SetIntAt(this byte[] buffer, int pos, Int16 value)