Page 1 of 1
How to read data from HID device?
Posted: Sun Jan 26, 2014 9:05 pm
by anze87
I am new at Raspberry and Python, so I will be very glad if you help me at my problem. I need to read some data from weight scale when button on scale is pressed. When I connected this scale via USB on PC, I saw that it works as HID. When I press the button, data are written as string in some text edit document for example.
So, now I am going to connect this scale on Raspberry Pi to read and manipulate with data. Can you give me some code example, advice, which library I need to import? I want to write a script, that waits for incomming data and then something do with it. Thanks for help.
Re: How to read data from HID device?
Posted: Sun Jan 26, 2014 10:13 pm
by joan
What happens when you plug it into a Pi and press a button?
Re: How to read data from HID device?
Posted: Sun Jan 26, 2014 10:32 pm
by FLYFISH TECHNOLOGIES
Hi,
anze87 wrote:data are written as string in some text edit document for example.
It seems that the weight scale represents itself as a standard HID keyboard.
In order to read its output, your software needs have focus and you read data 100% equally as when you type the values on your keyboard.
Best wishes, Ivan Zilic.
Re: How to read data from HID device?
Posted: Tue Jan 28, 2014 4:33 pm
by anze87
I finaly find time to moving forward. I try to read data, and it works just like from keyboard.
This works:
I also try like this, but failed:
Code: Select all
f = open('/dev/hidraw0', 'rb')
buffer = f.read(8)
I don't know why incomming data are different in win8 and in Linux. For example, in Win I get string "G + 12.34 g" in Linux just "1234 ". When I read string data, I remove whitespaces with split() method, so I get just "1234". Because scale has fixed two decimal numbers, it's not a problem to divide with 100. But it becomes a problem, when result from weight is negative, and I can't know that. Does anybody know, what could be the reason for that? The result is the same, if I just open text editor and press button on scale, so I don't think it is problem in reading...
Thanks!
Re: How to read data from HID device?
Posted: Tue Jan 28, 2014 6:26 pm
by Richard-TX
Usually when a weight comes up negative, it means that it is either in overload, there was a weight on the scale when it was powered up (tare weight) , or there is an error. Try power cycling the scale with nothing on it and see if the negative values go away.
Re: How to read data from HID device?
Posted: Tue Jan 28, 2014 7:15 pm
by anze87
Yes, I understand that. But I can't figure it out why in Win is received data different than in my Raspberry. In Win I get sign (+) or (-) and decimal dot (.) and unit (g). In Raspberry I get just numbers and spaces after numbers, without anything. What would cause that, any ideas to check?
Re: How to read data from HID device?
Posted: Tue Jan 28, 2014 7:48 pm
by FLYFISH TECHNOLOGIES
Hi,
anze87 wrote:What would cause that, any ideas to check?
Weird... I first thought about NumLock,... but this doesn't explain behavior well...
Do you have a chance to sniff USB communication ?
Best wishes, Ivan Zilic.
Re: How to read data from HID device?
Posted: Tue Jan 28, 2014 9:09 pm
by anze87
Do you mean with some kind of software? Isn't USB very complex protocol?
Re: How to read data from HID device?
Posted: Tue Jan 28, 2014 9:41 pm
by FLYFISH TECHNOLOGIES
Hi,
anze87 wrote:Do you mean with some kind of software? Isn't USB very complex protocol?
There are also some software-only sniffers. Since I worked with hardware-based only so far, I cannot write much about these software tools... Anyway, check this:
http://biot.com/blog/usb-sniffing-on-linux
Best wishes, Ivan Zilic.
Re: How to read data from HID device?
Posted: Thu Jan 30, 2014 8:21 pm
by anze87
It was very stupid problem. I had wrong keyboard emulation settings on scale. Now it works, as it should. Thanks for help!
Re: How to read data from HID device?
Posted: Thu Jun 25, 2015 8:51 am
by LeeAlexander
I'm interested in using the Pi to read scales, could you tell me what scales you used?
Regards
Lee
Re: How to read data from HID device?
Posted: Fri Jun 26, 2015 6:29 am
by ghp
Hello,
some time ago I connected a barcode scanner to raspberry, using my python scratchClient software and scratch.
I wanted to avoid the problem, that HID input is accepted only when the program runs in foreground.
http://heppg.de/ikg/wordpress/?p=390
Although the target here is to connect this to scratch, the python code is straightforward and you find it in scratchClient/src/adapter/usbAdapter.py
Regards,
Gerhard