Quantcast
Channel: For the record
Viewing all articles
Browse latest Browse all 95

Install pyUSB 1.x latest version

$
0
0

pyUSB is an excellent Python package that can significantly simplify USB programming. For most Linux distributions there are packages only for older versions of pyUSB, but since it is actively developed you probably want to have the latest version on your system.

First of all, make sure one of libusb-0.1, libusb-1.0 or openusb is installed – currently libusb-1.0 is installed as default on most Linux systems.

Download the latest package by visiting the pyUSB website and clicking on the tar.gz folder icon.

If you have an older version of pyUSB already installed, you may want to remove it:

sudo apt-get remove python-usb

Install the Python package manager and then use it to install the freshly downloaded pyUSB package:

sudo apt-get install python-pip
sudo pip install --upgrade ~/Downloads/walac-pyusb-1.0.0b1-52-g452880f.tar.gz

To check that the version you have just installed is accessed by default:

laczik@laptop$ python
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import usb
>>> print usb.__version__
1.0.0b2
>>> exit()

To get help/information, use the built-in help function:

laczik@laptop$ python
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import usb.core
>>> help(usb.core)
[ ... ]
>>> help(usb.core.Device)
[ ... ]
>>> exit()

Finally, an example of how easy USB programming is with pyUSB:

laczik@laptop$ python
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import usb.core
>>> import usb.util
>>> for dev in usb.core.find(find_all=True):
...   print dev
... 
DEVICE ID 04d8:feaa on Bus 007 Address 063 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :   0xff Vendor-specific
 bDeviceSubClass        :   0xff
 bDeviceProtocol        :   0xff
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x04d8
 idProduct              : 0xfeaa
 bcdDevice              :  0x414 Device 4.14
 iManufacturer          :    0x1 RB+AG
 iProduct               :    0x2 P8
 iSerialNumber          :    0x0 
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 250 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x20 (32 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0 
   bmAttributes         :   0xc0 Self Powered
   bMaxPower            :   0x7d (250 mA)
    INTERFACE 0: Vendor Specific ===========================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :   0xff Vendor Specific
     bInterfaceSubClass :   0xff
     bInterfaceProtocol :   0xff
     iInterface         :    0x0 
      ENDPOINT 0x1: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x0
      ENDPOINT 0x81: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x0
DEVICE ID 1d6b:0001 on Bus 007 Address 000 =================
 bLength                :   0x12 (18 bytes)
[ ... detailed list of all other USB devices found ... ]
>>> exit()

Viewing all articles
Browse latest Browse all 95

Trending Articles