@kduma-autoid/capacitor-usb-scale

Capacitor adapter for cheap USB scales like Dymo M10

Install

npm install @kduma-autoid/capacitor-usb-scalenpx cap sync

API

Latest API documentation can be found in readme file on GitHub

enumerateDevices()

enumerateDevices() => Promise<{ devices: USBDevice[]; }>

Get a list of all connected compatible USB scale devices

Returns: Promise<{ devices: USBDevice; }>


requestPermission(...)

requestPermission(device?: string | undefined) => Promise<{ status: boolean; }>

Request permission to access the USB scale device

ParamTypeDescription
devicestringThe device to request permission for. If not specified, the first device will be used.

Returns: Promise<{ status: boolean; }>


open(...)

open(device?: string | undefined) => Promise<void>

Open the USB scale device for data reading

ParamTypeDescription
devicestringThe device to open. If not specified, the first device will be used.

stop()

stop() => Promise<void>

Close the USB scale device


setIncomingWeightDataCallback(...)

setIncomingWeightDataCallback(callback: (data: ScaleRead) => void) => Promise<CallbackID>

Sets a callback to be called when the scale sends data. If callback is not set, there will bi raised an usb_scale_read event.

ParamTypeDescription
callback(data: ScaleRead) => voidThe callback to be called when the scale sends data.

Returns: Promise<string>


clearIncomingWeightDataCallback()

clearIncomingWeightDataCallback() => Promise<void>

Clears the callback set by setIncomingWeightDataCallback.


Type Aliases

USBDevice

{ id: string, vid: number, pid: number, serial?: string, product: { manufacturer: string, name: string } }

ScaleRead

{ data: number, weight: number, status: ScaleStatus }

ScaleStatus

"Fault" | "Zero" | "InMotion" | "Stable" | "UnderZero" | "OverWeight" | "NeedCalibration" | "NeedZeroing" | "Unknown"

CallbackID

string

Events

usb_scale_read

addEventListener(type: "usb_scale_read", listener: (ev: ScaleRead) => any, useCapture?: boolean): void;

Emitted when the scale sends data, and there is no callback set by setIncomingWeightDataCallback.

usb_scale_connected

addEventListener(type: "usb_scale_connected", listener: (ev: { device: USBDevice }) => any, useCapture?: boolean): void;

Emitted when a compatible USB scale device is connected.

usb_scale_disconnected

addEventListener(type: "usb_scale_disconnected", listener: (ev: { device: USBDevice }) => any, useCapture?: boolean): void;

Emitted when a compatible USB scale device is disconnected.