Skip to main content

Serial

caution

This service is experimental and may change in the future.

An asynchronous serial communication service capable of sending and receiving buffers of data. Settings default to 115200 baud 8N1.

import { Serial } from "@devicescript/core"

const serial = new Serial()

Commands

send

Send a buffer of data over the serial transport.

serial.send(data: Buffer): Promise<void>

Registers

enabled

Indicates if the serial connection is active.

  • type: Register<boolean> (packing format u8)

  • read and write

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.enabled.read()
await serial.enabled.write(value)
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.enabled.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

connectionName

User-friendly name of the connection.

  • type: Register<string> (packing format s)

  • optional: this register may not be implemented

  • read only

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.connectionName.read()
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.connectionName.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

baudRate

A positive, non-zero value indicating the baud rate at which serial communication is be established.

  • type: Register<number> (packing format u32)

  • read and write

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.baudRate.read()
await serial.baudRate.write(value)
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.baudRate.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

dataBits

The number of data bits per frame. Either 7 or 8.

  • type: Register<number> (packing format u8)

  • read and write

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.dataBits.read()
await serial.dataBits.write(value)
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.dataBits.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

stopBits

The number of stop bits at the end of a frame. Either 1 or 2.

  • type: Register<number> (packing format u8)

  • read and write

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.stopBits.read()
await serial.stopBits.write(value)
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.stopBits.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

parityMode

The parity mode.

  • type: Register<number> (packing format u8)

  • read and write

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.parityMode.read()
await serial.parityMode.write(value)
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.parityMode.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

bufferSize

A positive, non-zero value indicating the size of the read and write buffers that should be created.

  • type: Register<number> (packing format u8)

  • read and write

import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
const value = await serial.bufferSize.read()
await serial.bufferSize.write(value)
  • track incoming values
import { Serial } from "@devicescript/core"

const serial = new Serial()
// ...
serial.bufferSize.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.