LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 11-19-2006, 09:13 PM   #1
republicson
Member
 
Registered: Feb 2006
Location: Springfield, MO
Distribution: Ubuntu Dapper 6.06
Posts: 35

Rep: Reputation: 15
Installing a USB Scale


I am trying to install a USB Scale that previously worked when I was on Windows. However, I am a complete newb and have no idea what to do to get this thing going. I am using Ubuntu 6.06 and kernel
2.6.15-27-386. When I plugged in the device, "dmesg" read as below.

Code:
[17554543.240000] usb 3-2: new low speed USB device using uhci_hcd and address 2[17554543.448000] hiddev96: USB HID v1.10 Device [RadioShack Corporation USB Electronic Scale] on usb-0000:00:1d.2-2
[17554543.756000] usb 3-2: USB disconnect, address 2
[17554543.996000] usb 3-2: new low speed USB device using uhci_hcd and address 3[17554544.204000] hiddev96: USB HID v1.10 Device [RadioShack Corporation USB Electronic Scale] on usb-0000:00:1d.2-2
If you can help me out, please give me as detailed directions as possible. Thanks!
 
Old 11-20-2006, 05:45 AM   #2
fozner
Member
 
Registered: Aug 2006
Posts: 147

Rep: Reputation: 16
Looks like there are no well-known open-source drivers available but perhaps an exhaustive search will turn up something. Try calling the manufacturer and see if they have any source code for Linux (or windows for that matter).

There is a chance that it works like a joystick. Open up KDE Control Center and look under Peripherals - Joystick.

If so, you could hire a programmer or study up and write a "simple" program in C to read the joystick and calibrate it to weight in pounds, ounces, kilograms or stones, whatever.

If it's not a joystick or mouse-like device, it will require more delving into the uhci_hcd source code and docs. Not a problem if you have the time--or the money.

A "quick and dirty" solution is to use qemu with the new usb support and boot up your old windows disk in a window, using the windows driver. Presto!

Last edited by fozner; 11-20-2006 at 05:47 AM.
 
Old 03-21-2007, 08:11 AM   #3
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Have you had any more progress on this project? I'm planning to do something similar. I have Pitney Bowes USB scale. I'd welcome any suggestions on usb hid interface as well.
Thx
CHris
 
Old 03-21-2007, 12:33 PM   #4
republicson
Member
 
Registered: Feb 2006
Location: Springfield, MO
Distribution: Ubuntu Dapper 6.06
Posts: 35

Original Poster
Rep: Reputation: 15
I've not had further progress. It's just sitting by my desk until I want to deal with it again.
 
Old 03-21-2007, 09:02 PM   #5
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Hi,

OK, I think I have some good news. I've been playing around with that scale this evening and using the information that I found here : http://www.frogmouth.net/hid-doco/linux-hid.html
and all over the Internet
I've managed to write a little C program that reads events from the hid device. I don't know about your scale but mine seems to be regular HID device and there's no special event device created for it so I read directly from hid interface. Here's the code :

Code:
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <asm/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/hiddev.h>

#define EV_NUM 5


int main (int argc, char **argv) {

  int fd = -1;
  int i;
  struct hiddev_event ev[EV_NUM];
  char name[100];

  if (argc != 2) {
    fprintf(stderr, "usage: %s hiddevice - probably /dev/usb/hiddev0\n", argv[0]);
    exit(1);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror("hiddev open");
    exit(1);
  }

  ioctl(fd, HIDIOCGNAME(100), name);

  printf("OK name = %s\n", name);
  
  printf("Reading values .. \n");
  while (1) {
      read(fd, ev, sizeof(struct hiddev_event) * EV_NUM);
      for (i = 0; i < EV_NUM; i++) {
          printf("EV: PARAM %x : %d\n", ev[i].hid, ev[i].value);
      }
  }

  close(fd);

  exit(0);
}
You can copmile and run it with :
Code:
gcc -o hidtest -Wall -W hid.c
./hidtest /dev/usb/hiddev0
Replace hiddev0 with whatever your scale is bound with.
If you have problem compiling I noticed there's a bug in hiddev.h header that uses macro that wasn't defined in any of previuosly included files - HID_MAX_USAGES.
The quick and dirty workaround is to edit the /usr/include/linux/hiddev.h and comment out the lines :

Code:
//struct hiddev_usage_ref_multi {
//	struct hiddev_usage_ref uref;
//	__u32 num_values;
//	__s32 values[HID_MAX_USAGES];
//};
once this was done I was able to compile the code.

So, example output from my scale is :

OK name = Pitney Bowes MP6V
Reading values ..
EV: PARAM 008d0050 : 2
EV: PARAM 008d0050 : 11
EV: PARAM 008d0050 : 255
EV: PARAM 008d0050 : 0
EV: PARAM 008d0050 : 0

and after putting 13.4 oz item on the scale it changes to :

EV: PARAM 008d0050 : 4
EV: PARAM 008d0050 : 11
EV: PARAM 008d0050 : 255
EV: PARAM 008d0050 : 134 - looks exactly like what I'm looking for
EV: PARAM 008d0050 : 0

I determined following meanings of the values (in the sequence):

1 : Status : 2-tray empty, 3-measuring in progress, 4-stable reading
2 : 11 probably first byte separator, never changes
3 : 255 probably second byte of separator, never changes
4 : weight - LSB
5 : weight - MSB

therefore total weight in oz is:
WEIGHT = (MSB * 25.5) + LSB / 10

I guessed number of structures (5) by experiment; if I read more the output looks like garbage.

The only thing I have to figure out now is what to send to the scale to calibrate it. It presumably calibrates once turned on but it's better to have this function available. As hid devs are "self descriptive" I guess I have to look for a proper ioctl interface param and shoot it to the scale.
 
