Class ModbusServer
Modbus server implementation that listens for Modbus requests and handles them.
public class ModbusServer : Port
- Inheritance
-
ModbusServer
- Inherited Members
Constructors
ModbusServer(ModbusDevice, SerialPort, SerialMode)
Initializes a new instance of the ModbusServer class with the specified Modbus device and serial port.
public ModbusServer(ModbusDevice device, SerialPort port, SerialMode mode = SerialMode.RS485)
Parameters
device
ModbusDeviceThe Modbus device.
port
SerialPortThe serial port.
mode
SerialModeThe mode of serial port, default is RS485.
ModbusServer(ModbusDevice, string, int, Parity, int, StopBits, SerialMode)
Initializes a new instance of the ModbusServer class with the specified Modbus device and communication parameters.
public ModbusServer(ModbusDevice device, string portName, int baudRate = 9600, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One, SerialMode mode = SerialMode.RS485)
Parameters
device
ModbusDeviceThe Modbus device.
portName
stringThe name of the serial port.
baudRate
intThe baud rate.
parity
ParityThe parity.
dataBits
intThe number of data bits.
stopBits
StopBitsThe stop bits.
mode
SerialModeThe mode of serial port, default is RS485.
Methods
DataReceived(int)
Called when data is received on the serial port.
protected override void DataReceived(int bytesToRead)
Parameters
bytesToRead
intThe number of bytes to read from the serial port.
StartListening()
Starts listening for Modbus requests on the server.
public void StartListening()