Class SerialDevice
Represents a serial port. The object provides methods and properties that an app can use to find the port (in the system).
Implements
Inherited Members
Namespace: Windows.Devices.SerialCommunication
Assembly: Windows.Devices.SerialCommunication.dll
Syntax
public sealed class SerialDevice : IDisposable
Properties
| Improve this Doc View SourceBaudRate
Gets or sets the baud rate.
Declaration
public uint BaudRate { get; set; }
Property Value
Type | Description |
---|---|
UInt32 | The baud rate of the serial port. |
Remarks
The property is set on the SerialDevice object that represents the serial port. The baud rate must be supported by the serial port.
BytesReceived
Represents the number of bytes received by the last read operation of the input stream.
Declaration
public uint BytesReceived { get; }
Property Value
Type | Description |
---|---|
UInt32 | The number of bytes received by the last read operation of the input stream. |
BytesToRead
Gets the number of bytes of data available in the input stream.
Declaration
public uint BytesToRead { get; }
Property Value
Type | Description |
---|---|
UInt32 | The number of bytes of data in the input stream. |
Remarks
This property is specific to nanoFramework. There is no equivalent one in the UWP API.
DataBits
The number of data bits in each character value that is transmitted or received, and does not include parity bits or stop bits.
Declaration
public ushort DataBits { get; set; }
Property Value
Type | Description |
---|---|
UInt16 | The number of data bits in each character value that is transmitted or received. |
Remarks
DataBits corresponds to the WordLength member of the SERIAL_LINE_CONTROL structure.
Handshake
Gets or sets the handshaking protocol for flow control.
Declaration
public SerialHandshake Handshake { get; set; }
Property Value
Type | Description |
---|---|
SerialHandshake | One of the values defined in SerialHandshake enumeration. |
InputStream
Input stream that contains the data received on the serial port.
Declaration
public IInputStream InputStream { get; }
Property Value
Type | Description |
---|---|
IInputStream | Input stream that contains the data received. |
Remarks
To access data received on the port, get the input stream from SerialDevice object, and then use the DataReader to read data.
Mode
Declaration
public SerialMode Mode { get; set; }
Property Value
Type | Description |
---|---|
SerialMode |
OutputStream
Gets an output stream to which the app can write data to transmit through the serial port.
Declaration
public IOutputStream OutputStream { get; }
Property Value
Type | Description |
---|---|
IOutputStream |
Remarks
To write data, first get the output stream from the SerialDevice object by using OutputStream property and then use the DataWriter object to write the actual buffer.
Parity
Gets or sets the parity bit for error-checking.
Declaration
public SerialParity Parity { get; set; }
Property Value
Type | Description |
---|---|
SerialParity | One of the values defined in SerialParity enumeration. |
Remarks
In serial communication, the parity bit is used as an error-checking procedure. In data transmission that uses parity checking, the bit format is 7 data bits-x-1 stop bit, where x is the parity bit. That bit indicates whether the number of 1s in the data byte is even or odd. The parity bit can be E (even), O (odd), M (mark), or S (space). Those values are defined in the SerialParity enumeration. For example, if the format is 7-E-1 and the data bits are 0001000, the parity bit is set to 1 to make sure there are even number of 1s.
PortName
Gets the port name for serial communications.
Declaration
public string PortName { get; }
Property Value
Type | Description |
---|---|
String | The communication port name. For example "COM1". |
ReadTimeout
Gets or sets the time-out value for a read operation.
Declaration
public TimeSpan ReadTimeout { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan | The span of time before a time-out occurs when a read operation does not finish. |
StopBits
Gets or sets the standard number of stop bits per byte.
Declaration
public SerialStopBitCount StopBits { get; set; }
Property Value
Type | Description |
---|---|
SerialStopBitCount | One of the values defined in the SerialStopBitCount enumeration. |
Remarks
In serial communication, a transmission begins with a start bit, followed by 8 bits of data, and ends with a stop bit. The purpose of the stop bit is to separate each unit of data or to indicate that no data is available for transmission.
WatchChar
Sets a character to watch for in the incoming data stream.
Declaration
public char WatchChar { set; }
Property Value
Type | Description |
---|---|
Char |
Remarks
This property is specific to nanoFramework. There is no equivalent in the UWP API.
When calling Load(UInt32) in the InputStream the operation will return immediately if this character is received in the incoming data stream. No matter if the requested quantity of bytes hasn't been read. Also if this character is received in the incoming data stream, the DataReceived event is fired with it's SerialData parameter set to WatchChar.
WriteTimeout
Gets or sets the time-out value for a write operation.
Declaration
public TimeSpan WriteTimeout { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan | The span of time before a time-out occurs when a write operation does not finish. |
Methods
| Improve this Doc View SourceDispose()
Declaration
public void Dispose()
Finalize()
Declaration
protected void Finalize()
FromId(String)
Creates a SerialDevice object.
Declaration
public static SerialDevice FromId(string deviceId)
Parameters
Type | Name | Description |
---|---|---|
String | deviceId | The device instance path of the device. To obtain that value, get the DeviceInformation.Id property value. |
Returns
Type | Description |
---|---|
SerialDevice | Returns an SerialDevice object. |
Remarks
This method is specific to nanoFramework. The equivalent method in the UWP API is: FromIdAsync.
GetDeviceSelector()
Gets all the available Serial devices available on the system.
Declaration
public static extern string GetDeviceSelector()
Returns
Type | Description |
---|---|
String | String containing all the serial devices available in the system. |
Remarks
This method is specific to nanoFramework. The equivalent method in the UWP API returns an Advanced Query Syntax (AQS) string.
Events
| Improve this Doc View SourceDataReceived
Indicates that data has been received through a SerialDevice object.
Declaration
public event SerialDataReceivedEventHandler DataReceived
Event Type
Type | Description |
---|---|
SerialDataReceivedEventHandler |
Remarks
This event is specific to nanoFramework. There is no equivalent method in the UWP API.
Data events can be caused by any of the items in the SerialData enumeration. Because the operating system determines whether to raise this event or not, not all parity errors may be reported. The DataReceived event is also raised if the WatchChar character is received, regardless of the number of bytes available in the InputStream. The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesReceived property or the available bytes property of the InputStream to determine how much data is available to be read from the InputStream.