Table of Contents

Class SerialPort

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll
NOTE
Experimental
The SerialPort interface of the Web Serial API provides access to a serial port on the host device.
[Value("SerialPort")]
public class SerialPort : EventTarget
Inheritance
SerialPort
Inherited Members

Remarks

Constructors

SerialPort()

public SerialPort()

Properties

Connected

NOTE
Experimental
The connected read-only property of the SerialPort interface returns a boolean value that indicates whether the port is logically connected to the device.
[Value("connected")]
public bool Connected { get; }

Property Value

bool

A boolean — true if the port is logically connected, and false if not.

Remarks

Onconnect

[Value("onconnect")]
public EventHandlerNonNull Onconnect { get; set; }

Property Value

EventHandlerNonNull

Ondisconnect

[Value("ondisconnect")]
public EventHandlerNonNull Ondisconnect { get; set; }

Property Value

EventHandlerNonNull

Readable

NOTE
Experimental
The readable read-only property of the SerialPort interface returns a ReadableStream for receiving data from the device connected to the port. Chunks read from this stream are instances of {{jsxref("Uint8Array")}}. This property is non-null as long as the port is open and has not encountered a fatal error.
[Value("readable")]
public ReadableStream Readable { get; }

Property Value

ReadableStream

A ReadableStream.

Remarks

Writable

NOTE
Experimental
The writable read-only property of the SerialPort interface returns a WritableStream for sending data to the device connected to the port. Chunks written to this stream must be instances of {{jsxref("ArrayBuffer")}}, {{jsxref("TypedArray")}}, or {{jsxref("DataView")}}. This property is non-null as long as the port is open and has not encountered a fatal error.
[Value("writable")]
public WritableStream Writable { get; }

Property Value

WritableStream

A WritableStream

Remarks

Methods

Close()

NOTE
Experimental
The SerialPort.close() method of the SerialPort interface returns a {{jsxref("Promise")}} that resolves when the port closes.
[Value("close")]
public Task<GlobalObject.Undefined> Close()

Returns

Task<GlobalObject.Undefined>

A Promise.

Remarks

Forget()

NOTE
Experimental
The SerialPort.forget() method of the SerialPort interface returns a {{jsxref("Promise")}} that resolves when access to the serial port is revoked.
[Value("forget")]
public Task<GlobalObject.Undefined> Forget()

Returns

Task<GlobalObject.Undefined>

A Promise that resolves with undefined once the connection is revoked.

Remarks

GetInfo()

NOTE
Experimental
The getInfo() method of the SerialPort interface returns an object containing identifying information for the device available via the port.
[Value("getInfo")]
public SerialPortInfo GetInfo()

Returns

SerialPortInfo

An object containing the following properties:

Remarks

GetSignals()

NOTE
Experimental
The SerialPort.getSignals() method of the SerialPort interface returns a {{jsxref("Promise")}} that resolves with an object containing the current state of the port's control signals.
[Value("getSignals")]
public Task<SerialInputSignals> GetSignals()

Returns

Task<SerialInputSignals>

Returns a Promise that resolves with an object containing the following members:

Remarks

Open(SerialOptions)

NOTE
Experimental
The open() method of the SerialPort interface returns a {{jsxref("Promise")}} that resolves when the port is opened. By default the port is opened with 8 data bits, 1 stop bit and no parity checking. The baudRate parameter is required.
[Value("open")]
public Task<GlobalObject.Undefined> Open(SerialOptions options)

Parameters

options SerialOptions

Returns

Task<GlobalObject.Undefined>

A Promise.

Remarks

SetSignals(SerialOutputSignals)

NOTE
Experimental
The setSignals() method of the SerialPort interface sets control signals on the port and returns a {{jsxref("Promise")}} that resolves when they are set.
[Value("setSignals")]
public Task<GlobalObject.Undefined> SetSignals(SerialOutputSignals signals = null)

Parameters

signals SerialOutputSignals

Returns

Task<GlobalObject.Undefined>

A Promise.

Remarks