Skip to main content

BarcodeReader

caution

This service is experimental and may change in the future.

A device that reads various barcodes, like QR codes. For the web, see BarcodeDetector.

import { BarcodeReader } from "@devicescript/core"

const barcodeReader = new BarcodeReader()

Registers

enabled

Turns on or off the detection of barcodes.

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

  • read and write

import { BarcodeReader } from "@devicescript/core"

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

const barcodeReader = new BarcodeReader()
// ...
barcodeReader.enabled.subscribe(async (value) => {
...
})
note

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

formats

Reports the list of supported barcode formats, as documented in https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API.

  • type: Register<any[]> (packing format r: u8)
  • optional: this register may not be implemented
  • constant: the register value will not change (until the next reset)
note

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

Events

detect

Raised when a bar code is detected and decoded. If the reader detects multiple codes, it will issue multiple events. In case of numeric barcodes, the data field should contain the ASCII (which is the same as UTF8 in that case) representation of the number.

barcodeReader.detect.subscribe(() => {

})