erjiang / usbscale

Reads weight data from USB scales.
GNU General Public License v3.0
90 stars 22 forks source link

Fairbanks scales #20

Closed bhartvigsen closed 4 years ago

bhartvigsen commented 4 years ago

@bhartvigsen Interesting find. Can you open an issue on https://github.com/erjiang/usbscale/issues with details about your scale? It'd be nice to add support for it.

Here's all i know:

#!/usr/bin/perl
#
use bytes;

my $data;

#prevents us from repeating messages
my $waitingflag = 0;

while (1) {
        $data = `cat /dev/hidraw0 | head -c 7`;
        my $report = ord(substr($data, 0, 1));
        my $status = ord(substr($data, 1, 1));
        my $unit = ord(substr($data, 2, 1));
        my $lsb = ord(substr($data, 4, 1));
        my $msb = ord(substr($data, 5, 1));
        my $weight = ($msb * 256 + $lsb) / 100;
        if ($report != 0x03) {
                die "Error reading scale data!\n";
        }
        if ($status == 0x01) {
                die "Scale reports FAULT!\n";
        } elsif ($status == 0x02 || $weight == 0) {
                if ($waitingflag != 0x02) {
                        print "Zero'd...\n";
                        $waitingflag = 0x02;
                }
        } elsif ($status == 0x03) {
                if ($waitingflag != 0x03) {
                        print "Weighing...\n";
                        $waitingflag = 0x03;
                }
        } elsif ($status == 0x04) {
                my $unitName = "units";
                if ($unit == 11) {
                        $unitName = "ounces";
                } elsif ($unit == 12) {
                        $unitName = "pounds";
                }
                print "$weight $unitName\n";
                last;
        } elsif ($status == 0x05) {
                if ($waitingflag != 0x05) {
                        print "Scale reports Under Zero...\n";
                        $waitingflag = 0x05;
                }
        } elsif ($status == 0x06) {
                if ($waitingflag != 0x06) {
                        print "Scale reports Over Weight!\n";
                        $waitingflag = 0x06;
                }
        } elsif ($status == 0x07) {
                if ($waitingflag != 0x07) {
                        print "Scale reports Calibration Needed!\n";
                        $waitingflag = 0x07;
                }
        } elsif ($status == 0x08) {
                if ($waitingflag != 0x08) {
                        print "Scale reports Re-zeroing Needed!\n";
                        $waitingflag = 0x08;
                }
        } else {
                die "Unknown status code: $status\n";
        }
}
Fairbanks Scales SCB-R9000:

  Product ID:   0x555e
  Vendor ID:    0x0b67
  Version:  0.04
  Serial Number:    130850800074
  Speed:    Up to 12 Mb/sec
  Manufacturer: Fairbanks Scales
  Location ID:  0x14130000 / 14
  Current Available (mA):   500
  Current Required (mA):    100
  Extra Operating Current (mA): 0
erjiang commented 4 years ago

Sorry for the lack of attention on this. It looks like the Fairbanks SCB-R9000 was already added as a supported scale (see scales.h). If there's anything else needed in relation to this particular scale, feel free to reopen or open a new issue.