Class: USB::Device

Inherits:
Data
  • Object
show all
Defined in:
lib/usb.rb,
ext/usb.c

Overview

:startdoc:

Instance Method Summary collapse

Instance Method Details

#bcdDeviceObject

USB::Device#descriptor_bcdDevice



231
# File 'ext/usb.c', line 231

static VALUE rusb_devdesc_bcdDevice(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bcdDevice); }

#bcdUSBObject

USB::Device#descriptor_bcdUSB



210
# File 'ext/usb.c', line 210

static VALUE rusb_devdesc_bcdUSB(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bcdUSB); }

#bDescriptorTypeObject

USB::Device#descriptor_bDescriptorType



207
# File 'ext/usb.c', line 207

static VALUE rusb_devdesc_bDescriptorType(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDescriptorType); }

#bDeviceClassObject

USB::Device#descriptor_bDeviceClass



213
# File 'ext/usb.c', line 213

static VALUE rusb_devdesc_bDeviceClass(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceClass); }

#bDeviceProtocolObject

USB::Device#descriptor_bDeviceProtocol



219
# File 'ext/usb.c', line 219

static VALUE rusb_devdesc_bDeviceProtocol(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceProtocol); }

#bDeviceSubClassObject

USB::Device#descriptor_bDeviceSubClass



216
# File 'ext/usb.c', line 216

static VALUE rusb_devdesc_bDeviceSubClass(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceSubClass); }

#bLengthObject

USB::Device#descriptor_bLength



204
# File 'ext/usb.c', line 204

static VALUE rusb_devdesc_bLength(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bLength); }

#bMaxPacketSize0Object

USB::Device#descriptor_bMaxPacketSize0



222
# File 'ext/usb.c', line 222

static VALUE rusb_devdesc_bMaxPacketSize0(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bMaxPacketSize0); }

#bNumConfigurationsObject

USB::Device#descriptor_bNumConfigurations



243
# File 'ext/usb.c', line 243

static VALUE rusb_devdesc_bNumConfigurations(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bNumConfigurations); }

#busObject

USB::Device#bus



182
# File 'ext/usb.c', line 182

static VALUE rusb_device_bus(VALUE v) { return rusb_bus_make(get_usb_device(v)->bus, Qnil); }

#childrenObject

USB::Device#children



191
192
193
194
195
196
197
198
199
200
201
# File 'ext/usb.c', line 191

static VALUE
rusb_device_children(VALUE vdevice)
{
  rusb_device_t *d = get_rusb_device(vdevice);
  struct usb_device *device = d->ptr;
  int i;
  VALUE children = rb_ary_new2(device->num_children);
  for (i = 0; i < device->num_children; i++)
    rb_ary_store(children, i, rusb_device_make(device->children[i], d->parent));
  return children;
}

#configurationsObject

USB::Device#configurations



246
247
248
249
250
251
252
253
254
255
# File 'ext/usb.c', line 246

static VALUE
rusb_device_config(VALUE v)
{
  struct usb_device *device = get_usb_device(v);
  int i;
  VALUE children = rb_ary_new2(device->descriptor.bNumConfigurations);
  for (i = 0; i < device->descriptor.bNumConfigurations; i++)
    rb_ary_store(children, i, rusb_config_descriptor_make(&device->config[i], v));
  return children;
}

#devnumObject

USB::Device#devnum



185
# File 'ext/usb.c', line 185

static VALUE rusb_device_devnum(VALUE v) { return INT2FIX(get_usb_device(v)->devnum); }

#endpointsObject



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

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

#filenameObject

USB::Device#filename



179
# File 'ext/usb.c', line 179

static VALUE rusb_device_filename(VALUE v) { return rb_str_new2(get_usb_device(v)->filename); }

#idProductObject

USB::Device#descriptor_idProduct



228
# File 'ext/usb.c', line 228

static VALUE rusb_devdesc_idProduct(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.idProduct); }

#idVendorObject

USB::Device#descriptor_idVendor



225
# File 'ext/usb.c', line 225

static VALUE rusb_devdesc_idVendor(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.idVendor); }

#iManufacturerObject

USB::Device#descriptor_iManufacturer



234
# File 'ext/usb.c', line 234

static VALUE rusb_devdesc_iManufacturer(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iManufacturer); }

#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

#iProductObject

USB::Device#descriptor_iProduct



237
# File 'ext/usb.c', line 237

static VALUE rusb_devdesc_iProduct(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iProduct); }

#iSerialNumberObject

USB::Device#descriptor_iSerialNumber



240
# File 'ext/usb.c', line 240

static VALUE rusb_devdesc_iSerialNumber(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iSerialNumber); }

#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

#nextObject

USB::Device#next



176
# File 'ext/usb.c', line 176

static VALUE rusb_device_next(VALUE v) { rusb_device_t *device = get_rusb_device(v); return rusb_device_make(device->ptr->next, device->parent); }

#num_childrenObject

USB::Device#num_children



188
# File 'ext/usb.c', line 188

static VALUE rusb_device_num_children(VALUE v) { return INT2FIX(get_usb_device(v)->num_children); }

#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

#prevObject

USB::Device#prev



173
# File 'ext/usb.c', line 173

static VALUE rusb_device_prev(VALUE v) { rusb_device_t *device = get_rusb_device(v); return rusb_device_make(device->ptr->prev, device->parent); }

#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

#revoked?Boolean

USB::Bus#revoked?

Returns:

  • (Boolean)


166
167
168
169
170
# File 'ext/usb.c', line 166

static VALUE
rusb_device_revoked_p(VALUE v)
{
  return RTEST(!check_usb_device(v));
}

#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

#usb_openObject

USB::Device#usb_open



258
259
260
261
262
263
264
# File 'ext/usb.c', line 258

static VALUE
rusb_device_open(VALUE vdevice)
{
  struct usb_device *device = get_usb_device(vdevice);
  usb_dev_handle *h = usb_open(device);
  return rusb_dev_handle_new(h);
}