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
serialPort
SerialPortThe 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
buffer
byte[]The byte array to write the input to.
offset
intThe offset in
buffer
at which to write the bytes.count
intThe maximum number of bytes to read. Fewer bytes are read if
count
is 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
buffer
byte[]The byte array to write the input to.
offset
intThe offset in
buffer
at which to write the bytes.count
intThe maximum number of bytes to read. Fewer bytes are read if
count
is greater than the number of bytes in the input buffer.token
CancellationTokenA 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
buffer
byte[]The byte array that contains the data to write to the port.
offset
intThe zero-based byte offset in the
buffer
parameter at which to begin copying bytes to the port.count
intThe 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
buffer
byte[]The byte array that contains the data to write to the port.
offset
intThe zero-based byte offset in the
buffer
parameter at which to begin copying bytes to the port.count
intThe number of bytes to write.
token
CancellationTokenA token to cancel the current operation.