# DeviceSerialBinding

`import { DeviceSerialBinding } from "destack:device/binding";`

Serial binding family.

```ds title="DeviceSerialBinding"
export interface DeviceSerialBinding {
    listSerialPorts(): Result<SerialPort[], HostError>;
    openSerialWatch(): Result<SerialWatchHandle, HostError>;
    closeSerialWatch(watch: SerialWatchHandle): Result<void, HostError>;
    readSerialWatch(watch: SerialWatchHandle, timeoutNs?: uint64 | undefined): Result<SerialWatchEvent, HostError>;
    openSerialPort(id: &'a readonly string, options: &'b readonly SerialOpenOptions): Result<SerialPortHandle, HostError>;
    closeSerialPort(port: SerialPortHandle): Result<void, HostError>;
    describeSerialPort(port: SerialPortHandle): Result<SerialPort, HostError>;
    getSerialConfig(port: SerialPortHandle): Result<SerialConfig, HostError>;
    setSerialConfig(port: SerialPortHandle, config: &'a readonly SerialConfig): Result<void, HostError>;
    readSerial(port: SerialPortHandle, buffer: &'a [uint8], timeoutNs?: uint64 | undefined): Result<uint64, HostError>;
    writeSerial(port: SerialPortHandle, bytes: &'a readonly [uint8], timeoutNs?: uint64 | undefined): Result<uint64, HostError>;
    drainSerial(port: SerialPortHandle): Result<void, HostError>;
    flushSerial(port: SerialPortHandle, buffers: SerialFlushFlags): Result<void, HostError>;
    getSerialSignals(port: SerialPortHandle): Result<SerialInputSignals, HostError>;
    setSerialSignals(port: SerialPortHandle, signals: &'a readonly SerialOutputSignals): Result<void, HostError>;
    readSerialEvent(port: SerialPortHandle, timeoutNs?: uint64 | undefined): Result<SerialEvent, HostError>;
}
```

[language/library/src/device/binding/serial.ds:292:456](https://github.com/destack-sh/destack/blob/main/language/library/src/device/binding/serial.ds#L292-L456)

## Members

### `listSerialPorts(): Result<SerialPort[], HostError>`

List serial ports.

### `openSerialWatch(): Result<SerialWatchHandle, HostError>`

Open a serial topology watch.

### `closeSerialWatch(watch: SerialWatchHandle): Result<void, HostError>`

Close a serial topology watch.

### `readSerialWatch(watch: SerialWatchHandle, timeoutNs?: uint64 | undefined): Result<SerialWatchEvent, HostError>`

Read one serial topology event.

### `openSerialPort(id: &'a readonly string, options: &'b readonly SerialOpenOptions): Result<SerialPortHandle, HostError>`

Open a serial port.

### `closeSerialPort(port: SerialPortHandle): Result<void, HostError>`

Close a serial port.

### `describeSerialPort(port: SerialPortHandle): Result<SerialPort, HostError>`

Describe a serial port.

### `getSerialConfig(port: SerialPortHandle): Result<SerialConfig, HostError>`

Read serial port configuration.

### `setSerialConfig(port: SerialPortHandle, config: &'a readonly SerialConfig): Result<void, HostError>`

Update serial port configuration.

### `readSerial(port: SerialPortHandle, buffer: &'a [uint8], timeoutNs?: uint64 | undefined): Result<uint64, HostError>`

Read bytes from a serial port.

### `writeSerial(port: SerialPortHandle, bytes: &'a readonly [uint8], timeoutNs?: uint64 | undefined): Result<uint64, HostError>`

Write bytes to a serial port.

### `drainSerial(port: SerialPortHandle): Result<void, HostError>`

Wait for queued serial output to drain.

### `flushSerial(port: SerialPortHandle, buffers: SerialFlushFlags): Result<void, HostError>`

Flush queued serial bytes.

### `getSerialSignals(port: SerialPortHandle): Result<SerialInputSignals, HostError>`

Read serial input signals.

### `setSerialSignals(port: SerialPortHandle, signals: &'a readonly SerialOutputSignals): Result<void, HostError>`

Update serial output signals.

### `readSerialEvent(port: SerialPortHandle, timeoutNs?: uint64 | undefined): Result<SerialEvent, HostError>`

Read one serial port event.
