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 , time
tm = 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 device
dev = 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 one
dev.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
write
dir(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.py
device 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
------------------------------------------------------------------------------
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