好消息是,这种便宜的厦门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)