Skip to content

Commit

Permalink
Fixed #3 and added test case. Version increase to 1.0.8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelventura committed Mar 20, 2020
1 parent 611a583 commit 8568647
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion SharpModbus/ModbusTCPProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ public class ModbusTCPProtocol : IModbusProtocol

private int TransactionId { get { return transactionId; } }

private int NextTid()
{
var tid = transactionId++;
transactionId &= 0xFFFF;
return tid;
}

public IModbusWrapper Wrap(IModbusCommand wrapped)
{
return new ModbusTCPWrapper(wrapped, transactionId++);
return new ModbusTCPWrapper(wrapped, NextTid());
}

public IModbusWrapper Parse(byte[] request, int offset)
Expand Down
2 changes: 1 addition & 1 deletion SharpModbus/SharpModbus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
<PackageId>SharpModbus</PackageId>
<PackageVersion>1.0.7.0</PackageVersion>
<PackageVersion>1.0.8.0</PackageVersion>
<Description>C# Modbus Tools</Description>
<Authors>Samuel Ventura</Authors>
<PackageProjectUrl>https://github.com/samuelventura/SharpModbus</PackageProjectUrl>
Expand Down
3 changes: 2 additions & 1 deletion SharpModbusTest/MasterSlaveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public void TcpSlaveTest()
var model = new ModbusModel();
var stream = new ModelStream(model, new ModbusTCPScanner());
var master = new ModbusMaster(stream, new ModbusTCPProtocol());
Test(model, master);
//ensure TransactionId wraps around 0xFFFF
for(var i=0; i<=0xFFFF; i++) Test(model, master);
}

void Test(ModbusModel model, ModbusMaster master)
Expand Down

0 comments on commit 8568647

Please sign in to comment.