23-04-2021



  • INSTALLATION
    • Prerequisites
      • Windows
  • METHODS/FUNCTIONS
    • Library initialization/deinitialization
    • Device handling and enumeration
    • Miscellaneous
    • USB descriptors
      • get_active_config_descriptor
      • get_bos_descriptor
    • Synchronous device I/O

USB::LibUSB - Perl interface to the libusb-1.0 API.

This module provides a Perl interface to the libusb-1.0 API. It provides access to most basic libusb functionality including read-out of device descriptors and synchronous device I/O.

Staying as close as possible to the libusb-1.0 API, this module adds convenient error handling and additional high-level functionality (e.g. device discovery with vid, pid and serial number). Easy to build more functionality without knowing about XS.

Prerequisites

Download libusb-win32 for free. Libusb-win32 is a port of libusb-0.1 under Windows. Libusb-win32 is a port of the USB. Libusb-win32 device driver and filter driver. LibUsb is the better of the two drivers, but if you require out-of-the-box vista 64 support then WinUSB may be a better choice. For a complete.NET LibUsb/WinUsb driver solution, check out LibUsbDotNet at sourceforge! Write all your application/driver code in.NET. Switch between the two drivers just by using a different usb setup/inf. Libusb 1.0.21 libusb is a C library that provides generic access to USB devices. It is intended to be used by developers to facilitate the production of applications that communicate with USB hardware.

  1. Wrap a platform-specific system device handle and obtain a libusb device handle for the underlying device. The handle allows you to use libusb to perform I/O on the device in question. Must call libusbsetoption(NULL, LIBUSBOPTIONWEAKAUTHORITY) before libusbinit if don't have authority to access the usb device directly.
  2. Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features.

Linux/UNIX

This requires libusb (>= 1.0.17) development files and pkg-config installed.

On Debian like Linux:

On Cygwin you need the pkg-config, libusb1.0-devel and libcrypt-devel packages.

Windows

On Windows you have to manually download the libusb binaries from http://libusb.info and extract them somewhere.

Assuming that the location of the extracted libusb folder is C:Userssimonlibusb-1.0, you need to set the USB_LIBUSB_INCLUDE and USB_LIBUSB_LIB environment variables as follows:

You will also need to add

to the Path environment variable.

For StrawberryPerl, version 5.26 or newer is required (see https://rt.cpan.org/Public/Bug/Display.html?id=121219).

Driver Installation

On Windows you need an additional driver to use a device with libusb. See the Windows section in the libusb wiki.

Building USB::LibUSB

The rest of the installation can be done by a CPAN client like cpanm:

Library initialization/deinitialization

set_debug

init

exit

last_retval

Get return value of last called libusb function.

Device handling and enumeration

get_device_list

Returned elements are USB::LibUSB::Device objects.

get_bus_number

get_port_number

get_port_numbers

get_parent

get_device_address

get_device_speed

get_max_packet_size

get_max_iso_packet_size

ref_device

unref_device

open

Return a USB::LibUSB::Device::Handle object.

open_device_with_vid_pid

Return a USB::LibUSB::Device::Handle object. If the vid:pid combination is not unique, return the first device which is found.

open_device_with_vid_pid_unique

Like open_device_with_vid_pid, but croak in case of multiple devices with this vid:pid combination.

open_device_with_vid_pid_serial

Like open_device_with_vid_pid, but also requires a serial number.

close

get_device

get_configuration

set_configuration

claim_interface

release_interface

set_interface_alt_setting

clear_halt

reset_device

Libusb 1.0 Driver Win 7

kernel_driver_active

detach_kernel_driver

attach_kernel_driver

set_auto_detach_kernel_driver

Throws exception on Windows and Darwin.

Miscellaneous

libusb_has_capability

libusb_error_name

libusb_get_version

Return hashref $version_hash with the following keys:

major
minor
micro
nano
rc

libusb_setlocale

libusb_strerror

USB descriptors

All descriptors are returned as hash references.

get_device_descriptor

Return hashref $desc with the following keys

bLength
bDescriptorType
bcdUSB
bDeviceClass
bDeviceSubClass
bDeviceProtocol
bMaxPacketSize0
idVendor
idProduct
bcdDevice
iManufacturer
iProduct
iSerialNumber
bNumConfigurations

All keys hold a scalar value.

get_active_config_descriptor

Return hashref $config with the following keys:

bLength
bDescriptorType
wTotalLength
bNumInterfaces
bConfigurationValue
iConfiguration
bmAttributes
MaxPower
interface
extra

With the exception of interface, all values are scalars. interface holds an arrayref of bNumInterfaces interface descriptors. Each interface consists of an array of alternate settings. These are hashrefs with the following keys:

bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass
bInterfaceSubClass
bInterfaceProtocol
iInterface
endpoint
extra

With the exception of endpoint, all values are scalars. endpoint holds an arrayref of endpoint descriptors. These are hashrefs with the following keys:

bLength
bDescriptorType
bEndpointAddress
bmAttributes
wMaxPacketSize
bInterval
bRefresh
bSynchAddress
extra

All values are scalars. If the endpoint supports USB 3.0 SuperSpeed, the hashref will contain an additional key superspeed which holds a SuperSpeed Endpoint Companion descriptor with the following keys:

bLength
bDescriptorType
bMaxBurst
bmAttributes
wBytesPerInterval

Example

Dump $config with YAML::XS:

For a Linux Foundation 3.0 root hub:

get_config_descriptor

Return config descriptor as hashref.

get_config_descriptor_by_value

Return config descriptor as hashref.

get_bos_descriptor

Return BOS descriptor as hashref with the following keys:

bLength
bDescriptorType
wTotalLength
bNumDeviceCaps
dev_capability

dev_capability holds an arrayref of BOS Device Capability descriptors. They have the following keys:

bLength
bDescriptorType
bDevCapabilityType
dev_capability_data

Additional parsing of the capability data is performed if bDevCapabilityType has one of the following values:

LIBUSB_BT_USB_2_0_EXTENSION

The hashref will contain a key usb_2_0_extension.

LIBUSB_BT_SS_USB_DEVICE_CAPABILITY

The hashref will contain a key ss_usb_device_capability.

LIBUSB_BT_CONTAINER_ID

The hashref will contain a key container_id.

Example

Dump $bos with YAML::XS:

For a Linux Foundation 3.0 root hub:

get_string_descriptor_ascii

get_descriptor

get_string_descriptor

Device hotplug event notification

To be implemented.

Asynchronous device I/O

To be implemented.

Polling and timing

To be implemented.

Synchronous device I/O

control_transfer_write

control_transfer_read

bulk_tranfer_write

bulk_transfer_read

interrupt_transfer_write

interrupt_transfer_read

Libusb 1.0 Driver

Please report bugs at https://github.com/lab-measurement/USB-LibUSB/issues.

Feel free to contact us at the #labmeasurement channel on Freenode IRC.

Simon Reinhardt, <simon.reinhardt@physik.uni-r.de>

Copyright (C) 2017 by Simon Reinhardt

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.0 or, at your option, any later version of Perl 5 you may have available.

Libusb 1.0 Driver Windows 10

To install USB::LibUSB, copy and paste the appropriate command in to your terminal.

Libusb 1.0 Driver Download

For more information on module installation, please visit the detailed CPAN module installation guide.