Class ModbusLine
Several devices on one simulated line, as devices share an RS485 pair: every frame reaches all of them, the one it is addressed to answers, and each carries out a broadcast write.
public sealed class ModbusLine : IDisposable
- Inheritance
-
ModbusLine
- Implements
- Inherited Members
Examples
using var line = new ModbusLine();
line.Attach(meter);
using SerialPort port = line.Port(new SerialSettings(19_200, Parity.Even));
Remarks
Port(SerialSettings) makes a serial port with the line on its far end, which a ModbusClient polls exactly as it would the kernel's serial device. Nothing on such a port waits: the silences and the timeouts a real line takes are counted in the port's WaitedMicros.
Constructors
ModbusLine()
Makes a line with no devices on it.
public ModbusLine()
Properties
Count
How many devices are on the line.
public int Count { get; }
Property Value
Methods
Attach(ModbusServer)
Puts a device on the line. The line shares it, so the device still reads and changes.
public ModbusLine Attach(ModbusServer server)
Parameters
serverModbusServerThe device.
Returns
- ModbusLine
This line, to put another device on.
Dispose()
Releases this handle to the line. A port made from it keeps its own share.
public void Dispose()
Port(SerialSettings)
Makes a serial port with the line on its far end: every frame written reaches each device, and whatever they answer waits to be read. Devices put on the line later are on the port too.
public SerialPort Port(SerialSettings settings)
Parameters
settingsSerialSettingsThe speed and character format the line runs at.
Returns
- SerialPort
The port.
Exceptions
- PamojaException
The settings are not ones a port has.