好消息是厦门这么便宜ELANE.NET称重传感器通过USB进入Report 3模式;不断以克表示其当前重量。
这是它的数据表:
我可以通过标准pyusb通话阅读。这个样本可以读取秤...
...如果您将设备搜索替换为usb.core.find(idVendor=0x7b7c, idProduct=0x301)
(我也滥用sudo程序运行程序,因为我拒绝考虑设备权限,而且sudo在Raspberry Pi上去容易。
使用标准pyusb呼叫,我可以这样读秤的喷嘴:
device.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize)
返回6字节数组:
--------------------- 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]
现在,当我试图向秤发送命令时,乐趣开始了。将当前重量归零的命令(零重量,又称皮重)可能是7 4 2 0 0 0。
# ep_out.write('\x07\x04\x02\x00\x00\x00', 6)
ep_out.write([0x07, 0x04, 0x02, 0x00, 0x00, 0x00], 6)
(症状是,我可以在我的称重传感器上放一个负载,使用它.read()线称重,然后去皮,再次不为零.read()。)
嗯,我们还没死。我们还没有尝试过任何东西。HIDAPI。所以我apt-get我一些libusbhid-common,有的cython-dev,有的libusb-dev,有的libusb-1.0.0-dev,有的libudev-dev,我升级HIDAPI C例程代码试图皮重:
handle = hid_open(0x7b7c, 0x301, NULL);
buf[0] = 0x07;
buf[1] = 0x04;
buf[2] = 0x02;
res = hid_write(handle, buf, 3);
那子。
为了在Python复制我的成功(尽管用C 重写一小层我的应用程序有多诱人!),我鞭打了一些Cython-hidapi(大概来自git://github.com/signal11/hidapi.git),并升级了try.py示例代码:
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])
你猜怎么了?最后一行不剥皮。但是,如果我运行三次,它真的很轻!
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])
所以,有人能检查我的数学,提出快捷的方法,直到我写一个反复调用去皮重线读回零级的循环吗?pyusb解决方案也可以很好地工作。
解决方案
在过去的几周里,我只用了pyusb在Python中做了一些HID他们的工作似乎很可靠。
你检查过你发送的信息吗?write命令是否提示答复?在这种情况下,您必须阅读此内容。这是初始化代码:
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 is 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
在那之后,
self.hdev.write(endpoint.bEndpointAddress, self.data)
和
self.data = self.hdev.read(endpoint.bEndpointAddress, 64, 64)
必要的selfs共享外围设备子是其处理的外围设备的一部分,共享hdev变量。
编辑:你指的PDF只下载一页,命令7、4、2、0、0、0没有记录在其中。是否有更完整的信息可用?
另外,我发现了一些可能对你有用的指示。根据本文的介绍,无需连续询问量表:
根据下面的文章,似乎有必要进行多次询问(最多10次),我怀疑这可能与AD转换时间有关。本文是关于Dymo但协议似乎有些相似: