Class ModbusRtuSerialPort
- Namespace
- FluentModbus
- Assembly
- FluentModbus.dll
A wrapper for a SerialPort.
public class ModbusRtuSerialPort : IModbusRtuSerialPort
- Inheritance
-
ModbusRtuSerialPort
- Implements
Constructors
ModbusRtuSerialPort(SerialPort)
Initializes a new instances of the ModbusRtuSerialPort class.
public ModbusRtuSerialPort(SerialPort serialPort)
Parameters
serialPortSerialPortThe serial port to wrap.
Properties
IsOpen
Gets a value indicating the open or closed status of the ModbusRtuSerialPort object.
public bool IsOpen { get; }
Property Value
PortName
Gets the port for communications.
public string PortName { get; }
Property Value
Methods
Close()
Closes the port connection, sets the IsOpen property to false, and disposes of the internal Stream object.
public void Close()
Open()
Opens a new serial port connection.
public void Open()
Read(byte[], int, int)
Reads from the SerialPort input buffer.
public int Read(byte[] buffer, int offset, int count)
Parameters
bufferbyte[]The byte array to write the input to.
offsetintThe offset in
bufferat which to write the bytes.countintThe maximum number of bytes to read. Fewer bytes are read if
countis greater than the number of bytes in the input buffer.
Returns
- int
The number of bytes read.
ReadAsync(byte[], int, int, CancellationToken)
Asynchronously reads from the SerialPort input buffer.
public Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken token)
Parameters
bufferbyte[]The byte array to write the input to.
offsetintThe offset in
bufferat which to write the bytes.countintThe maximum number of bytes to read. Fewer bytes are read if
countis greater than the number of bytes in the input buffer.tokenCancellationTokenA token to cancel the current operation.
Returns
Write(byte[], int, int)
Writes data to the serial port output buffer.
public void Write(byte[] buffer, int offset, int count)
Parameters
bufferbyte[]The byte array that contains the data to write to the port.
offsetintThe zero-based byte offset in the
bufferparameter at which to begin copying bytes to the port.countintThe number of bytes to write.
WriteAsync(byte[], int, int, CancellationToken)
Asynchronously writes data to the serial port output buffer.
public Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
Parameters
bufferbyte[]The byte array that contains the data to write to the port.
offsetintThe zero-based byte offset in the
bufferparameter at which to begin copying bytes to the port.countintThe number of bytes to write.
tokenCancellationTokenA token to cancel the current operation.