Interface IModbusBusClient
Interface for a Modbus bus client.
Assembly: Meadow.Contracts.dll
View Source
public interface IModbusBusClient
Properties
IsConnected
Gets a value indicating whether the client is connected.
View Source
bool IsConnected { get; }
Methods
Connect()
Asynchronously connects the client.
View Source
Task Connect()
Returns
System.Threading.Tasks.Task: A System.Threading.Tasks.Task representing the asynchronous operation.
Disconnect()
Disconnects the client.
View Source
void Disconnect()
WriteHoldingRegister(byte, ushort, ushort, bool)
Writes a single value to the given register on a device
View Source
Task WriteHoldingRegister(byte modbusAddress, ushort register, ushort value, bool addressIsLogical = false)
Returns
System.Threading.Tasks.Task
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte | modbusAddress | |
System.UInt16 | register | |
System.UInt16 | value | |
System.Boolean | addressIsLogical | If 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
Task WriteHoldingRegisters(byte modbusAddress, ushort startRegister, IEnumerable<ushort> values, bool addressIsLogical = false)
Returns
System.Threading.Tasks.Task
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte | modbusAddress | The target device modbus address |
System.UInt16 | startRegister | The first register to begin writing |
System.Collections.Generic.IEnumerable<System.UInt16> | values | The registers (16-bit values) to write |
System.Boolean | addressIsLogical | If 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
Task<ushort[]> ReadHoldingRegisters(byte modbusAddress, ushort startRegister, int registerCount, bool addressIsLogical = false)
Returns
System.Threading.Tasks.Task<System.UInt16[]>
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte | modbusAddress | |
System.UInt16 | startRegister | |
System.Int32 | registerCount | |
System.Boolean | addressIsLogical | If 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
Task<float[]> ReadHoldingRegistersFloat(byte modbusAddress, ushort startRegister, int floatCount)
Returns
System.Threading.Tasks.Task<System.Single[]>
Parameters
| Type | Name |
|---|---|
System.Byte | modbusAddress |
System.UInt16 | startRegister |
System.Int32 | floatCount |
WriteCoil(byte, ushort, bool)
Writes a coil value to the given register on a device.
View Source
Task WriteCoil(byte modbusAddress, ushort register, bool value)
Returns
System.Threading.Tasks.Task: A System.Threading.Tasks.Task representing the asynchronous operation.
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte | modbusAddress | The Modbus address of the device. |
System.UInt16 | register | The register to write to. |
System.Boolean | value | The value to write. |
WriteMultipleCoils(byte, ushort, IEnumerable<bool>)
Writes multiple coil values to the given registers on a device.
View Source
Task WriteMultipleCoils(byte modbusAddress, ushort startRegister, IEnumerable<bool> values)
Returns
System.Threading.Tasks.Task: A System.Threading.Tasks.Task representing the asynchronous operation.
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte | modbusAddress | The Modbus address of the device. |
System.UInt16 | startRegister | The first register to begin writing. |
System.Collections.Generic.IEnumerable<System.Boolean> | values | The coil values to write. |
ReadCoils(byte, ushort, int)
Reads the requested number of coils from a device.
View Source
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
| Type | Name | Description |
|---|---|---|
System.Byte | modbusAddress | The Modbus address of the device. |
System.UInt16 | startCoil | The first coil to begin reading. |
System.Int32 | coilCount | The number of coils to read. |
Events
Disconnected
Event that is raised when the client is disconnected.
View Source
event EventHandler Disconnected
Event Type
System.EventHandler
Connected
Event that is raised when the client is connected.
View Source
event EventHandler Connected
Event Type
System.EventHandler