Skip to content

Instantly share code, notes, and snippets.

@erwincoumans
Created March 29, 2019 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erwincoumans/84aac83d685d74c9dd0df844adcd4d76 to your computer and use it in GitHub Desktop.
Save erwincoumans/84aac83d685d74c9dd0df844adcd4d76 to your computer and use it in GitHub Desktop.
DYMO usb scale reading (multiple scales)
import sys
import usb.core
VENDOR_ID = 0x0922
PRODUCT_ID = 0x8003
# find USB devices
devices = list(usb.core.find(find_all=True, idVendor=VENDOR_ID,
idProduct=PRODUCT_ID))
# loop through devices, printing vendor and product ids in decimal and hex
print("len=",len(devices))
masses=[]
sum=0
for device in devices:
cfg=device
#sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.idProduct) + '\n')
#sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n')
#print("device=",device)
device.set_configuration()
# first endpoint
endpoint = device[0][(0,0)][0]
# read a data packet
attempts = 10
data = None
while data is None and attempts > 0:
try:
data = device.read(endpoint.bEndpointAddress,
endpoint.wMaxPacketSize)
except usb.core.USBError as e:
data = None
if e.args == ('Operation timed out',):
attempts -= 1
continue
#print (data)
mass = data[5]*256+data[4]
sum += mass
masses.append(mass)
#print("mass=",mass)
print("masses=",masses)
print("sum=",sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment