Code Monkey home page Code Monkey logo

serial-nci-scale's Introduction

Serial NCI Scale

An API to query a Serial Scale which supports the NCI protocal (SCP-12, NCI 3825, NCI 3835). Tested against the Salter Brecknell PS-USB scale. Depends on the Web Serial API.

Getting Started

Page Hosting the library must be served over HTTPS. Demo is available at https://chris-rudmin.github.io/serial-nci-scale/

Installation

npm install serial-nci-scale --save

Usage

import SerialNCIScale from 'serial-nci-scale';

const scale = new SerialNCIScale();
const { weight, units, status } = await scale.getWeight();

Constructor

  • const scale = new SerialNCIScale( [config] ) - Create a new instance with optional device filter array or port config object

Config Object

  • config.filters - Optional - Array of filters to use when initializing the port. Defaults to [].
  • config.portConfig - Optional - Object containing serial configuration to use for initializing port. Defaults to 7E1 byte format.

Instance Methods

  • scale.getWeight() - Returns a promise which resolves with scale weight data. Required to be called from user action
  • scale.getStatus() - Returns a promise which resolves with scale status data. Required to be called from user action
  • scale.zero() - Returns a promise which resolves when the scale is zeroed. Required to be called from user action
  • scale.startPolling([pollInterval]) - Starts polling the scale for weight data. Default polling interval is 500 ms Required to be called from user action
  • scale.stopPolling() - Stops polling the scale
  • scale.disconnect() - Returns a promise which resolves once disconnected. Closes the read and write streams and frees the serial port

Static Attributes

  • SerialNCIScale.isWebSerialSupported - true if Web Serial API exists in your browser
  • SerialNCIScale.supportedScaleFilters - Array of devices which are known to be supported

Events

The serial-nci-scale instance is an EventTarget and can be listened to for custom events. Scale data is contained the in the detail property.

  • weight - Dispatched for every weight read
  • status - Dispatched for every status read
  • settled - Dispatched when the scale is no longer in motion and if the weight is different than the last settled weight
scale.addEventListener('settled', ({ detail }) => foo(detail.status));
scale.startPolling();

Supported Browsers

Currently only Chrome 89+ and Edge 89+ support the Web Serial API. Earlier versions of Chrome and Edge can use the API if it is enabled in chrome://flags

serial-nci-scale's People

Contributors

chris-rudmin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

loreteano

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.