Good call on checking the interfaces more carefully. It turns out interface
0 is not being used at all and I updated the c accordingly.
For clarity I simplified and combined all the c into one file. I verified
it compiles and that the binary dumps temperature from my device properly
after multiple disconnects/reconnects:
http://pastie.org/3354572
>From learning that only interface 1 is used I updated the python as follows:
------------------
import usb.core
dev = usb.core.find(idVendor=0x0c45,idProduct=0x7401)
if dev.is_kernel_driver_active(1):
dev.detach_kernel_driver(1)
dev.set_configuration()
request = ''.join([chr(x) for x in
[0x01,0x80,0x33,0x01,0x00,0x00,0x00,0x00]])
dev.ctrl_transfer(0x21,9,0x200,0x1,request,8)
ret = dev.read(0x82,8,1,500)
print(ret)
------------------
I now get a Resource Busy error:
------------------
Traceback (most recent call last):
File "temper1.py", line 9, in <module>
dev.set_configuration()
File
"/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/core.py",
line 530, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File
"/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/core.py",
line 92, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File
"/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/_debug.py",
line 52, in do_trace
return f(*args, **named_args)
File
"/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/backend/libusb10.py",
line 455, in set_configuration
_check(_lib.libusb_set_configuration(dev_handle, config_value))
File
"/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/backend/libusb10.py",
line 357, in _check
raise USBError(_str_error[retval.value])
usb.core.USBError: Resource busy
-------------------
On Fri, Feb 10, 2012 at 7:19 AM, Wander Lairson Costa <
wander.lair...@gmail.com> wrote:
> 2012/2/10 Lance R. Vick <la...@lrvick.net>:
> > Hello all.
> >
> > So I have some working c code for a temperature Temper1v1.1 usb
> temperature
> > sensor I recently bought: http://pastie.org/3354037
> >
> > But I want to port this to using pure python via pyusb.
> >
> > Based on the working c code I came up with the following:
> >
>
> I don't know why your c code is working, because you didn't claim the
> interfaces.
>
> > ------------
> >
> > import usb.core
> >
> > dev = usb.core.find(idVendor=0x0c45,idProduct=0x7401)
> >
> > if dev.is_kernel_driver_active(0):
> > dev.detach_kernel_driver(0)
> > dev.detach_kernel_driver(1)
> >
> > dev.set_configuration()
> >
> > request = ''.join([chr(x) for x in
> > [0x01,0x80,0x33,0x01,0x00,0x00,0x00,0x00]])
> >
> > dev.ctrl_transfer(0x21,9,0x200,0x1,request,8)
> >
> > ret = dev.read(0x82,8,0)
> >
> > print(ret)
> >
> > ------------
> >
> > However, this fails with the following Traceback
> >
> > ------------
> >
> >
> > Traceback (most recent call last):
> > File
> >
> "/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/core.py",
> > line 177, in get_endpoint_type
> > return self._ep_type_map[key]
> > KeyError: (130, 0, 0)
> >
> > During handling of the above exception, another exception occurred:
> >
> > Traceback (most recent call last):
> > File "temper1.py", line 15, in <module>
> > ret = dev.read(0x82,8,0)
> > File
> >
> "/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/core.py",
> > line 629, in read
> > fn = fn_map[self._ctx.get_endpoint_type(self, endpoint, intf)]
> > File
> >
> "/home/lrvick/.virtualenvs/temper1/lib/python3.2/site-packages/usb/core.py",
> > line 180, in get_endpoint_type
> > etype = util.endpoint_type(e.bmAttributes)
> > AttributeError: 'NoneType' object has no attribute 'bmAttributes'
> >
> > ------------
> >
> >
> > Clearly I am doing something wrong but I have no idea what to try next.
> Any
> > ideas?
> >
>
> There is only one thing that I can imagine: endpoint 0x82 belongs to
> interface 1, not interface 0. Furthermore, can you can that the
> interface numbers are 0 and 1? It is often the case, but not a rule.
>
> --
> Best Regards,
> Wander Lairson Costa
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> pyusb-users mailing list
> pyusb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>
--
Lance R. Vick
__________________________________________________
Cell - 407.283.7596
Gtalk - la...@lrvick.net
Website - http://lrvick.net
PGP Key - http://lrvick.net/0x36C8AAA9.asc
keyserver - subkeys.pgp.net
__________________________________________________
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users