Namespace: SpawnDev.SpawnJS.JSObjects.Serial
Inheritance: SpawnJSObject -> EventTarget -> Serial
MDN Reference: Serial - MDN
The Serial interface of the Web Serial API provides methods for connecting to serial ports. Access via Navigator.Serial. Requires a secure context and user gesture for RequestPort().
| Signature |
Description |
Serial(SpawnJSObjectReference _ref) |
Deserialization constructor. Access via navigator.Serial. |
| Method |
Return Type |
Description |
RequestPort() |
Task<SerialPort> |
Prompts the user to select a serial port. |
RequestPort(SerialPortOptions options) |
Task<SerialPort> |
Prompts with filter options (vendor/product ID). |
GetPorts() |
Task<SerialPort[]> |
Returns previously authorized ports. |
| Event |
Type |
Description |
OnConnect |
ActionEvent<Event> |
Fired when a serial port becomes available. |
OnDisconnect |
ActionEvent<Event> |
Fired when a serial port is removed. |
using var navigator = new Navigator();
var serial = navigator.Serial;
if (serial != null)
{
using var port = await serial.RequestPort();
await port.Open(new SerialOptions { BaudRate = 115200 });
// Use port.Readable and port.Writable for data transfer
}