Implementing ASCII protocol; removing min. unit ID for serial line - see note on README
This commit is contained in:
@@ -13,12 +13,19 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// The minimum allowed unit id specified by the Modbus TCP protocol.
|
||||
/// The minimum allowed unit id specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <strong>INFORMATION:</strong>
|
||||
/// <br/>
|
||||
/// Reading the specification, the minimum allowed unit ID would be <strong>1</strong>.
|
||||
/// <br/>
|
||||
/// As of other implementations seen, this limit is <em>not</em> enforced!
|
||||
/// </remarks>
|
||||
public const byte MIN_UNIT_ID = 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum allowed unit id specified by the Modbus TCP protocol.
|
||||
/// The maximum allowed unit id specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Reading the specification, the max allowed unit id would be <strong>247</strong>!
|
||||
@@ -26,32 +33,32 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
public const byte MAX_UNIT_ID = 0xFF;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum allowed read count specified by the Modbus TCP protocol.
|
||||
/// The minimum allowed read count specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
public const ushort MIN_READ_COUNT = 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum allowed write count specified by the Modbus TCP protocol.
|
||||
/// The minimum allowed write count specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
public const ushort MIN_WRITE_COUNT = 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum allowed read count for discrete values specified by the Modbus TCP protocol.
|
||||
/// The maximum allowed read count for discrete values specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
public const ushort MAX_DISCRETE_READ_COUNT = 0x07D0; // 2000
|
||||
|
||||
/// <summary>
|
||||
/// The maximum allowed write count for discrete values specified by the Modbus TCP protocol.
|
||||
/// The maximum allowed write count for discrete values specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
public const ushort MAX_DISCRETE_WRITE_COUNT = 0x07B0; // 1968
|
||||
|
||||
/// <summary>
|
||||
/// The maximum allowed read count for registers specified by the Modbus TCP protocol.
|
||||
/// The maximum allowed read count for registers specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
public const ushort MAX_REGISTER_READ_COUNT = 0x007D; // 125
|
||||
|
||||
/// <summary>
|
||||
/// The maximum allowed write count for registers specified by the Modbus TCP protocol.
|
||||
/// The maximum allowed write count for registers specified by the Modbus SerialLine protocol.
|
||||
/// </summary>
|
||||
public const ushort MAX_REGISTER_WRITE_COUNT = 0x007B; // 123
|
||||
|
||||
@@ -74,9 +81,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeReadCoils(byte unitId, ushort startAddress, ushort count)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
if (count < MIN_READ_COUNT || MAX_DISCRETE_READ_COUNT < count)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
@@ -137,9 +141,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeReadDiscreteInputs(byte unitId, ushort startAddress, ushort count)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
if (count < MIN_READ_COUNT || MAX_DISCRETE_READ_COUNT < count)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
@@ -200,9 +201,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeReadHoldingRegisters(byte unitId, ushort startAddress, ushort count)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
if (count < MIN_READ_COUNT || MAX_REGISTER_READ_COUNT < count)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
@@ -260,9 +258,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeReadInputRegisters(byte unitId, ushort startAddress, ushort count)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
if (count < MIN_READ_COUNT || MAX_REGISTER_READ_COUNT < count)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
@@ -320,9 +315,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeReadDeviceIdentification(byte unitId, ModbusDeviceIdentificationCategory category, ModbusDeviceIdentificationObject objectId)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
if (!Enum.IsDefined(typeof(ModbusDeviceIdentificationCategory), category))
|
||||
throw new ArgumentOutOfRangeException(nameof(category));
|
||||
|
||||
@@ -387,9 +379,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeWriteSingleCoil(byte unitId, Coil coil)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(coil);
|
||||
#else
|
||||
@@ -434,9 +423,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeWriteSingleHoldingRegister(byte unitId, HoldingRegister register)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(register);
|
||||
#else
|
||||
@@ -481,9 +467,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeWriteMultipleCoils(byte unitId, IReadOnlyList<Coil> coils)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(coils);
|
||||
#else
|
||||
@@ -555,9 +538,6 @@ namespace AMWD.Protocols.Modbus.Common.Protocols
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<byte> SerializeWriteMultipleHoldingRegisters(byte unitId, IReadOnlyList<HoldingRegister> registers)
|
||||
{
|
||||
if (unitId < MIN_UNIT_ID)
|
||||
throw new ArgumentOutOfRangeException(nameof(unitId));
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(registers);
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user