I was looking for some documetation on pyusb . Found this link and tried to use Lennart Renegro's answer.
import usb
in python shell on IDLE gave me the following error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import usb
ImportError: No module named 'usb'
However, I ran this program using python first.py
on bash:
import usb
dev = usb.core.find(idVendor = 0xfffe, idProduct = 0x0001)
if dev is None:
raise ValueError('Device not found')
dev.set_configuration()
cfg = dev.get_active_configuration()
interface_number = cfg[(0,0)].bInterfaceNumber
alternate_setting = usb.control.get_interface(interface_number)
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number, bAlternateSetting = alternate_setting)
ep = usb.util.find.descriptor(intf, custom_match = lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
assert ep is not None
ep.write('test')
and bash return the following error(which I was expecting because I hadn't connected any usb devices atm):
Traceback (most recent call last):
File "first.py", line 6, in <module>
raise ValueError('Device not found')
ValueError: Device not found
What is happening here? And how do I read those docs?
Summarizing the discussion above, apparently the python versions of IDLE and the default python shell are different. You installed pyusb
for python 2.7.5, while you want to use it on IDLE which runs python 3.3.2.
To fix this problem, either
pyusb
for python 3.3.2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.