Old 03-21-2007, 10:07 PM   #6
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Finally, I created a program that shows more user firendly results - works with PitneyBowes SmallOffice Series scale. I believe it can be easily modified to work with any other HID compatible scale. Soon, I'll add a "calibrate" function.

Code:
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <asm/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/hiddev.h>

#define EV_NUM 5


int main (int argc, char **argv) {

    int fd = -1;
    int last_status = 0;
    struct hiddev_event ev[EV_NUM];
    char name[100];
    float weight_oz;
    int weight_pd;

    if (argc != 2) {
        fprintf(stderr, "usage: %s hiddevice - probably /dev/usb/hiddev0\n", argv[0]);
        exit(1);
    }
    
    if ((fd = open(argv[1], O_RDONLY)) < 0) {
        perror("hiddev open");
        exit(1);
    }

    ioctl(fd, HIDIOCGNAME(100), name);

    printf("%s ready...\n", name);
  
    printf("Reading values .. \n");
    
    while (1) {
        read(fd, ev, sizeof(struct hiddev_event) * EV_NUM);
        //printf("EV: PARAM %x : %d\n", ev[0].hid, ev[0].value);
      
        if (ev[3].value < 0 || ev[3].value > 255) {
            continue;
        }
      
        if (ev[4].value < 0 || ev[4].value > 255) {
            continue;
        }
      
        if (ev[1].value != 11 || ev[2].value != 255) {
            continue;
        }
      
        if (ev[0].value == 3) {
            continue;
        }
      
        weight_oz = (ev[4].value * 25.5) + (ev[3].value / 10.0);
        weight_pd = weight_oz / 16;
        weight_oz = weight_oz - 16 * weight_pd;
      
        if (ev[0].value != last_status) {
            printf("Weight: %d pd %.2f oz \n", weight_pd, weight_oz);
        }
      
        last_status = ev[0].value;
    }

    close(fd);

    exit(0);
}
 
Old 11-11-2007, 08:17 AM   #7
hhhansen
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Rep: Reputation: 0
Thumbs up Tried the code with a no-name USB scale

Just a note to let you know that I managed to get your code to work with a no-name USB scale. Instead of a EV_SIZE=5 I had to read the parameters into two separate variables, 8 events at a time. And the weight output was encoded in a different way.

Thanks!
 
Old 11-12-2007, 09:39 AM   #8
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Glad to hear that, can you post a short description of how you calculate the final weight using your device?
 
Old 11-12-2007, 09:48 AM   #9
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
looks like you have something for a page on Sourceforge.
 
Old 04-24-2008, 01:00 AM   #10
yonnieboy
Member
 
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143

Rep: Reputation: 15
How's the progress on the scale? I'm using F8, a total newb. I have the same scale but can't use it. I have a copy of the official radio shack osx and xp drivers, would any portions of those be useful in building a driver for Linux?
 
Old 04-29-2008, 12:20 PM   #11
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Hi,

Sorry for the late answer, I was quite busy recently. I think you can use the code that I posted above however hhhansen would have to help you modify it as he did (he also has RS scale). Did you try to compile the source?

Chris
 
Old 04-30-2008, 02:17 AM   #12
yonnieboy
Member
 
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143

Rep: Reputation: 15
compiling is a little beyond my ability at this time. I'm teaching the staff at the same time I learn something new, so everything's breaking, too! Trying to get them to call a file and interpret a reading is also a bit beyond the users here. I was hoping you or someone else had found or created a good scale driver and posted. I did find a reference to the vendor and product ID on another linux website for usb devices, but that ended up in another all-nighter search with no useful results. I also got the m$ and mac drivers, if those are of any help.
 
Old 04-30-2008, 06:21 AM   #13
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
I'm afraid you will not find it. I was also looking for it. I took me so long that I wrote my own software to deal with it. Compiling is not that difficult though, I think I can help you with that. Let's start with this question : what Linux distribution are you using?
 
Old 05-01-2008, 12:06 AM   #14
yonnieboy
Member
 
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143

Rep: Reputation: 15
Hi Krizzz,
I got fap'ed by the bit gestapo, so everything is really slow. Anyway, I'm using f8kde on the target system. The USB scale I have is the Radio Shack one and Kinfo id's it as vendor#2233 product#6323. I'd like to get this thing working so we can weigh mail for postage. I was diddling around earlier with modprobe getting another usb device working today and I'm wondering if that was even necessary since the kernel already had the vendor and product numbers already in it.

I haven't knowingly compiled a thing yet in Linux, so this sounds like a good reason to have Linux, sort of brings back the fun of having a computer in the first place.
 
Old 05-01-2008, 08:41 AM   #15
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Alright, I assume that you know how to use terminal. Copy the code from the post #6 and save it to the file named hid.c . Then in the directory where the file is try to execute following :

Quote:
gcc -o hidtest -Wall -W hid.c
./hidtest /dev/usb/hiddev0
Let me know about the results. You should have hidtest file created in the directory. Also, post the output from following :
Quote:
ls -l /dev/usb/hid*
lsusb
having the scale connected and powered on (if there's any switch)

Once we have all that info we can carry on...
 
  


Reply

Tags
electronic, joystick, kde, mouse, qemu, radio, source, usb, windows



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mplayer: picture does not scale bamsesbilledbog Linux - Software 5 11-19-2012 01:38 PM
glade and scale widgets johnson_steve Programming 10 03-15-2006 03:29 PM
Large Scale porting lucky6969b Programming 2 01-26-2006 09:32 PM
scale sundaresh Linux - General 1 11-14-2005 03:15 PM
Crop/scale pdfs S.B. Linux - Software 1 03-16-2005 11:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration