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
- 
      
      PropertyChangedBaseModbusMasterModuleBase
- Implements
- 
      
      
      
      
      INotifyPropertyChangedEx
- Derived
- Inherited Members
- 
    
    
    
    
    
    
    
    PropertyChangedBase.Refresh()PropertyChangedBase.IsNotifyingPropertyChangedBase.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
InitializationState
Gets or sets a value indicating whether the object is initialized.
public InitializationState InitializationState { get; protected set; }Property Value
Logger
Gets the logger.
protected ILogger Logger { get; }Property Value
TimeoutInMS
Gets or sets the timeout in milliseconds. Default is 1000ms.
[Configuration(1000, Unit = "ms")]
public int TimeoutInMS { get; set; }Property Value
Methods
ExecuteCustomMessage<TResponse>(ICustomMessage)
Writes and reads a custom message (FC FunctionCode).
public TResponse ExecuteCustomMessage<TResponse>(ICustomMessage request) where TResponse : ICustomMessage, new()Parameters
- requestICustomMessage
- 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
- slaveAddressbyte
- Address of device to read values from. 
- startAddressushort
- Address to begin reading. 
- quantityushort
- 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
- slaveAddressbyte
- Address of device to read values from. 
- startAddressushort
- Address to begin reading. 
- quantityushort
- 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
- slaveAddressbyte
- Address of device to read values from. 
- startAddressushort
- Address to begin reading. 
- quantityushort
- 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
- slaveAddressbyte
- Address of device to read values from. 
- startAddressushort
- Address to begin reading. 
- quantityushort
- 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
- slaveAddressbyte
- Address of device to read values from. 
- readStartingAddressushort
- Address to begin reading. 
- readQuantityushort
- Number of inputs to read. 
- writeStartingAddressushort
- Address to begin writing. 
- writeValuesIEnumerable<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
- slaveAddressbyte
- Address of device to write values to. 
- addressushort
- Address to begin writing. 
- valuebool
- 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
- slaveAddressbyte
- Address of device to write values to. 
- addressushort
- Address to begin writing. 
- valueushort
- 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
- slaveAddressbyte
- Address of device to read values from. 
- startAddressushort
- Address to begin writing. 
- valuesIEnumerable<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
- slaveAddressbyte
- Address of device to read values from. 
- startAddressushort
- Address to begin writing. 
- valuesIEnumerable<ushort>
- Values to write.