Implementation of the basic functionallity
This commit is contained in:
41
AMWD.Protocols.Modbus.Common/Models/HoldingRegister.cs
Normal file
41
AMWD.Protocols.Modbus.Common/Models/HoldingRegister.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace AMWD.Protocols.Modbus.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a holding register.
|
||||
/// </summary>
|
||||
public class HoldingRegister : ModbusObject
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override ModbusObjectType Type => ModbusObjectType.HoldingRegister;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the holding register.
|
||||
/// </summary>
|
||||
public ushort Value
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[] blob = [HighByte, LowByte];
|
||||
if (BitConverter.IsLittleEndian)
|
||||
Array.Reverse(blob);
|
||||
|
||||
return BitConverter.ToUInt16(blob, 0);
|
||||
}
|
||||
set
|
||||
{
|
||||
byte[] blob = BitConverter.GetBytes(value);
|
||||
if (BitConverter.IsLittleEndian)
|
||||
Array.Reverse(blob);
|
||||
|
||||
HighByte = blob[0];
|
||||
LowByte = blob[1];
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
=> $"Holding Register #{Address} | {Value} | HI: {HighByte:X2}, LO: {LowByte:X2}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user