erjiang / usbscale

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

5Lb Stamps.com scale doesn't work on Ubuntu 12.04 - fixed #4

Closed hamx0r closed 10 years ago

hamx0r commented 10 years ago

If you'd like me to do a pull request, I can do that. However, i noticed the "free" 5Lb scale stamps.com gives its customers reports differently than what you script expects. I like the script more than the C port you made because it allows quick hacking for new devices.

The Model 510 (the variant which works on both Mac and Windows) does not seem to report status and units as your code expects. The only fields which change with the weight change are the 13th and 14th bytes. The units are always tenths of an oz. To make your script work i changed these lines: my $lsb = ord(substr($data, 12, 1)); my $msb = ord(substr($data, 13, 1));

I also added vars to calculate pounds and ounces: use POSIX; my $lbs = floor($weight / 16); my $ozs = $weight % 16;

which cases this output: print "$weight $lbs $ozs\n"; 28.3 1 12

Which reads 28.3oz is 1lb 12oz

Here is some more debug output in case you want to guess what the other fields mean: sudo cat /dev/usb/hiddev0 | hexdump 0000000 0041 008d ffff ffff 0040 008d 011b 0000 (28.3oz item) 0000130 0041 008d ffff ffff 0040 008d 022f 0000 (55.9oz item) 0000190 0041 008d ffff ffff 0040 008d 0000 0000 (nothing on scale) *

erjiang commented 10 years ago

Can you tell me what the vendor and device ID of your scale is? The original program was written for the 5lb scale I originally got from Stamps.com, and I wouldn't be surprised if they have a newer version.

Anyways, the Perl code is known to have had an issue with being off by one, and I suggest you use the C program instead. It's easy to add support for a new scale: see the readme file. The data protocol for USB scales is standardized, so unless your scale is non-compliant, then there should be no problems.

I'm going to close this issue since for now, since it's not about the C program. If you try the C program and it doesn't work, then open a new ticket.