Coder Social home page Coder Social logo

vaclavvanik / usb-scale-reader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sanmai/usb-scale-reader

0.0 2.0 0.0 70 KB

Read weight from an USB scale (from Stamps.com or DYMO) in Linux

License: MIT License

Makefile 3.48% PHP 66.22% C 30.31%

usb-scale-reader's Introduction

USBScaleReader

Build Status

This library lets you read weight from a standard USB scale using pure PHP.

Could be ported to other languages with ease, should they have unpack()

Tested with:

  • Stamps.com Stainless Steel 5 lb. Digital Scale
  • DYMO M25 25 lb Digital Postal Scale

See read_stupid.php or usbscale.c if you want to understand how it works at a glance.

Usage

$reader = \USBScaleReader\Reader::fromDevice('/dev/scale');
$weightInGrams = $reader->getWeight();
var_dump($reader, $weightInGrams);

Sample output:

class USBScaleReader\Reader#2 (5) {
  public $report =>
  int(3)
  public $status =>
  int(4)
  public $unit =>
  int(2)
  public $exponent =>
  int(0)
  public $weight =>
  int(144)
}
int(144)

udev rules

Add to /etc/udev/rules.d/80-persistent-scale.rules:

KERNEL=="hidraw*", ATTRS{manufacturer}=="Maker Name", SYMLINK+="scale"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"

Maker name is either Stamps.com or DYMO.

And then reconnect your scale.

For other makers see:

udevadm info -a -p  $(udevadm info -q path -n /dev/hidrawN)

These rules imply that you should be in plugdev for the scripts to work.

C version

There is also a simple reading program written in C.

To build it and run tests against PHP implementation:

cd example
make test

Usage is as simple as it can be:

./usbscale /dev/hidraw3

Outputs something like

70.87 g

usb-scale-reader's People

Contributors

sanmai avatar

Watchers

 avatar  avatar

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.