If you go pawing through the /sys/devices/pci0000:00/ directory tree looking
for your device, you should be able to find appropriate endpoints, interfaces,
etc. listed there. lspci -vt and lsusb -v are also useful in narrowing (&
understanding) the search. Checking the USB spec (and the class / subclass
specs for your device) will also help determine which endpoints are appropriate
and whether you should be using bulk read/write or something else. Class driver
availability varies by distribution & version, so figuring out what class
device you're dealing with may also give you options....
>From what I've seen, endpoints are usually referenced by their hex address and
>bmAttributes, so 0x06 ("06", or 6 decimal ) is a bulk-out endpoint and 0x85
>("85" or 133) is a bulk-in endpoint. Typically address and bmAttributes are
>the same, though I don't think that's required by spec. "In" and "Out" are
>from the computer's point of view.
YMMV
-Sarah
--- On Thu, 3/10/11, Nathan Kelhos <nathankel...@gmail.com> wrote:
From: Nathan Kelhos <nathankel...@gmail.com>
Subject: [pyusb-users] beginners USB problem
To: pyusb-users@lists.sourceforge.net
Date: Thursday, March 10, 2011, 9:33 PM
Hi everyone, I have a simple piece of lab equipment that I need to control
with a USB device from an OSX laptop in python, so I'm attempting to use PyUSB.
I've used a sniffer program to figure out most of the commands I need to
send(from the device-maker's windows software), but I'm having trouble writing
and reading to the device from OSX. Below I have a short script, and the
terminal's output from running that code.
script: #!/usr/bin/python
import usb , sys , timetm = time.time()
def CT() : return (time.time()-tm)
if len(sys.argv) != 2 : exit('needs a message to send')
msg = sys.argv[1]print ' %5.3f msg:%s' % ( CT() , repr(msg) )
# find our devicedev = usb.core.find( idVendor=0x0403 , idProduct=0x6001 )
# was it found?if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active onedev.set_configuration()
liss = dir(dev)print 'dir(dev) : '
for i in liss : print '\t',i
print 'dir(dev.write) : \n\t' , dir(dev.write)import inspect
print 'inspect.getsourcefile(dev.write) : \n\t' , inspect.getsourcefile(
dev.write )
print 'device class: \n\t' , dev.bDeviceClass
print '\njust before failure...\n'
print 'write:\n\t%i' % dev.write( 1 , 'p\n\r' , 0 )print 'read:\n\t%s' %
dev.read( 30 )
print ' %5.3f done.' % CT()
terminal output of script:
[nckelley@HawcMobile01 attenuator]$ ./atten adskfj 0.000
msg:'adskfj'dir(dev) : _Device__default_timeout
_Device__get_def_tmo _Device__get_timeout _Device__set_def_tmo
__class__ __del__ __delattr__
__dict__ __doc__ __format__
__getattribute__ __getitem__ __hash__
__init__ __iter__ __module__
__new__ __reduce__ __reduce_ex__
__repr__ __setattr__ __sizeof__
__str__ __subclasshook__ __weakref__
_ctx attach_kernel_driver bDescriptorType
bDeviceClass bDeviceProtocol bDeviceSubClass
bLength bMaxPacketSize0 bNumConfigurations
bcdDevice bcdUSB ctrl_transfer
default_timeout detach_kernel_driver get_active_configuration
iManufacturer iProduct iSerialNumber
idProduct idVendor is_kernel_driver_active
read reset set_configuration
set_interface_altsetting writedir(dev.write) : ['__call__',
'__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__func__',
'__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', 'im_class', 'im_func', 'im_self']
inspect.getsourcefile(dev.write) :
/Library/Python/2.6/site-packages/usb/core.pydevice class: 0
just before failure...
Traceback (most recent call last): File "./atten", line 36, in <module>
print 'write:\n\t%i' % dev.write( 1 , 'p\n\r' , 0 )
File "/Library/Python/2.6/site-packages/usb/core.py", line 594, in write
fn = fn_map[self._ctx.get_endpoint_type(self, endpoint, intf)] File
"/Library/Python/2.6/site-packages/usb/core.py", line 180, in get_endpoint_type
etype = util.endpoint_type(e.bmAttributes)AttributeError: 'NoneType' object
has no attribute 'bmAttributes'
My vague understanding so far makes me think that I'm not using the correct
interface or endpoint, but dont know what the correct ones are ( in
dev.write(), using 1 and 0 were guesses ), or how to find them(this is a very
simple device). Any suggestions on whats gone wrong? Thanks in advance.
- Nathan
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
-----Inline Attachment Follows-----
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users