Class ModbusMasterModuleBase
Represents a Modbus master module base which connects to a slave (server).
Inheritance
Implements
Inherited Members
Namespace: Loehnert.Lisrt.Communication.Modbus
Assembly: Loehnert.Lisrt.Communication.Modbus.dll
Syntax
public abstract class ModbusMasterModuleBase : CompositeModule, ICompositeModule, ILisrtModule, IModbusMaster, IInitializable, INotifyPropertyChangedEx, INotifyPropertyChanged
Properties
CommunicationLogIsEnabled
Gets or sets a value indicating whether the communication log is enabled.
Declaration
[Configuration(false, Description = "Enables the LisRT communication log")]
public bool CommunicationLogIsEnabled { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
InitializationState
Gets or sets a value indicating whether the object is initialized.
Declaration
public InitializationState InitializationState { get; protected set; }
Property Value
Type | Description |
---|---|
InitializationState |
Logger
Gets the logger.
Declaration
protected ILogger Logger { get; }
Property Value
Type | Description |
---|---|
ILogger |
TimeoutInMS
Gets or sets the timeout in milliseconds. Default is 1000ms.
Declaration
[Configuration(1000, Unit = "ms")]
public int TimeoutInMS { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
ExecuteCustomMessage<TResponse>(ICustomMessage)
Writes and reads a custom message (FC FunctionCode).
Declaration
public TResponse ExecuteCustomMessage<TResponse>(ICustomMessage request)
where TResponse : ICustomMessage, new()
Parameters
Type | Name | Description |
---|---|---|
ICustomMessage | request | A custom message request. |
Returns
Type | Description |
---|---|
TResponse | The response. |
Type Parameters
Name | Description |
---|---|
TResponse | The type of the response. |
Exit()
De-initializes the object.
Declaration
public abstract void Exit()
Initialize()
Initializes the object.
Declaration
public abstract void Initialize()
ReadCoils(Byte, UInt16, UInt16)
Reads coils status (FC 01).
Declaration
public virtual IEnumerable<bool> ReadCoils(byte slaveAddress, ushort startAddress, ushort quantity)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | startAddress | Address to begin reading. |
System.UInt16 | quantity | Number of coils to read. |
Returns
Type | Description |
---|---|
IEnumerable<Boolean> | Coils status. |
ReadDiscreteInputs(Byte, UInt16, UInt16)
Reads discrete inputs (FC 02).
Declaration
public virtual IEnumerable<bool> ReadDiscreteInputs(byte slaveAddress, ushort startAddress, ushort quantity)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | startAddress | Address to begin reading. |
System.UInt16 | quantity | Number of inputs to read. |
Returns
Type | Description |
---|---|
IEnumerable<Boolean> | Inputs status. |
ReadHoldingRegisters(Byte, UInt16, UInt16)
Reads the contents of a contiguous block of holding registers (FC 03).
Declaration
public virtual IEnumerable<ushort> ReadHoldingRegisters(byte slaveAddress, ushort startAddress, ushort quantity)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | startAddress | Address to begin reading. |
System.UInt16 | quantity | Number of inputs to read. |
Returns
Type | Description |
---|---|
IEnumerable<System.UInt16> | Holding register status. |
ReadInputRegisters(Byte, UInt16, UInt16)
Reads contiguous input registers (FC 04).
Declaration
public virtual IEnumerable<ushort> ReadInputRegisters(byte slaveAddress, ushort startAddress, ushort quantity)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | startAddress | Address to begin reading. |
System.UInt16 | quantity | Number of inputs to read. |
Returns
Type | Description |
---|---|
IEnumerable<System.UInt16> | Input register status. |
ReadWriteHoldingRegisters(Byte, UInt16, UInt16, UInt16, IEnumerable<UInt16>)
Performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read.
Declaration
public virtual IEnumerable<ushort> ReadWriteHoldingRegisters(byte slaveAddress, ushort readStartingAddress, ushort readQuantity, ushort writeStartingAddress, IEnumerable<ushort> writeValues)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | readStartingAddress | Address to begin reading. |
System.UInt16 | readQuantity | Number of inputs to read. |
System.UInt16 | writeStartingAddress | Address to begin writing. |
IEnumerable<System.UInt16> | writeValues | Values to write. |
Returns
Type | Description |
---|---|
IEnumerable<System.UInt16> | Read holding register status. |
WriteCoil(Byte, UInt16, Boolean)
Writes single coil status (FC 05).
Declaration
public virtual void WriteCoil(byte slaveAddress, ushort address, bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to write values to. |
System.UInt16 | address | Address to begin writing. |
Boolean | value | Value to write. |
WriteHoldingRegister(Byte, UInt16, UInt16)
Writes a single holding register (FC 06).
Declaration
public virtual void WriteHoldingRegister(byte slaveAddress, ushort address, ushort value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to write values to. |
System.UInt16 | address | Address to begin writing. |
System.UInt16 | value | Values to write. |
WriteMultipleCoils(Byte, UInt16, IEnumerable<Boolean>)
Writes multiple coils status (FC 15).
Declaration
public virtual void WriteMultipleCoils(byte slaveAddress, ushort startAddress, IEnumerable<bool> values)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | startAddress | Address to begin writing. |
IEnumerable<Boolean> | values | Values to write. |
WriteMultipleHoldingRegisters(Byte, UInt16, IEnumerable<UInt16>)
Writes a block of contiguous registers (FC 16).
Declaration
public virtual void WriteMultipleHoldingRegisters(byte slaveAddress, ushort startAddress, IEnumerable<ushort> values)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | slaveAddress | Address of device to read values from. |
System.UInt16 | startAddress | Address to begin writing. |
IEnumerable<System.UInt16> | values | Values to write. |