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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
05-02-2008, 01:12 AM
|
#16
|
Member
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143
Rep:
|
cd Desktop
[jan@alpha-site Desktop]$ ./hidtest /dev/usb/hiddev0
hiddev open: No such file or directory
[jan@alpha-site Desktop]$ ls -l /dev/usb/hid*
ls: cannot access /dev/usb/hid*: No such file or directory
[jan@alpha-site Desktop]$ lsusb
bash: lsusb: command not found
hid.c and hidtest exist. Should I be doing this as root? I had a problem a little earlier when I tried to copy/paste post#6. The browser crashed, bug-report popped-up. I restarted the system and then the copy/paste started working again.
|
|
|
05-02-2008, 01:16 AM
|
#17
|
Member
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143
Rep:
|
I found a section in one of my manuals on programming, think I'll read it.
|
|
|
05-05-2008, 09:08 AM
|
#18
|
Member
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200
Rep:
|
It seems that you successfully compiled the program so you're very close from actually getting it to work. I checked out the fedora core hiddev support and the device should be there by default but the path to it is a bit different. I used Slackware in my example. Try using /dev/hiddev0 instead of /dev/usb/hiddev0. That should work. Also, please post output from lsusb command and try ls -l /dev/hid* this time. Make sure the scale is connected.
|
|
|
05-05-2008, 09:24 AM
|
#19
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,311
|
I agree that you probably do have a SourceForge entry.
The only remaining "trick" is the USB bit. The piece you probably want to read more about is called hotplug. When you plug-in a device or remove it, the hotplug daemon looks-up information to find out what to do. (In your case, specifically look at /etc/hotplug/usb*.)
In your case, this device really isn't privileged and probably won't be used by more than one client, so all you'd really like to do here is to have it set up a nice entry in /dev/input so that your user-application can expect to find the device by a nice name such as pitney_bowes_xyzzy_scale.
Beyond that, no system-level driver-stuff is needed: you can read and write to the device as it is. A short user-level library might be a nice touch, with routines like "is there a device attached," "wait so-many seconds for device to be attached," "wait so-many seconds to read the weight," and so on.
|
|
|
05-05-2008, 09:45 AM
|
#20
|
Member
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200
Rep:
|
Actually the Pitney-Bowes scale has been working for me for quite a while. I read directly from the raw hiddev as the protocol is trivial - just like I demonstrated in the example. It would be good if hhhansen posted his modifications to the code for Radio Shack scale then the people like yonnieboy wouldn't have to struggle again. We could add the scale recognition and support for different USB scales over unified protocol. I'll open the SF project.
|
|
|
05-06-2008, 12:26 AM
|
#21
|
LQ Newbie
Registered: Nov 2007
Posts: 4
Rep:
|
Quote:
Originally Posted by krizzz
Actually the Pitney-Bowes scale has been working for me for quite a while. I read directly from the raw hiddev as the protocol is trivial - just like I demonstrated in the example. It would be good if hhhansen posted his modifications to the code for Radio Shack scale then the people like yonnieboy wouldn't have to struggle again. We could add the scale recognition and support for different USB scales over unified protocol. I'll open the SF project.
|
Ok, sorry for not having responded before. I will post my mods as soon as possible. Krizz, thanks for being so helpful.
|
|
|
05-06-2008, 02:55 AM
|
#22
|
Member
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143
Rep:
|
cd Desktop
[jan@alpha-site Desktop]$ gcc -o hidtest -Wall -W hid.c
[jan@alpha-site Desktop]$ ./hidtest /dev/hiddev0
hiddev open: Permission denied
[jan@alpha-site Desktop]$ ps
PID TTY TIME CMD
7706 pts/0 00:00:00 bash
7845 pts/0 00:00:00 ps
[jan@alpha-site Desktop]$ lsusb
bash: lsusb: command not found
[jan@alpha-site Desktop]$ ls -l /dev/hid*
crw-rw---- 1 root root 180, 96 2008-05-04 05:34 /dev/hiddev0
crw-rw---- 1 root root 251, 0 2008-05-04 05:34 /dev/hidraw0
[jan@alpha-site Desktop]$
I took your change as meaning the line in the file hid.c and changed it too. After altering the file I clicked on hidtest and nothing seemed to happen. So then I did the above from the terminal. I can't find the process using ps -ef so I can't kill it and try over.
after reboot hiddev is still open permission denied
Last edited by yonnieboy; 05-06-2008 at 03:20 AM.
Reason: need to add reboot info.
|
|
|
05-06-2008, 09:14 AM
|
#23
|
Member
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200
Rep:
|
Try to run it as root. You don't have permissions to the device.
|
|
|
05-07-2008, 02:10 PM
|
#24
|
Member
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143
Rep:
|
ktop]# hidtest
bash: hidtest: command not found
[root@alpha-site Desktop]# ./hidtest
usage: ./hidtest hiddevice - probably /dev/hiddev0
[root@alpha-site Desktop]# ./hidtest /dev/hiddev0
RadioShack Corporation USB Electronic Scale ready...
Reading values ..
exit
The display just sat there at reading values, I put envelopes on and my glasses, and my finger, no changes. So I tried exit, then q, then escape, no effect. So I closed the terminal. Doubleclicking the hidtest icon as root didn't appear to do anything either. But it apparently does something as root!
|
|
|
09-24-2008, 06:08 PM
|
#25
|
LQ Newbie
Registered: Sep 2008
Posts: 4
Rep:
|
radioshack USB scale
I wrote some terribly sloppy code that seems to mostly work with the "Radio Shack USB Scale"
(ID 2233:6323 RadioShack Corporation USB Electronic Scale)
Even though it's been a while since anyone posted this thread helped me initially and is the first result in google for "linux usb scale"
The places where it is divided by 2.55 may be further fine-tuned by changing that number. If someone finds a better value please reply, as I don't have a comparison scale handy.
That is, if it's possible to make sense of this
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 8
int get_input(int argc, char **argv,int input_type) {
int fd = -1;
int i;
struct hiddev_event ev[EV_NUM];
char name[100];
int input_small;
int input_large;
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);
read(fd, ev, sizeof(struct hiddev_event) * EV_NUM);
input_large = ev[6].value;
input_small = ev[7].value;
close(fd);
if (input_type == 1) {return input_small;}
if (input_type == 0) {return input_large;}
}
int tare(int input[5]) {
int input_small = 1;
int input_large = 0;
int i;
int largest_value = input[0];
//Just returns the largest value from the array.. for now.
for ( i = 0; i < 5; i++)
{
if (largest_value > input[i]) {largest_value = input[i];}
}
//printf("%i Largest Value?\n",largest_value);
return largest_value;
}
int main (int argc, char **argv) {
int input_small = 1; // Just for easy viewing
int input_large = 0; // Input selection
int small_array[5]; // Array of values to be tared
int large_array[5]; //
unsigned char base_small;// Tared Values to work with
unsigned char base_large;//
unsigned char weight_small;
unsigned char weight_large;
int final_weight;
int last_status = 0;
int i;
// Get Input
for ( i = 0; i < 5; i++){
small_array[i] = get_input(argc,argv,input_small);
large_array[i] = get_input(argc,argv,input_large);
}
// Basic Tare
base_small = tare(small_array);
base_large = tare(large_array);
printf("Tared! Ready to Weigh\n");
while (1) {
weight_small = get_input(argc,argv,input_small);
weight_large = get_input(argc,argv,input_large);
if (weight_large < (base_large + 1)) { weight_large = 0; }
else { weight_large = (((weight_large - (base_large + 1)) * 100) + 25); }
if (weight_large == 0)
{
if (weight_small >= base_small){
weight_small = (((weight_small) - (base_small)) / 2.55);}
else
{weight_small = 0;}
}
if (weight_large > 0) {
weight_small = ((weight_small) / 2.55); }
final_weight = (weight_large + weight_small);
if (weight_small != last_status) {
printf("Weight: %d grams \n", final_weight);
}
last_status = weight_small;
}
exit(0);
return 0;
}
edit: Thank you for the previous code posted,which is used in this.
I know it's ugly! But at least give it a try with your RadioShack USB Scale if you're interested.
Last edited by bkubes; 09-24-2008 at 06:10 PM.
Reason: Credit
|
|
|
09-25-2008, 03:53 AM
|
#26
|
Member
Registered: Apr 2008
Location: sw OR
Distribution: PCLOS, Kubuntu, Lubuntu, Unity
Posts: 143
Rep:
|
Thanks! I'll go hunt down where it may have gone! I haven't had the time to fiddle with it. Wife's all mad because her XP got replaced with Linux and then her scale don't work, and the system is broke, when all she wants most is solitaire. Well...I put a few nice things on like a whole bunch of solitaire games and gnucash, and cosmos screensavers, and grandkid education stuff ... well she likes it better now than the xp! Except for the scale! I'll try it out and get back to you!
Really appreciate the effort!
|
|
|
09-25-2008, 03:30 PM
|
#27
|
LQ Newbie
Registered: Sep 2008
Posts: 4
Rep:
|
Actually after some more testing, under heavier weight this is broken... but it's a start.
|
|
|
09-25-2008, 05:00 PM
|
#28
|
LQ Newbie
Registered: Sep 2008
Posts: 4
Rep:
|
Here it is able to work off of heavier weights.
Might still need some tuning for completely accurate weights, but it's fairly close.
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 8
int get_input(int argc, char **argv,int input_type) {
int fd = -1;
int i;
struct hiddev_event ev[EV_NUM];
char name[100];
int input_small;
int input_large;
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);
read(fd, ev, sizeof(struct hiddev_event) * EV_NUM);
input_large = ev[6].value;
input_small = ev[7].value;
close(fd);
if (input_type == 1) {return input_small;}
if (input_type == 0) {return input_large;}
}
int tare(int input[5]) {
int input_small = 1;
int input_large = 0;
int i;
int largest_value = input[0];
//Just returns the largest value from the array.. for now.
for ( i = 0; i < 5; i++)
{
if (largest_value > input[i]) {largest_value = input[i];}
}
//printf("%i Largest Value?\n",largest_value);
return largest_value;
}
int main (int argc, char **argv) {
int input_small = 1; // Just for easy viewing
int input_large = 0; // Input selection
int small_array[5]; // Array of values to be tared
int large_array[5]; //
unsigned char base_small;// Tared Values to work with
unsigned char base_large;//
unsigned char weight_small_char;
unsigned char weight_large_char;
int final_weight;
int last_status = 0;
float weight_small;
float weight_large;
float constant = 2.6666667;
int i;
// Get Input
for ( i = 0; i < 5; i++){
small_array[i] = get_input(argc,argv,input_small);
large_array[i] = get_input(argc,argv,input_large);
}
// Basic Tare
base_small = tare(small_array);
base_large = tare(large_array);
printf("Tared! Ready to Weigh\n");
while (1) {
weight_small_char = get_input(argc,argv,input_small);
weight_large_char = get_input(argc,argv,input_large);
weight_small = weight_small_char;
weight_large = weight_large_char;
if (weight_large < (base_large + 1)) { weight_large = 0; }
else { weight_large = (((weight_large - (base_large + 1)) * 94) + ((256 - base_small) / constant)); }
if (weight_large == 0)
{
if (weight_small >= base_small){
weight_small = ( ( (weight_small) - (base_small) ) / constant);}
else
{weight_small = 0;}
}
if (weight_large > 0) { weight_small = ((weight_small) / constant); }
final_weight = (weight_large + weight_small);
if (weight_small != last_status) {
printf("Weight: %d grams \n", final_weight);
}
last_status = weight_small;
}
exit(0);
return 0;
}
Edited code, accuracy seems to match up with a scale on windows.
Rather than continue editing it here i'll keep the newest working at http://kubes.org/src/usbscale.c
Last edited by bkubes; 09-26-2008 at 05:34 PM.
|
|
1 members found this post helpful.
|
02-19-2012, 06:11 PM
|
#29
|
LQ Newbie
Registered: Nov 2006
Distribution: Slackware 11.0
Posts: 4
Rep:
|
works with RadioShack scale on Ubuntu 11.10 64-bit
Thanks @bkubes. I downloaded the source from your website, built it, and it works on my 64-bit machine. Nice job.
Any plans to host this somewhere for others to fork and work from, ala GitHub?
|
|
|
02-24-2012, 10:28 PM
|
#30
|
LQ Newbie
Registered: Sep 2008
Posts: 4
Rep:
|
Thanks lucasrangit. While I love programming I'm still very much a novice..
A while back I found someone who had ported it to python-
http://www.thok.org/intranet/python/usb/README.html
He cleaned up the code some, and some of the variable names are more intuitive.
I don't have any future plans for the code.. perhaps if I can find the scale again.
However, if anyone wants to use / modify the source code they're free to do whatever they like.
Best Regards
|
|
|
All times are GMT -5. The time now is 12:42 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|