Class: USB::DevHandle

Inherits:
Object
  • Object
show all
Defined in:
lib/libusb/compat.rb

Instance Method Summary collapse

Constructor Details

#initialize(dev) ⇒ DevHandle

Returns a new instance of DevHandle.


291
292
293
# File 'lib/libusb/compat.rb', line 291

def initialize(dev)
  @dev = dev
end

Instance Method Details

#get_string_simple(index) ⇒ Object


372
373
374
# File 'lib/libusb/compat.rb', line 372

def get_string_simple(index)
  @dev.string_descriptor_ascii(index)
end

#usb_bulk_read(endpoint, bytes, timeout) ⇒ Object


330
331
332
333
334
# File 'lib/libusb/compat.rb', line 330

def usb_bulk_read(endpoint, bytes, timeout)
  res = @dev.bulk_transfer(endpoint: endpoint, dataIn: bytes.bytesize, timeout: timeout)
  bytes[0, res.bytesize] = res
  res.bytesize
end

#usb_bulk_write(endpoint, bytes, timeout) ⇒ Object


327
328
329
# File 'lib/libusb/compat.rb', line 327

def usb_bulk_write(endpoint, bytes, timeout)
  @dev.bulk_transfer(endpoint: endpoint, dataOut: bytes, timeout: timeout)
end

#usb_claim_interface(c) ⇒ Object Also known as: claim_interface


300
# File 'lib/libusb/compat.rb', line 300

def usb_claim_interface(c); @dev.claim_interface(c); end

#usb_clear_halt(c) ⇒ Object Also known as: clear_halt


298
# File 'lib/libusb/compat.rb', line 298

def usb_clear_halt(c); @dev.clear_halt(c); end

#usb_closeObject


295
# File 'lib/libusb/compat.rb', line 295

def usb_close; @dev.close; end

#usb_control_msg(requesttype, request, value, index, bytes, timeout) ⇒ Object


313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/libusb/compat.rb', line 313

def usb_control_msg(requesttype, request, value, index, bytes, timeout)
  if requesttype&LIBUSB::ENDPOINT_IN != 0
    # transfer direction in
    res = @dev.control_transfer(bmRequestType: requesttype, bRequest: request,
        wValue: value, wIndex: index, dataIn: bytes.bytesize, timeout: timeout)
    bytes[0, res.bytesize] = res
    res.bytesize
  else
    # transfer direction out
    @dev.control_transfer(bmRequestType: requesttype, bRequest: request, wValue: value,
        wIndex: index, dataOut: bytes, timeout: timeout)
  end
end

#usb_detach_kernel_driver_np(interface, dummy = nil) ⇒ Object


349
350
351
# File 'lib/libusb/compat.rb', line 349

def usb_detach_kernel_driver_np(interface, dummy=nil)
  @dev.detach_kernel_driver(interface)
end

#usb_get_driver_np(interface, buffer) ⇒ Object


355
356
357
358
359
360
361
362
363
# File 'lib/libusb/compat.rb', line 355

def usb_get_driver_np(interface, buffer)
  if @dev.kernel_driver_active?(interface)
    t = "unknown driver"
    buffer[0, t.length] = t
  else
    raise Errno::ENODATA, "No data available"
  end
  nil
end

#usb_get_string(index, langid, buffer) ⇒ Object


302
303
304
305
306
# File 'lib/libusb/compat.rb', line 302

def usb_get_string(index, langid, buffer)
  t = @dev.string_descriptor(index, langid)
  buffer[0, t.length] = t
  t.length
end

#usb_get_string_simple(index, buffer) ⇒ Object


307
308
309
310
311
# File 'lib/libusb/compat.rb', line 307

def usb_get_string_simple(index, buffer)
  t = @dev.string_descriptor_ascii(index)
  buffer[0, t.length] = t
  t.length
end

#usb_interrupt_read(endpoint, bytes, timeout) ⇒ Object


339
340
341
342
343
# File 'lib/libusb/compat.rb', line 339

def usb_interrupt_read(endpoint, bytes, timeout)
  res = @dev.interrupt_transfer(endpoint: endpoint, dataIn: bytes.bytesize, timeout: timeout)
  bytes[0, res.bytesize] = res
  res.bytesize
end

#usb_interrupt_write(endpoint, bytes, timeout) ⇒ Object


336
337
338
# File 'lib/libusb/compat.rb', line 336

def usb_interrupt_write(endpoint, bytes, timeout)
  @dev.interrupt_transfer(endpoint: endpoint, dataOut: bytes, timeout: timeout)
end

#usb_release_interface(c) ⇒ Object Also known as: release_interface


301
# File 'lib/libusb/compat.rb', line 301

def usb_release_interface(c); @dev.release_interface(c); end

#usb_resetObject


299
# File 'lib/libusb/compat.rb', line 299

def usb_reset; @dev.reset_device; end

#usb_set_altinterface(c) ⇒ Object Also known as: set_altinterface


297
# File 'lib/libusb/compat.rb', line 297

def usb_set_altinterface(c); @dev.set_interface_alt_setting=c; end

#usb_set_configuration(c) ⇒ Object Also known as: set_configuration


296
# File 'lib/libusb/compat.rb', line 296

def usb_set_configuration(c); @dev.configuration=c; end