Merge pull request #3 from linspb/Mettler_Toledo

Thanks for the pull request!
pull/18/head
erjiang 11 years ago
commit 72a7ea6aaf

@ -1,3 +1,4 @@
SUBSYSTEM=="usb", ATTR{idVendor}=="1446", ATTR{idProduct}=="6a73", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="1446", ATTR{idProduct}=="6a73", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="7b7c", ATTR{idProduct}=="0100", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="7b7c", ATTR{idProduct}=="0100", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="2474", ATTR{idProduct}=="0550", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="2474", ATTR{idProduct}=="0550", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="0eb8", ATTR{idProduct}=="f000", MODE="0776"

@ -12,7 +12,12 @@
// //
// **NSCALES** should be kept updated with the length of the list. // **NSCALES** should be kept updated with the length of the list.
// //
#define NSCALES 3 #define NSCALES 4
//
// What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing)
//
#define WEIGH_COUNT 2
// //
// Scales // Scales
@ -24,5 +29,7 @@ uint16_t scales[NSCALES][2] = {\
// USPS (Elane) PS311 "XM Elane Elane UParcel 30lb" // USPS (Elane) PS311 "XM Elane Elane UParcel 30lb"
{0x7b7c, 0x0100}, {0x7b7c, 0x0100},
// Stamps.com Stainless Steel 5 lb. Digital Scale // Stamps.com Stainless Steel 5 lb. Digital Scale
{0x2474, 0x0550} {0x2474, 0x0550},
// Mettler Toledo
{0x0eb8, 0xf000}
}; };

@ -94,6 +94,8 @@ int main(void)
libusb_device* dev; libusb_device* dev;
libusb_device_handle* handle; libusb_device_handle* handle;
int weigh_count = WEIGH_COUNT -1;
// //
// We first try to init libusb. // We first try to init libusb.
// //
@ -213,10 +215,13 @@ int main(void)
printf("%x\n", data[i]); printf("%x\n", data[i]);
} }
#endif #endif
if (weigh_count < 1) {
scale_result = print_scale_data(data); scale_result = print_scale_data(data);
if(scale_result != 1) if(scale_result != 1)
break; break;
} }
weigh_count--;
}
else { else {
fprintf(stderr, "Error in USB transfer\n"); fprintf(stderr, "Error in USB transfer\n");
scale_result = -1; scale_result = -1;
@ -275,13 +280,17 @@ static int print_scale_data(unsigned char* dat) {
double weight = (double)(dat[4] + (dat[5] << 8)) / 10; double weight = (double)(dat[4] + (dat[5] << 8)) / 10;
if(expt != 255 && expt != 0) { if(expt != 255 && expt != 0) {
if (expt > 127) {
weight = weight * pow(10, expt-255);
} else {
weight = pow(weight, expt); weight = pow(weight, expt);
} }
}
// //
// The scale's first byte, its "report", is always 3. // The scale's first byte, its "report", is always 3.
// //
if(report != 0x03) { if(report != 0x03 && report != 0x04) {
fprintf(stderr, "Error reading scale data\n"); fprintf(stderr, "Error reading scale data\n");
return -1; return -1;
} }

Loading…
Cancel
Save