SerialDevice Class


Represents a serial port. The object provides methods and properties that an app can use to find and interact with serials ports on the system.

public ref class SerialDevice sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SerialDevice final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class SerialDevice : System.IDisposable
Public NotInheritable Class SerialDevice
Implements IDisposable
Object IInspectable SerialDevice

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)


using System;
using Windows.Devices.Enumeration;
using Windows.Devices.SerialCommunication;
using Windows.Storage.Streams;


DeviceInformationCollection serialDeviceInfos = await DeviceInformation.FindAllAsync(SerialDevice.GetDeviceSelector());

foreach (DeviceInformation serialDeviceInfo in serialDeviceInfos)
        SerialDevice serialDevice = await SerialDevice.FromIdAsync(serialDeviceInfo.Id);

        if (serialDevice != null)
            // Found a valid serial device.

            // Reading a byte from the serial device.
            DataReader dr = new DataReader(serialDevice.InputStream);
            int readByte = dr.ReadByte();

            // Writing a byte to the serial device.
            DataWriter dw = new DataWriter(serialDevice.OutputStream);
    catch (Exception)
        // Couldn't instantiate the device


The serial device capability, serialCommunication, is required to use the SerialDevice class. For more information, see Windows.Devices.SerialCommunication.

Create a SerialDevice object

  1. Generate an Advanced Query Syntax (AQS) string that contains search criteria for finding the device in the enumerated device collection. If you have the vendor and product identifiers, call GetDeviceSelectorFromUsbVidPid.
  2. Pass the retrieved string to FindAllAsync. The call retrieves a DeviceInformationCollection object.
  3. Loop through the collection. Each iteration gets a DeviceInformation object.
  4. Get the DeviceInformation.Id property value. The string value is the device interface path. (e.g \\?\usb#vid_03eb&pid_2157&mi_01#7&1435ec7f&0&0001#{86e0d1e0-8089-11d0-9ce4-08003e301f73}).
  5. Call FromIdAsync by passing the device interface string and get the SerialDevice object. If this throws an exception or returns null, it is likely:
    • The device interface path is invalid
    • The device interface path does not respresent a serial device
    • Application is missing the serialCommunication capability
    • The serial device is inaccessible. (see Windows.Devices.SerialCommunication)

Read and write data

You can then use the SerialDevice object to read from or write to the serial port by using the Windows.Storage.Streams namespace.

  1. Obtain a reference to the input stream by getting the SerialDevice.InputStream property.
  2. Create a DataReader object by specifying the input stream in the DataReader constructor.
  3. Obtain a reference to the output stream by getting the SerialDevice.OutputStream property.
  4. Create a DataWriter object by specifying the output stream in the DataWriter constructor.



Gets or sets the baud rate.


Gets or sets the break signal state.


Represents the number of bytes received by the last read operation of the input stream.


Gets the state of the Carrier Detect (CD) line.


Gets the state of the Clear-to-Send (CTS) line.


The number of data bits in each character value that is transmitted or received, and does not include parity bits or stop bits.


Gets the state of the Data Set Ready (DSR) signal.


Gets or sets the handshaking protocol for flow control.


Input stream that contains the data received on the serial port.


Gets or sets a value that enables the Data Terminal Ready (DTR) signal.


Gets or sets a value that enables the Request to Send (RTS) signal.


Gets an output stream to which the app can write data to transmit through the serial port.


Gets or sets the parity bit for error-checking.


Gets the port name for serial communications.


Gets or sets the time-out value for a read operation.


Gets or sets the standard number of stop bits per byte.


Gets the idProduct field of the USB device descriptor. This value indicates the device-specific product identifier and is assigned by the manufacturer.


Gets the idVendor field of the USB device descriptor. The value indicates the vendor identifier for the device as assigned by the USB specification committee.


Gets or sets the time-out value for a write operation.



Releases the reference to the SerialDevice object that was previously obtained by calling FromIdAsync.


Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.


Starts an asynchronous operation that creates a SerialDevice object.


Gets an Advanced Query Syntax (AQS) string that the app can pass to DeviceInformation.FindAllAsync in order to find all serial devices on the system.


Gets an Advanced Query Syntax (AQS) string that the app can pass to DeviceInformation.FindAllAsync in order to find a serial device by specifying its port name.

GetDeviceSelectorFromUsbVidPid(UInt16, UInt16)

Gets an Advanced Query Syntax (AQS) string that the app can pass to DeviceInformation.FindAllAsync in order to find a specific Serial-to-USB device by specifying its VID and PID.



Event handler that is invoked when error occurs on the serial port.


Event handler that is invoked when the state of a signal or line changes on the serial port.

Applies to

See also