Skip to content

Commit

Permalink
Update docs to reflect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
helynranta committed Oct 11, 2024
1 parent c3709f1 commit d0845f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
6 changes: 3 additions & 3 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ It might happen that a server should not support all Modbus functions or only a

var server = new ModbusTcpServer()
{
RequestValidator = (unitIdentifier, functionCode, address, quantityOfRegisters) =>
RequestValidator = (args) =>
{
if (functionCode == ModbusFunctionCode.WriteSingleRegister)
if (args.FunctionCode == ModbusFunctionCode.WriteSingleRegister)
return ModbusExceptionCode.IllegalFunction;

else if (address < 5 || address > 15)
else if (args.Address < 5 || args.Address > 15)
return ModbusExceptionCode.IllegalDataAddress;

else
Expand Down
14 changes: 5 additions & 9 deletions doc/samples/modbus_validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ var server = new ModbusTcpServer()
RequestValidator = this.ModbusValidator;
};

private ModbusExceptionCode ModbusValidator(
byte unitIdentifier,
ModbusFunctionCode functionCode,
ushort address,
ushort quantityOfRegisters)
private ModbusExceptionCode ModbusValidator(RequestValidatorArgs args)
{
// check if address is within valid holding register limits
var holdingLimits = (address >= 50 && address < 90) ||
address >= 2000 && address < 2100;
var holdingLimits = (args.Address >= 50 && args.Address < 90) ||
args.Address >= 2000 && args.Address < 2100;

// check if address is within valid input register limits
var inputLimits = address >= 1000 && address < 2000;
var inputLimits = args.Address >= 1000 && args.Address < 2000;

// go through all cases and return proper response
return (functionCode, holdingLimits, inputLimits) switch
return (args.FunctionCode, holdingLimits, inputLimits) switch
{
// holding registers
(ModbusFunctionCode.ReadHoldingRegisters, true, _) => ModbusExceptionCode.OK,
Expand Down

0 comments on commit d0845f6

Please sign in to comment.