Class: USB::Device

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

Overview

:startdoc:

Instance Method Summary collapse

Instance Method Details

#endpointsObject



287
# File 'lib/usb.rb', line 287

def endpoints() self.settings.map {|d| d.endpoints }.flatten end

#inspectObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/usb.rb', line 228

def inspect
  if self.revoked?
    "\#<#{self.class} revoked>"
  else
    attrs = []
    attrs << "#{self.bus.dirname}/#{self.filename}"
    attrs << ("%04x:%04x" % [self.idVendor, self.idProduct])
    attrs << self.manufacturer
    attrs << self.product
    attrs << self.serial_number
    if self.bDeviceClass == USB::USB_CLASS_PER_INTERFACE
      devclass = self.settings.map {|i|
        USB.dev_string(i.bInterfaceClass, i.bInterfaceSubClass, i.bInterfaceProtocol)
      }.join(", ")
    else
      devclass = USB.dev_string(self.bDeviceClass, self.bDeviceSubClass, self.bDeviceProtocol)
    end
    attrs << "(#{devclass})"
    attrs.compact!
    "\#<#{self.class} #{attrs.join(' ')}>"
  end
end

#interfacesObject



285
# File 'lib/usb.rb', line 285

def interfaces() self.configurations.map {|d| d.interfaces }.flatten end

#manufacturerObject



251
252
253
254
255
256
# File 'lib/usb.rb', line 251

def manufacturer
  return @manufacturer if defined? @manufacturer
  @manufacturer = self.open {|h| h.get_string_simple(self.iManufacturer) }
  @manufacturer.strip! if @manufacturer
  @manufacturer
end

#openObject



272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/usb.rb', line 272

def open
  h = self.usb_open
  if block_given?
    begin
      r = yield h
    ensure
      h.usb_close
    end
  else
    h
  end
end

#productObject



258
259
260
261
262
263
# File 'lib/usb.rb', line 258

def product
  return @product if defined? @product
  @product = self.open {|h| h.get_string_simple(self.iProduct) }
  @product.strip! if @product
  @product
end

#serial_numberObject



265
266
267
268
269
270
# File 'lib/usb.rb', line 265

def serial_number
  return @serial_number if defined? @serial_number
  @serial_number = self.open {|h| h.get_string_simple(self.iSerialNumber) }
  @serial_number.strip! if @serial_number
  @serial_number
end

#settingsObject



286
# File 'lib/usb.rb', line 286

def settings() self.interfaces.map {|d| d.settings }.flatten end