Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import usb.core
  2. import usb.util
  3.  
  4. #open printer connection
  5. dev = usb.core.find(idVendor=0x0a5f, idProduct=0x0062)
  6.  
  7. assert dev is not None
  8.  
  9. endpoint = dev[0][(0,0)][0]
  10. dev.set_configuration()
  11.  
  12. # get an endpoint instance
  13. cfg = dev.get_active_configuration()
  14. intf = cfg[(0,0)]
  15.  
  16. # find descriptor
  17. descriptor = usb.util.find_descriptor(intf, custom_match = lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
  18. assert descriptor is not None
  19.  
  20. def exec_command(command):
  21.    descriptor.write(command + chr(0x0D) + chr(0x0A))
  22.    bytes = dev.read(endpoint.bEndpointAddress,endpoint.wMaxPacketSize)
  23.    response = "".join(map(chr, bytes))
  24.    print(response)
  25.  
  26.  
  27. exec_command(descriptor, '! U1 getvar "device.languages"')
  28. exec_command(descriptor, '! U1 getvar "device.pnp_option"')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement