Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

sanmai/usb-scale-reader

Repository files navigation

Latest Stable Version

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

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

Tested with:

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

Seeread_stupid.php orusbscale.c if you want to understand how it works at a glance.

Usage

composer require sanmai/usb-scale-reader

And then:

$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 eitherStamps.com orDYMO.

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 inplugdev for the scripts to work.

C version

There is alsoa simple reading program written in C.

To build it and run tests against PHP implementation:

cd examplemake test

Usage is as simple as it can be:

./usbscale /dev/hidraw3

Outputs something like

70.87 g

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp