diff --git a/src/FluentModbus/Server/ModbusServer.cs b/src/FluentModbus/Server/ModbusServer.cs index cb5290a..1c59a0d 100644 --- a/src/FluentModbus/Server/ModbusServer.cs +++ b/src/FluentModbus/Server/ModbusServer.cs @@ -232,6 +232,15 @@ public Span GetInputRegisterBuffer(byte unitIdentifier = 0) where T : unma /// /// The unit identifier of the input register buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). public Span GetInputRegisterBuffer(byte unitIdentifier = 0) + { + return GetInputRegisterMemory(unitIdentifier).Span; + } + + /// + /// Gets the input register. + /// + /// The unit identifier of the input register buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). + public Memory GetInputRegisterMemory(byte unitIdentifier = 0) { return Find(unitIdentifier, _inputRegisterBufferMap); } @@ -260,6 +269,15 @@ public Span GetHoldingRegisterBuffer(byte unitIdentifier = 0) where T : un /// /// The unit identifier of the holding register buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). public Span GetHoldingRegisterBuffer(byte unitIdentifier = 0) + { + return GetHoldingRegisterMemory(unitIdentifier).Span; + } + + /// + /// Gets the holding register buffer. + /// + /// The unit identifier of the holding register buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). + public Memory GetHoldingRegisterMemory(byte unitIdentifier = 0) { return Find(unitIdentifier, _holdingRegisterBufferMap); } @@ -288,6 +306,15 @@ public Span GetCoilBuffer(byte unitIdentifier = 0) where T : unmanaged /// /// The unit identifier of the coil buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). public Span GetCoilBuffer(byte unitIdentifier = 0) + { + return GetCoilMemory(unitIdentifier).Span; + } + + /// + /// Gets the coil buffer. + /// + /// The unit identifier of the coil buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). + public Memory GetCoilMemory(byte unitIdentifier = 0) { return Find(unitIdentifier, _coilBufferMap); } @@ -316,6 +343,15 @@ public Span GetDiscreteInputBuffer(byte unitIdentifier = 0) where T : unma /// /// The unit identifier of the discrete input buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). public Span GetDiscreteInputBuffer(byte unitIdentifier = 0) + { + return GetDiscreteInputMemory(unitIdentifier).Span; + } + + /// + /// Gets the discrete input buffer. + /// + /// The unit identifier of the discrete input buffer to return. A value of 0 means that the default unit identifier is used (for single-unit mode only). + public Memory GetDiscreteInputMemory(byte unitIdentifier = 0) { return Find(unitIdentifier, _discreteInputBufferMap); } @@ -449,7 +485,7 @@ public void RemoveUnit(byte unitIdentifer) } } - private Span Find(byte unitIdentifier, Dictionary map) + private Memory Find(byte unitIdentifier, Dictionary map) { if (!map.TryGetValue(unitIdentifier, out var buffer)) throw new KeyNotFoundException(ErrorMessage.ModbusServer_UnitIdentifierNotFound); @@ -459,10 +495,10 @@ private Span Find(byte unitIdentifier, Dictionary map) internal void OnRegistersChanged(byte unitIdentifier, int[] registers) { - RegistersChanged?.Invoke(this, new RegistersChangedEventArgs() - { + RegistersChanged?.Invoke(this, new RegistersChangedEventArgs() + { UnitIdentifier = unitIdentifier, - Registers = registers + Registers = registers }); }