@kduma-autoid/capacitor-usb-scale
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@kduma-autoid/capacitor-usb-scale

Capacitor adapter for cheap USB scales like Dymo M10

Install

npm install @kduma-autoid/capacitor-usb-scale
npx cap sync

API

enumerateDevices()

enumerateDevices() => Promise<EnumerateDevicesResponse>

Get a list of all connected compatible USB scale devices

Returns: Promise<EnumerateDevicesResponse>


requestPermission(...)

requestPermission(options?: RequestPermissionOptions | undefined) => Promise<void>

Request permission to access the USB scale device

Throws an error if permission is denied

Param Type
options RequestPermissionOptions

hasPermission(...)

hasPermission(options?: HasPermissionOptions | undefined) => Promise<HasPermissionResponse>

Check if app has permission to access the USB scale device

Param Type
options HasPermissionOptions

Returns: Promise<HasPermissionResponse>


open(...)

open(options?: OpenOptions | undefined) => Promise<void>

Open the USB scale device for data reading

Throws an error if the device is not connected or permission is denied

Param Type
options OpenOptions

close()

close() => Promise<void>

Close the USB scale device


addListener('onRead', ...)

addListener(eventName: 'onRead', listenerFunc: (event: OnReadEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Event emitted when the scale sends data

Param Type
eventName 'onRead'
listenerFunc (event: OnReadEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('onScaleConnected', ...)

addListener(eventName: 'onScaleConnected', listenerFunc: (event: OnScaleConnectedEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Event emitted when a compatible USB scale device is connected.

Param Type
eventName 'onScaleConnected'
listenerFunc (event: OnScaleConnectedEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('onScaleDisconnected', ...)

addListener(eventName: 'onScaleDisconnected', listenerFunc: (event: OnScaleDisconnectedEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Event emitted when a compatible USB scale device is disconnected.

Param Type
eventName 'onScaleDisconnected'
listenerFunc (event: OnScaleDisconnectedEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => Promise<void>

Removes all listeners


Interfaces

EnumerateDevicesResponse

Prop Type
devices USBDevice[]

USBDevice

Prop Type
id string
vid number
pid number
serial string
product { manufacturer: string; name: string; }

RequestPermissionOptions

Prop Type Description
device_id string The device to request permission for. If not specified, the first device will be used.

HasPermissionResponse

Prop Type Description
permission boolean Whether the app has permission to access the USB scale device

HasPermissionOptions

Prop Type Description
device_id string The device to check permission for. If not specified, the first device will be used.

OpenOptions

Prop Type Description
device_id string The device to open. If not specified, the first device will be used.

PluginListenerHandle

Prop Type
remove () => Promise<void>

OnReadEvent

Prop Type
data number[]
weight number
status ScaleStatus

OnScaleConnectedEvent

Prop Type
device USBDevice

OnScaleDisconnectedEvent

Prop Type
device USBDevice

Enums

ScaleStatus

Members Value
Fault "fault"
Zero "zero"
InMotion "in-motion"
Stable "stable"
UnderZero "under-zero"
OverWeight "over-weight"
NeedCalibration "need-calibration"
NeedZeroing "need-zeroing"
Unknown "unknown"

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.

Package Sidebar

Install

npm i @kduma-autoid/capacitor-usb-scale

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

72 kB

Total Files

34

Last publish

Collaborators

  • kduma