Python 使用Brecknell标尺的多重可再现误差
我正在使用python和PyUSB从usb秤上获取重量。这是我的密码Python 使用Brecknell标尺的多重可再现误差,python,usb,pyusb,Python,Usb,Pyusb,我正在使用python和PyUSB从usb秤上获取重量。这是我的密码 import sys import usb.core import usb.util from reports import \ ReportFactory, STATUSES, ZERO_WEIGHT, STABLE_WEIGHT, DATA_REPORT device = usb.core.find(idVendor=0x67b, idProduct=0x2303) if device is None:
import sys
import usb.core
import usb.util
from reports import \
ReportFactory, STATUSES, ZERO_WEIGHT, STABLE_WEIGHT, DATA_REPORT
device = usb.core.find(idVendor=0x67b, idProduct=0x2303)
if device is None:
raise ValueError('Device Not Found')
if device.is_kernel_driver_active(0) is True:
device.detach_kernel_driver(0)
usb.util.claim_interface(device, 0)
device.set_configuration()
collected = 0
attempts = 50
while collected < attempts:
ret = device.read(0x2,0x0040)
sret=''.join([chr(x) for x in ret])
print "Return Raw: ",ret
print "Return : ", sret
print ReportFactory.build(ret)
# release the device
usb.util.release_interface(device, 0)
device.attach_kernel_driver(0)
导入系统
导入usb.core
导入usb.util
从报告导入\
报告工厂、状态、零权重、稳定权重、数据报告
device=usb.core.find(idVendor=0x67b,idProduct=0x2303)
如果设备为无:
raise VALUERROR('未找到设备')
如果device.is_kernel_driver_active(0)为True:
设备.分离内核驱动程序(0)
usb.util.claim_接口(设备,0)
设备。设置_配置()
已收集=0
尝试次数=50次
在收集尝试时:
ret=设备读取(0x2,0x0040)
sret=''.join([chr(x)表示ret中的x])
打印“返回原始:”,返回
打印“退货:”,sret
打印ReportFactory.build(ret)
#释放设备
usb.util.release_接口(设备,0)
设备。附加内核驱动程序(0)
第一次运行此程序时,出现资源繁忙错误
我得到的第二次运行操作在第五次转储时超时
之后的后续运行会导致立即超时
这里发生了几件事
kernel\u驱动程序if语句应该处理它
任何帮助都将不胜感激 好的,任何人如果想使用PyUSB从GP100 Brecknell磅秤中获取任何东西,请切换到PySerial。由于这是市场上最便宜的USB电子秤之一,我猜这些信息将帮助很多人 我通过电子邮件向制造商索取文档,他们向我发送了一些有价值的串行协议信息 如果将scale的协议设置为7010,则可以使用如下所示的python代码
import time
import serial
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=2400,
bytesize=8,
parity='N',
stopbits=2
)
while 1:
x = ser.read(100)
print(x)
这将流式传输8字节的数据
- 第一个字节是可以解释的状态信息
- 第2-4位
- 第5-8位
- 可以安全地忽略字节2和3
- 字节4-8具有权重信息,由字符0-9表示(例如00023=2.3磅)。该秤的精度仅为+-0.6磅,不适用于盎司,可能使用相同串行控制器的其他型号使用oz功能。PG100没有