Fixed casting in GetIntAt

- fix #29
This commit is contained in:
Federico Barresi
2022-05-18 14:29:28 +02:00
parent eb8448a59c
commit 5a3c85c5f7
3 changed files with 9 additions and 3 deletions

View File

@@ -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`

View File

@@ -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 })]

View File

@@ -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)