Skip to main content

Interface IModbusBusClient

Interface for a Modbus bus client.

Assembly: Meadow.Contracts.dll​
View Source​
Declaration
public interface IModbusBusClient

Properties​

IsConnected​

Gets a value indicating whether the client is connected.

View Source​
Declaration
bool IsConnected { get; }

Methods​

Connect()​

Asynchronously connects the client.

View Source​
Declaration
Task Connect()
Returns​

System.Threading.Tasks.Task: A System.Threading.Tasks.Task representing the asynchronous operation.

Disconnect()​

Disconnects the client.

View Source​
Declaration
void Disconnect()

WriteHoldingRegister(byte, ushort, ushort, bool)​

Writes a single value to the given register on a device

View Source​
Declaration
Task WriteHoldingRegister(byte modbusAddress, ushort register, ushort value, bool addressIsLogical = false)
Returns​

System.Threading.Tasks.Task

Parameters​
TypeNameDescription
System.BytemodbusAddress
System.UInt16register
System.UInt16value
System.BooleanaddressIsLogicalIf the address is a Modbus logical address, 40001 will be subtracted to get the register address.

WriteHoldingRegisters(byte, ushort, IEnumerable<ushort>, bool)​

Writes multiple values to holding registers (modbus function 16)

View Source​
Declaration
Task WriteHoldingRegisters(byte modbusAddress, ushort startRegister, IEnumerable<ushort> values, bool addressIsLogical = false)
Returns​

System.Threading.Tasks.Task

Parameters​
TypeNameDescription
System.BytemodbusAddressThe target device modbus address
System.UInt16startRegisterThe first register to begin writing
System.Collections.Generic.IEnumerable<System.UInt16>valuesThe registers (16-bit values) to write
System.BooleanaddressIsLogicalIf the address is a Modbus logical address, 40001 will be subtracted to get the register address.

ReadHoldingRegisters(byte, ushort, int, bool)​

Reads the requested number of holding registers from a device

View Source​
Declaration
Task<ushort[]> ReadHoldingRegisters(byte modbusAddress, ushort startRegister, int registerCount, bool addressIsLogical = false)
Returns​

System.Threading.Tasks.Task<System.UInt16[]>

Parameters​
TypeNameDescription
System.BytemodbusAddress
System.UInt16startRegister
System.Int32registerCount
System.BooleanaddressIsLogicalIf the address is a Modbus logical address, 40001 will be subtracted to get the register address.

ReadHoldingRegistersFloat(byte, ushort, int)​

Reads the requested number of floats from the holding registers Each float is two sequential registers

View Source​
Declaration
Task<float[]> ReadHoldingRegistersFloat(byte modbusAddress, ushort startRegister, int floatCount)
Returns​

System.Threading.Tasks.Task<System.Single[]>

Parameters​
TypeName
System.BytemodbusAddress
System.UInt16startRegister
System.Int32floatCount

WriteCoil(byte, ushort, bool)​

Writes a coil value to the given register on a device.

View Source​
Declaration
Task WriteCoil(byte modbusAddress, ushort register, bool value)
Returns​

System.Threading.Tasks.Task: A System.Threading.Tasks.Task representing the asynchronous operation.

Parameters​
TypeNameDescription
System.BytemodbusAddressThe Modbus address of the device.
System.UInt16registerThe register to write to.
System.BooleanvalueThe value to write.

WriteMultipleCoils(byte, ushort, IEnumerable<bool>)​

Writes multiple coil values to the given registers on a device.

View Source​
Declaration
Task WriteMultipleCoils(byte modbusAddress, ushort startRegister, IEnumerable<bool> values)
Returns​

System.Threading.Tasks.Task: A System.Threading.Tasks.Task representing the asynchronous operation.

Parameters​
TypeNameDescription
System.BytemodbusAddressThe Modbus address of the device.
System.UInt16startRegisterThe first register to begin writing.
System.Collections.Generic.IEnumerable<System.Boolean>valuesThe coil values to write.

ReadCoils(byte, ushort, int)​

Reads the requested number of coils from a device.

View Source​
Declaration
Task<bool[]> ReadCoils(byte modbusAddress, ushort startCoil, int coilCount)
Returns​

System.Threading.Tasks.Task<System.Boolean[]>: An array of coil values read from the device.

Parameters​
TypeNameDescription
System.BytemodbusAddressThe Modbus address of the device.
System.UInt16startCoilThe first coil to begin reading.
System.Int32coilCountThe number of coils to read.

Events​

Disconnected​

Event that is raised when the client is disconnected.

View Source​
Declaration
event EventHandler Disconnected
Event Type​

System.EventHandler

Connected​

Event that is raised when the client is connected.

View Source​
Declaration
event EventHandler Connected
Event Type​

System.EventHandler