Table of Contents

Class ModbusMasterModuleBase

Namespace
Loehnert.Lisrt.Communication.Modbus
Assembly
Loehnert.Lisrt.Communication.Modbus.dll

Represents a Modbus master module base which connects to a slave (server).

public abstract class ModbusMasterModuleBase : CompositeModule, ICompositeModule, ILisrtModule, IModbusMaster, IInitializable, INotifyPropertyChangedEx, INotifyPropertyChanged
Inheritance
PropertyChangedBase
ModbusMasterModuleBase
Implements
INotifyPropertyChangedEx
Derived
Inherited Members
PropertyChangedBase.Refresh()
PropertyChangedBase.IsNotifying
PropertyChangedBase.PropertyChanged

Properties

CommunicationLogIsEnabled

Gets or sets a value indicating whether the communication log is enabled.

[Configuration(false, Description = "Enables the LisRT communication log")]
public bool CommunicationLogIsEnabled { get; set; }

Property Value

bool

InitializationState

Gets or sets a value indicating whether the object is initialized.

public InitializationState InitializationState { get; protected set; }

Property Value

InitializationState

Logger

Gets the logger.

protected ILogger Logger { get; }

Property Value

ILogger

TimeoutInMS

Gets or sets the timeout in milliseconds. Default is 1000ms.

[Configuration(1000, Unit = "ms")]
public int TimeoutInMS { get; set; }

Property Value

int

Methods

ExecuteCustomMessage<TResponse>(ICustomMessage)

Writes and reads a custom message (FC FunctionCode).

public TResponse ExecuteCustomMessage<TResponse>(ICustomMessage request) where TResponse : ICustomMessage, new()

Parameters

request ICustomMessage

A custom message request.

Returns

TResponse

The response.

Type Parameters

TResponse

The type of the response.

Exit()

De-initializes the object.

public abstract void Exit()

Initialize()

Initializes the object.

public abstract void Initialize()

ReadCoils(byte, ushort, ushort)

Reads coils status (FC 01).

public virtual IEnumerable<bool> ReadCoils(byte slaveAddress, ushort startAddress, ushort quantity)

Parameters

slaveAddress byte

Address of device to read values from.

startAddress ushort

Address to begin reading.

quantity ushort

Number of coils to read.

Returns

IEnumerable<bool>

Coils status.

ReadDiscreteInputs(byte, ushort, ushort)

Reads discrete inputs (FC 02).

public virtual IEnumerable<bool> ReadDiscreteInputs(byte slaveAddress, ushort startAddress, ushort quantity)

Parameters

slaveAddress byte

Address of device to read values from.

startAddress ushort

Address to begin reading.

quantity ushort

Number of inputs to read.

Returns

IEnumerable<bool>

Inputs status.

ReadHoldingRegisters(byte, ushort, ushort)

Reads the contents of a contiguous block of holding registers (FC 03).

public virtual IEnumerable<ushort> ReadHoldingRegisters(byte slaveAddress, ushort startAddress, ushort quantity)

Parameters

slaveAddress byte

Address of device to read values from.

startAddress ushort

Address to begin reading.

quantity ushort

Number of inputs to read.

Returns

IEnumerable<ushort>

Holding register status.

ReadInputRegisters(byte, ushort, ushort)

Reads contiguous input registers (FC 04).

public virtual IEnumerable<ushort> ReadInputRegisters(byte slaveAddress, ushort startAddress, ushort quantity)

Parameters

slaveAddress byte

Address of device to read values from.

startAddress ushort

Address to begin reading.

quantity ushort

Number of inputs to read.

Returns

IEnumerable<ushort>

Input register status.

ReadWriteHoldingRegisters(byte, ushort, ushort, ushort, IEnumerable<ushort>)

Performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read.

public virtual IEnumerable<ushort> ReadWriteHoldingRegisters(byte slaveAddress, ushort readStartingAddress, ushort readQuantity, ushort writeStartingAddress, IEnumerable<ushort> writeValues)

Parameters

slaveAddress byte

Address of device to read values from.

readStartingAddress ushort

Address to begin reading.

readQuantity ushort

Number of inputs to read.

writeStartingAddress ushort

Address to begin writing.

writeValues IEnumerable<ushort>

Values to write.

Returns

IEnumerable<ushort>

Read holding register status.

WriteCoil(byte, ushort, bool)

Writes single coil status (FC 05).

public virtual void WriteCoil(byte slaveAddress, ushort address, bool value)

Parameters

slaveAddress byte

Address of device to write values to.

address ushort

Address to begin writing.

value bool

Value to write.

WriteHoldingRegister(byte, ushort, ushort)

Writes a single holding register (FC 06).

public virtual void WriteHoldingRegister(byte slaveAddress, ushort address, ushort value)

Parameters

slaveAddress byte

Address of device to write values to.

address ushort

Address to begin writing.

value ushort

Values to write.

WriteMultipleCoils(byte, ushort, IEnumerable<bool>)

Writes multiple coils status (FC 15).

public virtual void WriteMultipleCoils(byte slaveAddress, ushort startAddress, IEnumerable<bool> values)

Parameters

slaveAddress byte

Address of device to read values from.

startAddress ushort

Address to begin writing.

values IEnumerable<bool>

Values to write.

WriteMultipleHoldingRegisters(byte, ushort, IEnumerable<ushort>)

Writes a block of contiguous registers (FC 16).

public virtual void WriteMultipleHoldingRegisters(byte slaveAddress, ushort startAddress, IEnumerable<ushort> values)

Parameters

slaveAddress byte

Address of device to read values from.

startAddress ushort

Address to begin writing.

values IEnumerable<ushort>

Values to write.