Module: LIBUSB

Defined in:
lib/libusb.rb,
lib/libusb/bos.rb,
lib/libusb/call.rb,
lib/libusb/stdio.rb,
lib/libusb/device.rb,
lib/libusb/context.rb,
lib/libusb/setting.rb,
lib/libusb/endpoint.rb,
lib/libusb/transfer.rb,
lib/libusb/constants.rb,
lib/libusb/interface.rb,
lib/libusb/dev_handle.rb,
lib/libusb/gem_helper.rb,
lib/libusb/version_gem.rb,
lib/libusb/dependencies.rb,
lib/libusb/eventmachine.rb,
lib/libusb/ss_companion.rb,
lib/libusb/configuration.rb,
lib/libusb/libusb_recipe.rb,
lib/libusb/version_struct.rb,
lib/libusb/context_reference.rb

Overview

This file is part of Libusb for Ruby.

Libusb for Ruby is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Libusb for Ruby is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Libusb for Ruby. If not, see <www.gnu.org/licenses/>.

Defined Under Namespace

Modules: Call, Stdio Classes: Bos, BulkStreamTransfer, BulkTransfer, Configuration, Context, ControlTransfer, CrossLibrary, DevHandle, Device, Endpoint, Error, GemHelper, Interface, InterruptTransfer, IsoPacket, IsochronousTransfer, LibusbRecipe, RemainingReferencesError, Setting, SsCompanion, Transfer, Version

Constant Summary collapse

CONTROL_SETUP_SIZE =
8
DT_DEVICE_SIZE =
18
DT_CONFIG_SIZE =
9
DT_INTERFACE_SIZE =
9
DT_ENDPOINT_SIZE =
7
DT_ENDPOINT_AUDIO_SIZE =

Audio extension

9
DT_HUB_NONVAR_SIZE =
7
ENDPOINT_ADDRESS_MASK =

in bEndpointAddress

0x0f
ENDPOINT_DIR_MASK =
0x80
TRANSFER_TYPE_MASK =

in bmAttributes

0x03
ISO_SYNC_TYPE_MASK =
0x0C
ISO_USAGE_TYPE_MASK =
0x30
POLLIN =
1
POLLOUT =
4
HOTPLUG_MATCH_ANY =

Wildcard matching for hotplug events.

-1
VERSION =

Library version of libusb for Ruby

"0.7.2"
LIBUSB_VERSION =
ENV['LIBUSB_VERSION'] || '1.0.27'
LIBUSB_SOURCE_URI =
"https://github.com/libusb/libusb/releases/download/v#{LIBUSB_VERSION}/libusb-#{LIBUSB_VERSION}.tar.bz2"
LIBUSB_SOURCE_SHA256 =
'ffaa41d741a8a3bee244ac8e54a72ea05bf2879663c098c82fc5757853441575'
MINI_PORTILE_VERSION =
'~> 2.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dev_string(base_class, sub_class, protocol) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/libusb/constants.rb', line 159

def self.dev_string(base_class, sub_class, protocol)
  if desc = CLASS_CODES_HASH3[[base_class, sub_class, protocol]]
    desc
  elsif desc = CLASS_CODES_HASH2[[base_class, sub_class]]
    desc + " (%02x)" % [protocol]
  elsif desc = CLASS_CODES_HASH1[base_class]
    desc + " (%02x,%02x)" % [sub_class, protocol]
  else
    "Unknown(%02x,%02x,%02x)" % [base_class, sub_class, protocol]
  end
end

.raise_error(res, text) ⇒ Object

Raises:

  • (klass)


70
71
72
73
# File 'lib/libusb/constants.rb', line 70

def self.raise_error(res, text)
  klass = ErrorClassForResult[res]
  raise klass, "#{klass} #{text}"
end

Instance Method Details

#has_capability?(capability) ⇒ Boolean

Check at runtime if the loaded library has a given capability. Available since libusb-1.0.9.

Parameters:

  • capability (Symbol)

    the Capabilities symbol to check for

Returns:

  • (Boolean)

    true if the running library has the capability, false otherwise



51
52
53
54
# File 'lib/libusb.rb', line 51

def has_capability?(capability)
  r = Call.libusb_has_capability(capability)
  return r != 0
end

#set_option(option, *args) ⇒ Object

Set an default option in the libusb library.

Use this function to configure a specific option within the library. See option list.

Some options require one or more arguments to be provided. Consult each option’s documentation for specific requirements.

The option will be added to a list of default options that will be applied to all subsequently created contexts.

Available since libusb-1.0.22, LIBUSB_API_VERSION >= 0x01000106

Available since libusb-1.0.22

Parameters:

  • option (Symbol, Fixnum)
  • args

    Zero or more arguments depending on option



123
124
125
126
127
# File 'lib/libusb.rb', line 123

def set_option(option, *args)
  ffi_args = option_args_to_ffi(option, args, self)
  res = Call.libusb_set_option(nil, option, *ffi_args)
  LIBUSB.raise_error res, "in libusb_set_option" if res<0
end

#set_options(options = {}) ⇒ Object

Convenience function to set default options in the libusb library.

Use this function to configure any number of options within the library. It takes a Hash the same way as given to LIBUSB::Context#initialize. See also option list.

Available since libusb-1.0.22, LIBUSB_API_VERSION >= 0x01000106

Parameters:

  • options (Hash{Call::Options => Object}) (defaults to: {})

    Option hash

See Also:



139
140
141
142
143
# File 'lib/libusb.rb', line 139

def set_options(options={})
  options.each do |k, v|
    set_option(k, *Array(v))
  end
end

#versionVersion

Get version of the underlying libusb library. Available since libusb-1.0.10.

Returns:



41
42
43
# File 'lib/libusb.rb', line 41

def version
  Version.new(Call.libusb_get_version)
end