Characteristic | Locus |
---|---|
Inherited Members | IDisposable.Dispose() |
Namespace | Meadow.Hardware |
Assembly | Meadow.Contracts.dll |
Syntax
public interface ISerialPort : IDisposable
Properties
BaudRate
Gets or sets the serial baud rate.
Declaration
int BaudRate { get; set; }
Property Value
Type | Description |
---|---|
int |
BytesToRead
Gets the number of bytes of data in the receive buffer.
Declaration
int BytesToRead { get; }
Property Value
Type | Description |
---|---|
int |
DataBits
Gets or sets the standard length of data bits per byte.
Declaration
int DataBits { get; set; }
Property Value
Type | Description |
---|---|
int |
IsOpen
Gets a value indicating the open or closed status of the SerialPort object.
Declaration
bool IsOpen { get; }
Property Value
Type | Description |
---|---|
bool |
Parity
Gets or sets the parity-checking protocol.
Declaration
Parity Parity { get; set; }
Property Value
Type | Description |
---|---|
Parity |
PortName
Gets the port name used for communications.
Declaration
string PortName { get; }
Property Value
Type | Description |
---|---|
string |
ReadTimeout
The time required for a time-out to occur when a read operation does not finish.
Declaration
TimeSpan ReadTimeout { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Remarks
The time-out can be set to any value greater than zero, or set to <= 0, in which case no time-out occurs. InfiniteTimeout is the default.
ReceiveBufferSize
The size, in bytes, of the receive buffer that caches message data from the attached peripheral.
Declaration
int ReceiveBufferSize { get; }
Property Value
Type | Description |
---|---|
int |
StopBits
Gets or sets the standard number of stopbits per byte.
Declaration
StopBits StopBits { get; set; }
Property Value
Type | Description |
---|---|
StopBits |
WriteTimeout
The time required for a time-out to occur when a write operation does not finish.
Declaration
TimeSpan WriteTimeout { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Remarks
The time-out can be set to any value greater than zero, or set to <= 0, in which case no time-out occurs. InfiniteTimeout is the default.
Methods
ClearReceiveBuffer()
Discards data from the serial driver's receive buffer.
Declaration
void ClearReceiveBuffer()
Close()
Closes the port connection and sets the IsOpen property to false.
Declaration
void Close()
Open()
Opens a new serial port connection.
Declaration
void Open()
Peek()
Returns the next available byte in the input buffer but does not consume it.
Declaration
int Peek()
Returns
Type | Description |
---|---|
int | The byte, cast to an Int32, or -1 if there is no data available in the input buffer. |
Read(byte[], int, int)
Reads a number of bytes from the SerialPort input buffer and writes those bytes into a byte array at the specified offset.
Declaration
int Read(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The byte array to write the input to. |
int | offset | The offset in buffer at which to write the bytes. |
int | count | The maximum number of bytes to read. Fewer bytes are read if count is greater than the number of bytes in the input buffer. |
Returns
Type | Description |
---|---|
int | The number of bytes read. |
ReadAll()
Reads all currently available bytes from the SerialPort
Declaration
byte[] ReadAll()
Returns
Type | Description |
---|---|
byte[] |
ReadByte()
Synchronously reads one byte from the SerialPort input buffer.
Declaration
int ReadByte()
Returns
Type | Description |
---|---|
int | The byte, cast to an Int32, or -1 if the end of the stream has been read. |
ToString()
Returns a friendly string descriptor of the SerialPort
Declaration
string? ToString()
Returns
Type | Description |
---|---|
string |
Write(byte[])
Writes data to the serial port.
Declaration
int Write(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer |
Returns
Type | Description |
---|---|
int |
Write(byte[], int, int)
Writes a specified number of bytes to the serial port using data from a buffer.
Declaration
int Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The byte array that contains the data to write to the port. |
int | offset | The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port. |
int | count | The number of bytes to write. |
Returns
Type | Description |
---|---|
int |
Events
BufferOverrun
Indicates that the internal data buffer has overrun and data has been lost.
Declaration
event EventHandler BufferOverrun
Event Type
Type | Description |
---|---|
EventHandler |
DataReceived
Indicates that data has been received through a port represented by the SerialPort object.
Declaration
event SerialDataReceivedEventHandler DataReceived
Event Type
Type | Description |
---|---|
SerialDataReceivedEventHandler |