Characteristic | Locus |
---|---|
Namespace | Meadow.Hardware |
Assembly | Meadow.Core.NetStandard.dll |
Syntax
public interface ISerialPort
Properties
View SourceBaudRate
Gets or sets the serial baud rate.
Declaration
int BaudRate { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
BytesToRead
Gets the number of bytes of data in the receive buffer.
Declaration
int BytesToRead { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
DataBits
Gets or sets the standard length of data bits per byte.
Declaration
int DataBits { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsOpen
Gets a value indicating the open or closed status of the SerialPort object.
Declaration
bool IsOpen { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Parity
Gets or sets the parity-checking protocol.
Declaration
Parity Parity { get; }
Property Value
Type | Description |
---|---|
Parity |
PortName
Gets the port name used for communications.
Declaration
string PortName { get; }
Property Value
Type | Description |
---|---|
System.String |
ReadTimeout
The number of milliseconds before a time-out occurs when a read operation does not finish.
Declaration
int ReadTimeout { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
The time-out can be set to any value greater than zero, or set to InfiniteTimeout, 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 |
---|---|
System.Int32 |
StopBits
Gets or sets the standard number of stopbits per byte.
Declaration
StopBits StopBits { get; }
Property Value
Type | Description |
---|---|
StopBits |
Methods
View SourceClearReceiveBuffer()
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 by in the input buffer but does not consume it.
Declaration
int Peek()
Returns
Type | Description |
---|---|
System.Int32 | The byte, cast to an Int32, or -1 if there is no data available in the input buffer. |
Read(Byte[], Int32, Int32)
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 |
---|---|---|
System.Byte[] | buffer | The byte array to write the input to. |
System.Int32 | offset | The offset in buffer at which to write the bytes. |
System.Int32 | 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 |
---|---|
System.Int32 | The number of bytes read. |
ReadByte()
Synchronously reads one byte from the SerialPort input buffer.
Declaration
int ReadByte()
Returns
Type | Description |
---|---|
System.Int32 | The byte, cast to an Int32, or -1 if the end of the stream has been read. |
ReadToToken(Byte)
Reads bytes from the input buffer until a specified token is found
Declaration
byte[] ReadToToken(byte token)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | token | The token to search for |
Returns
Type | Description |
---|---|
System.Byte[] | All data in the buffer up to and including the specified token, if a toen exists, otherwise an empty array. |
ToString()
Declaration
string ToString()
Returns
Type | Description |
---|---|
System.String |
Write(Byte[])
Writes data to the serial port.
Declaration
int Write(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer |
Returns
Type | Description |
---|---|
System.Int32 |
Write(Byte[], Int32, Int32)
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 |
---|---|---|
System.Byte[] | buffer | The byte array that contains the data to write to the port. |
System.Int32 | offset | The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port. |
System.Int32 | count | The number of bytes to write. |
Returns
Type | Description |
---|---|
System.Int32 |
Events
View SourceDataReceived
Indicates that data has been received through a port represented by the SerialPort object.
Declaration
event SerialDataReceivedEventHandler DataReceived
Event Type
Type | Description |
---|---|
SerialDataReceivedEventHandler |