SerialDevice SerialDevice SerialDevice SerialDevice SerialDevice Class


Represents a serial port. The object provides methods and properties that an app can use to find the port (in the system).

public : sealed class SerialDevice : IClosable
struct winrt::Windows::Devices::SerialCommunication::SerialDevice : IClosable
public sealed class SerialDevice : IDisposable
Public NotInheritable Class SerialDevice Implements IDisposable
// This class does not provide a public constructor.

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


The serial device capability, <DeviceCapability>, is required to use the SerialDevice class. For more info, see Windows.Devices.SerialCommunication.

Create a SerialDevice object

  1. Get this information about the serial port.+ The COM port name that represents the serial port, such as "COM1". In Device Manager, open Ports (COM & LPT), the device node string indicates the port number.
  • If you are using a Serial-to-USB converter, the virtual COM port name such as "COM1" or the vendor and product identifiers of the converter. You can derive the identifiers from the Hardware Ids property in Device Manager. For example, if Hardware Id is "USB\VID_045E&PID_078E", vendor ID is "0x045E" and product Id is "0x078E".
  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 instance path. For example, PCI#VEN_9710&DEV_9835&SUBSYS_00011000&REV_01\5&338FDA70&0&20F0#CHILD0000.
  5. Call FromIdAsync by passing the device instance string and get the SerialDevice object.

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.

Release the SerialDevice object

After you are finished using the SerialDevice object, release it.

C++ apps must release the reference by using the delete keyword. C#/VB apps must call the SerialDevice.Dispose method. JavaScript apps must call SerialDevice.Close.


BaudRate BaudRate BaudRate BaudRate BaudRate

Gets or sets the baud rate.

BreakSignalState BreakSignalState BreakSignalState BreakSignalState BreakSignalState

Gets or sets the break signal state.

BytesReceived BytesReceived BytesReceived BytesReceived BytesReceived

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

CarrierDetectState CarrierDetectState CarrierDetectState CarrierDetectState CarrierDetectState

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

ClearToSendState ClearToSendState ClearToSendState ClearToSendState ClearToSendState

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

DataBits DataBits DataBits DataBits DataBits

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

DataSetReadyState DataSetReadyState DataSetReadyState DataSetReadyState DataSetReadyState

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

Handshake Handshake Handshake Handshake Handshake

Gets or sets the handshaking protocol for flow control.

InputStream InputStream InputStream InputStream InputStream

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

IsDataTerminalReadyEnabled IsDataTerminalReadyEnabled IsDataTerminalReadyEnabled IsDataTerminalReadyEnabled IsDataTerminalReadyEnabled

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

IsRequestToSendEnabled IsRequestToSendEnabled IsRequestToSendEnabled IsRequestToSendEnabled IsRequestToSendEnabled

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

OutputStream OutputStream OutputStream OutputStream OutputStream

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

Parity Parity Parity Parity Parity

Gets or sets the parity bit for error-checking.

PortName PortName PortName PortName PortName

Gets the port name for serial communications.

ReadTimeout ReadTimeout ReadTimeout ReadTimeout ReadTimeout

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

StopBits StopBits StopBits StopBits StopBits

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

UsbProductId UsbProductId UsbProductId UsbProductId UsbProductId

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

UsbVendorId UsbVendorId UsbVendorId UsbVendorId UsbVendorId

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.

WriteTimeout WriteTimeout WriteTimeout WriteTimeout WriteTimeout

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


Close() Close() Close() Close() Close()

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

Dispose() Dispose() Dispose() Dispose() Dispose()

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

FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String)

Starts an asynchronous operation that creates a SerialDevice object.

GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()

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.

GetDeviceSelector(String) GetDeviceSelector(String) GetDeviceSelector(String) GetDeviceSelector(String) GetDeviceSelector(String)

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) GetDeviceSelectorFromUsbVidPid(UInt16, UInt16) GetDeviceSelectorFromUsbVidPid(UInt16, UInt16) GetDeviceSelectorFromUsbVidPid(UInt16, UInt16) 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 it's VID and PID.


ErrorReceived ErrorReceived ErrorReceived ErrorReceived ErrorReceived

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

PinChanged PinChanged PinChanged PinChanged PinChanged

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

See also