hid - how to tare a cheap load cell scale thru Python HIDAPI? -


the news cheap xiamen elane.net load cell powers-up on usb report 3 mode; barfing current weight in grams, constantly.

here's datasheet:

http://www.elane.net/usbscales/list_usb_digital_load_cell_commands_and_data_format_user.pdf

i can read standard pyusb calls. sample read scale...

http://www.orangecoat.com/how-to/read-and-decode-data-from-your-mouse-using-this-pyusb-hack

... if replace device lookup usb.core.find(idvendor=0x7b7c, idproduct=0x301)

(i abuse sudo run program, bc decline muck around device permissions, , sudo easy on raspberry pi.)

using standard pyusb calls, can read scale's spew this:

device.read(endpoint.bendpointaddress, endpoint.wmaxpacketsize) 

that returns 6 byte array:

 +--------------------- report type  |  +------------------ weight stable (tray not moving)  |  |  +--------------- grams (not pounds)  |  |  |  +------------ whatever  |  |  |  |  +--------- 2 grams  |  |  |  |  |  +------ 0 x 256 grams  |  |  |  |  |  |  v  v  v  v  v  v [3, 4, 2, 0, 2, 0] 

now fun starts when try send commands scale. command zero-out current weight (zero weight, aka "tare") might 7 4 2 0 0 0.

if use sample code https://github.com/walac/pyusb/blob/master/docs/tutorial.rst find endpoint_out endpoint, , write using either of these lines, can't tare:

# ep_out.write('\x07\x04\x02\x00\x00\x00', 6) ep_out.write([0x07, 0x04, 0x02, 0x00, 0x00, 0x00], 6) 

(the symptom is, can put load on load cell, weigh above .read() line, tare, not 0 when .read() again.)

okay, we're not dead yet. haven't tried hidapi. apt-get me libusbhid-common, cython-dev, libusb-dev, libusb-1.0.0-dev, , libudev-dev, , upgrade hidapi c example code attempt tare:

handle = hid_open(0x7b7c, 0x301, null); buf[0] = 0x07;  buf[1] = 0x04; buf[2] = 0x02; res = hid_write(handle, buf, 3); 

and tares.

to replicate 1 success in python (despite how tempting rewriting 1 small layer of app in c++ is!), whip out cython-hidapi (presumably git://github.com/signal11/hidapi.git), , upgrade try.py example code:

h = hid.device() h.open(0x7b7c, 0x301)  print("manufacturer: %s" % h.get_manufacturer_string()) print("product: %s" % h.get_product_string()) print("serial no: %s" % h.get_serial_number_string())  res = h.write([0x07, 0x04, 0x02, 0,0,0]) 

guess what? last line not tare. tare if run 3 times!

res = h.write([0x07, 0x04, 0x02, 0,0,0]) res = h.write([0x07, 0x04, 0x02, 0,0,0]) res = h.write([0x07, 0x04, 0x02, 0,0,0]) 

so, before write loop calls tare line on , on until read returns level zero, check math , suggest shortcut? raw pyusb solution work great, too.

i did few little hid programs in python on last weeks, pyusb , seem work reliably.

did check if write command issue prompts reply? in case have read that. initialization code:

def claimed(self):     self.hdev = ucore.find(idvendor = vid, idproduct = pid)      #pdb.set_trace()     if self.hdev.is_kernel_driver_active(0):         print "kernel driver active."         self.hdev.detach_kernel_driver(0)         print self.hdev      self.hdev.set_configuration()     print "config set"     self.cfg = self.hdev.get_active_configuration()      return true 

after that, it's

self.hdev.write(endpoint.bendpointaddress, self.data) 

and

self.data = self.hdev.read(endpoint.bendpointaddress, 64, 64) 

as necessary. selfs there because function , statements part of class handles peripheral, , share hdev variable.

edit: pdf refer downloads 1 page, , command 7,4,2,0,0,0 not documented in there. there more complete information available?

also, found few indication might of use you. according article, there no need interrogate scales continuously:

http://www.elane.net/usermanuals/usb%20interface%20protocol%20%285-kg%20model%29.pdf

and according following article, seems necessary interrogate several times (up 10), suspect may have conversion time of ad. article dymo scale, protocol seems similar:

http://steventsnyder.com/reading-a-dymo-usb-scale-using-python/


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -