2017 © Pedro Peláez
 

library usb-scale-reader

Standard USB scale reader library

image

sanmai/usb-scale-reader

Standard USB scale reader library

  • Friday, October 23, 2015
  • by sanmai
  • Repository
  • 3 Watchers
  • 6 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 50 % Grown

The README.md

USBScaleReader

Latest Stable Version, (*1)

This library lets you read weight from a standard USB scale using pure PHP., (*2)

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

Tested with: - Stamps.com Stainless Steel 5 lb. Digital Scale - DYMO M25 25 lb Digital Postal Scale, (*4)

See read_stupid.php or usbscale.c if you want to understand how it works at a glance., (*5)

Usage

composer require sanmai/usb-scale-reader

And then:, (*6)

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

Sample output:, (*7)

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:, (*8)

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

Maker name is either Stamps.com or DYMO., (*9)

And then reconnect your scale., (*10)

For other makers see:, (*11)

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., (*12)

C version

There is also a simple reading program written in C., (*13)

To build it and run tests against PHP implementation:, (*14)

cd example
make test

Usage is as simple as it can be:, (*15)

./usbscale /dev/hidraw3

Outputs something like, (*16)

70.87 g

The Versions

23/10 2015

dev-master

9999999-dev https://github.com/sanmai/usb-scale-reader

Standard USB scale reader library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires