Class ModbusDevice
Represents a Modbus device.
public abstract class ModbusDevice
- Inheritance
-
ModbusDevice
Constructors
ModbusDevice(byte)
Initializes a new instance of the ModbusDevice class with the specified device ID.
public ModbusDevice(byte id = 1)
Parameters
id
byteThe device ID. Default is the minimum device ID.
Properties
DeviceId
Gets or sets the device ID.
public virtual byte DeviceId { get; protected set; }
Property Value
Methods
BeginRead()
Method called before reading from the Modbus device.
protected virtual void BeginRead()
BeginWrite()
Method called before writing to the Modbus device.
protected virtual void BeginWrite()
EndRead()
Method called after reading from the Modbus device.
protected virtual void EndRead()
EndWrite()
Method called after writing to the Modbus device.
protected virtual void EndWrite()
TryReadCoil(ushort, out bool)
Tries to read a coil from the Modbus device at the specified address.
protected abstract bool TryReadCoil(ushort address, out bool value)
Parameters
address
ushortThe address of the coil.
value
boolWhen this method returns, contains the value of the coil if the read operation succeeds, or false if the read operation fails.
Returns
- bool
True if the read operation succeeds; otherwise, false.
TryReadDiscreteInput(ushort, out bool)
Tries to read a discrete input from the Modbus device at the specified address.
protected abstract bool TryReadDiscreteInput(ushort address, out bool value)
Parameters
address
ushortThe address of the discrete input.
value
boolWhen this method returns, contains the value of the discrete input if the read operation succeeds, or false if the read operation fails.
Returns
- bool
True if the read operation succeeds; otherwise, false.
TryReadHoldingRegister(ushort, out short)
Tries to read a holding register from the Modbus device at the specified address.
protected abstract bool TryReadHoldingRegister(ushort address, out short value)
Parameters
address
ushortThe address of the holding register.
value
shortWhen this method returns, contains the value of the holding register if the read operation succeeds, or zero if the read operation fails.
Returns
- bool
True if the read operation succeeds; otherwise, false.
TryReadInputRegister(ushort, out short)
Tries to read an input register from the Modbus device at the specified address.
protected abstract bool TryReadInputRegister(ushort address, out short value)
Parameters
address
ushortThe address of the input register.
value
shortWhen this method returns, contains the value of the input register if the read operation succeeds, or zero if the read operation fails.
Returns
- bool
True if the read operation succeeds; otherwise, false.
TryWriteCoil(ushort, bool)
Tries to write a coil to the Modbus device at the specified address.
protected abstract bool TryWriteCoil(ushort address, bool value)
Parameters
Returns
- bool
True if the write operation succeeds; otherwise, false.
TryWriteHoldingRegister(ushort, short)
Tries to write a holding register to the Modbus device at the specified address.
protected abstract bool TryWriteHoldingRegister(ushort address, short value)
Parameters
address
ushortThe address of the holding register.
value
shortThe value to write to the holding register.
Returns
- bool
True if the write operation succeeds; otherwise, false.