python - Sending data via USB using PyUSB -
i need send data via usb using python, i'm using pyusb (http://sourceforge.net/apps/trac/pyusb/) usb port available, , tried send message:
devlist = usb.core.find(find_all=true) dev in devlist: cfg in dev: intf in cfg: sys.stdout.write('\t' + str(intf.binterfacenumber) + ',' + str(intf.balternatesetting) + '\n') ep in intf: sys.stdout.write('\t\t' + str(ep.bendpointaddress) + '\n') if ep.bendpointaddress: try: dev.write(ep.bendpointaddress, 'test', intf.binterfacenumber) except exception: print "\t\terror : dev.write("+str(ep.bendpointaddress)+", 'test', "+str(intf.binterfacenumber)+")"
the result :
0,0 129 error : dev.write(129, 'test', 0) 0,1 129 error : dev.write(129, 'test', 0) 0,0 136 error : dev.write(136, 'test', 0) 10 error : dev.write(10, 'test', 0) 1,0 139 error : dev.write(139, 'test', 1) 13 error : dev.write(13, 'test', 1)
without try catch gives:
usb.core.usberror: [errno none] usb_claim_interface: not claim interface 0, invalid configuration 0
what wrong? there best way communicate via usb python? because have found lib
as stated in tutorial:
[...] device not work without setting configuration, if has one! [...]
apparently of times there 1 configuration. assuming configurations different devices, can like:
for dev in devlist: cfg in dev: cfg.set() intf in cfg:
if can't set configuration due "resource busy", you'll need unload interface kernel driver:
dev.detatch_kernel_driver(interface)
Comments
Post a Comment