Skip to content

Commit

Permalink
Release 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Jan 18, 2025
1 parent 016960d commit e88ac87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/Meadow.Modbus/Clients/ModbusRtuClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ protected override async Task<byte[]> ReadResult(ModbusFunction function)

while (_port.BytesToRead < 5)
{
await Task.Delay(10);
t += 10;
if (_port.ReadTimeout.TotalMilliseconds > 0 && t > _port.ReadTimeout.TotalMilliseconds) throw new TimeoutException();
if (_port.ReadTimeout.TotalMilliseconds > 0 && t > _port.ReadTimeout.TotalMilliseconds)
{
throw new TimeoutException();
}
await Task.Delay(10);
}

int headerLen = function switch
Expand Down Expand Up @@ -118,7 +121,7 @@ protected override async Task<byte[]> ReadResult(ModbusFunction function)
read = 0;
while (read < 2)
{
_port.Read(errpacket, 3 + read, 2 - read);
read += _port.Read(errpacket, 3 + read, 2 - read);
}

var errorCode = (ModbusErrorCode)errpacket[2];
Expand All @@ -136,7 +139,11 @@ protected override async Task<byte[]> ReadResult(ModbusFunction function)
// read the remainder of the header
if (headerLen > 3)
{
_port.Read(header, 3, headerLen - 3);
read = 0;
while (read < headerLen - 2)
{
read += _port.Read(header, 3, headerLen - 3);
}
}

int bufferLen;
Expand Down Expand Up @@ -191,7 +198,7 @@ protected override async Task<byte[]> ReadResult(ModbusFunction function)
var result = new byte[resultLen];
Array.Copy(buffer, headerLen, result, 0, result.Length);

return await Task.FromResult(result);
return result;
}

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion src/Meadow.Modbus/Meadow.Modbus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Meadow.Contracts" Version="2.0.0.3" />
<PackageReference Include="Meadow.Contracts" Version="2.0.1" />
</ItemGroup>
</Project>

0 comments on commit e88ac87

Please sign in to comment.