class USB::DevHandle

Public Instance Methods

claim_interface(interface) click to toggle source
# File lib/usb.rb, line 399
def claim_interface(interface)
  interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber
  self.usb_claim_interface(interface)
end
clear_halt(ep) click to toggle source
# File lib/usb.rb, line 394
def clear_halt(ep)
  ep = ep.bEndpointAddress if ep.respond_to? :bEndpointAddress
  self.usb_clear_halt(ep)
end
get_string_simple(index) click to toggle source
# File lib/usb.rb, line 409
def get_string_simple(index)
  result = "\0" * 1024
  begin
    self.usb_get_string_simple(index, result)
  rescue Errno::EPIPE, Errno::EFBIG, Errno::EPERM
    return nil
  end
  result.delete!("\0")
  result
end
release_interface(interface) click to toggle source
# File lib/usb.rb, line 404
def release_interface(interface)
  interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber
  self.usb_release_interface(interface)
end
set_altinterface(alternate) click to toggle source
# File lib/usb.rb, line 389
def set_altinterface(alternate)
  alternate = alternate.bAlternateSetting if alternate.respond_to? :bAlternateSetting
  self.usb_set_altinterface(alternate)
end
set_configuration(configuration) click to toggle source
# File lib/usb.rb, line 384
def set_configuration(configuration)
  configuration = configuration.bConfigurationValue if configuration.respond_to? :bConfigurationValue
  self.usb_set_configuration(configuration)
end
usb_bulk_read(p1, p2, p3) click to toggle source

#usb_bulk_read(endpoint, bytes, timeout)

static VALUE
rusb_bulk_read(
  VALUE v,
  VALUE vep,
  VALUE vbytes,
  VALUE vtimeout)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ep = NUM2INT(vep);
  int timeout = NUM2INT(vtimeout);
  char *bytes;
  int size;
  int ret;
  StringValue(vbytes);
  rb_str_modify(vbytes);
  bytes = RSTRING_PTR(vbytes);
  size = RSTRING_LEN(vbytes);
  ret = usb_bulk_read(p, ep, bytes, size, timeout);
  check_usb_error("usb_bulk_read", ret);
  return INT2NUM(ret);
}
usb_bulk_write(p1, p2, p3) click to toggle source

#usb_bulk_write(endpoint, bytes, timeout)

static VALUE
rusb_bulk_write(
  VALUE v,
  VALUE vep,
  VALUE vbytes,
  VALUE vtimeout)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ep = NUM2INT(vep);
  int timeout = NUM2INT(vtimeout);
  char *bytes;
  int size;
  int ret;
  StringValue(vbytes);
  bytes = RSTRING_PTR(vbytes);
  size = RSTRING_LEN(vbytes);
  ret = usb_bulk_write(p, ep, bytes, size, timeout);
  check_usb_error("usb_bulk_write", ret);
  return INT2NUM(ret);
}
usb_claim_interface(p1) click to toggle source

#usb_claim_interface

static VALUE
rusb_claim_interface(VALUE v, VALUE interface)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_claim_interface(p, NUM2INT(interface));
  check_usb_error("usb_claim_interface", ret);
  return Qnil;
}
usb_clear_halt(p1) click to toggle source

#usb_clear_halt

static VALUE
rusb_clear_halt(VALUE v, VALUE ep)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_clear_halt(p, NUM2UINT(ep));
  check_usb_error("usb_clear_halt", ret);
  return Qnil;
}
usb_close() click to toggle source

#usb_close

static VALUE
rusb_close(VALUE v)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  check_usb_error("usb_close", usb_close(p));
  DATA_PTR(v) = NULL;
  return Qnil;
}
usb_control_msg(p1, p2, p3, p4, p5, p6) click to toggle source

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

static VALUE
rusb_control_msg(
  VALUE v,
  VALUE vrequesttype,
  VALUE vrequest,
  VALUE vvalue,
  VALUE vindex,
  VALUE vbytes,
  VALUE vtimeout)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int requesttype = NUM2INT(vrequesttype);
  int request = NUM2INT(vrequest);
  int value = NUM2INT(vvalue);
  int index = NUM2INT(vindex);
  int timeout = NUM2INT(vtimeout);
  char *bytes;
  int size;
  int ret;
  StringValue(vbytes);
  rb_str_modify(vbytes);
  bytes = RSTRING_PTR(vbytes);
  size = RSTRING_LEN(vbytes);
  ret = usb_control_msg(p, requesttype, request, value, index, bytes, size, timeout);
  check_usb_error("usb_control_msg", ret);
  return INT2NUM(ret);
}
usb_detach_kernel_driver_np(p1) click to toggle source

#usb_detach_kernel_driver_np

static VALUE
rusb_detach_kernel_driver_np(
  VALUE v,
  VALUE vinterface)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int interface = NUM2INT(vinterface);
  int ret;
  ret = usb_detach_kernel_driver_np(p, interface);
  check_usb_error("usb_detach_kernel_driver_np", ret);
  return Qnil;
}
usb_get_descriptor(p1, p2, p3) click to toggle source

#usb_get_descriptor(type, index, buf)

static VALUE
rusb_get_descriptor(
  VALUE v,
  VALUE vtype,
  VALUE vindex,
  VALUE vbuf)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int type = NUM2INT(vtype);
  int index = NUM2INT(vindex);
  char *buf;
  int buflen;
  int ret;
  StringValue(vbuf);
  rb_str_modify(vbuf);
  buf = RSTRING_PTR(vbuf);
  buflen = RSTRING_LEN(vbuf);
  ret = usb_get_descriptor(p, type, index, buf, buflen);
  check_usb_error("usb_get_descriptor", ret);
  return INT2NUM(ret);
}
usb_get_descriptor_by_endpoint(p1, p2, p3, p4) click to toggle source

#usb_get_descriptor_by_endpoint(endpoint, type, index, buf)

static VALUE
rusb_get_descriptor_by_endpoint(
  VALUE v,
  VALUE vep,
  VALUE vtype,
  VALUE vindex,
  VALUE vbuf)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ep = NUM2INT(vep);
  int type = NUM2INT(vtype);
  int index = NUM2INT(vindex);
  char *buf;
  int buflen;
  int ret;
  StringValue(vbuf);
  rb_str_modify(vbuf);
  buf = RSTRING_PTR(vbuf);
  buflen = RSTRING_LEN(vbuf);
  ret = usb_get_descriptor_by_endpoint(p, ep, type, index, buf, buflen);
  check_usb_error("usb_get_descriptor_by_endpoint", ret);
  return INT2NUM(ret);
}
usb_get_driver_np(p1, p2) click to toggle source

#usb_get_driver_np(interface, name)

static VALUE
rusb_get_driver_np(
  VALUE v,
  VALUE vinterface,
  VALUE vname)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int interface = NUM2INT(vinterface);
  char *name;
  int namelen;
  int ret;
  StringValue(vname);
  rb_str_modify(vname);
  name = RSTRING_PTR(vname);
  namelen = RSTRING_LEN(vname);
  ret = usb_get_driver_np(p, interface, name, namelen);
  check_usb_error("usb_get_driver_np", ret);
  return Qnil;
}
usb_get_string(p1, p2, p3) click to toggle source

#usb_get_string(index, langid, buf)

static VALUE
rusb_get_string(
  VALUE v,
  VALUE vindex,
  VALUE vlangid,
  VALUE vbuf)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int index = NUM2INT(vindex);
  int langid = NUM2INT(vlangid);
  char *buf;
  int buflen;
  int ret;
  StringValue(vbuf);
  rb_str_modify(vbuf);
  buf = RSTRING_PTR(vbuf);
  buflen = RSTRING_LEN(vbuf);
  ret = usb_get_string(p, index, langid, buf, buflen);
  check_usb_error("usb_get_string", ret);
  return INT2NUM(ret);
}
usb_get_string_simple(p1, p2) click to toggle source

#usb_get_string_simple(index, buf)

static VALUE
rusb_get_string_simple(
  VALUE v,
  VALUE vindex,
  VALUE vbuf)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int index = NUM2INT(vindex);
  char *buf;
  int buflen;
  int ret;
  StringValue(vbuf);
  rb_str_modify(vbuf);
  buf = RSTRING_PTR(vbuf);
  buflen = RSTRING_LEN(vbuf);
  ret = usb_get_string_simple(p, index, buf, buflen);
  check_usb_error("usb_get_string_simple", ret);
  return INT2NUM(ret);
}
usb_interrupt_read(p1, p2, p3) click to toggle source

#usb_interrupt_read(endpoint, bytes, timeout)

static VALUE
rusb_interrupt_read(
  VALUE v,
  VALUE vep,
  VALUE vbytes,
  VALUE vtimeout)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ep = NUM2INT(vep);
  int timeout = NUM2INT(vtimeout);
  char *bytes;
  int size;
  int ret;
  StringValue(vbytes);
  rb_str_modify(vbytes);
  bytes = RSTRING_PTR(vbytes);
  size = RSTRING_LEN(vbytes);
  ret = usb_interrupt_read(p, ep, bytes, size, timeout);
  check_usb_error("usb_interrupt_read", ret);
  return INT2NUM(ret);
}
usb_interrupt_write(p1, p2, p3) click to toggle source

#usb_interrupt_write(endpoint, bytes, timeout)

static VALUE
rusb_interrupt_write(
  VALUE v,
  VALUE vep,
  VALUE vbytes,
  VALUE vtimeout)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ep = NUM2INT(vep);
  int timeout = NUM2INT(vtimeout);
  char *bytes;
  int size;
  int ret;
  StringValue(vbytes);
  bytes = RSTRING_PTR(vbytes);
  size = RSTRING_LEN(vbytes);
  ret = usb_interrupt_write(p, ep, bytes, size, timeout);
  check_usb_error("usb_interrupt_write", ret);
  return INT2NUM(ret);
}
usb_release_interface(p1) click to toggle source

#usb_release_interface

static VALUE
rusb_release_interface(VALUE v, VALUE interface)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_release_interface(p, NUM2INT(interface));
  check_usb_error("usb_release_interface", ret);
  return Qnil;
}
usb_reset() click to toggle source

#usb_reset

static VALUE
rusb_reset(VALUE v)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_reset(p);
  check_usb_error("usb_reset", ret);
  /* xxx: call usb_close? */
  return Qnil;
}
usb_set_altinterface(p1) click to toggle source

#usb_set_altinterface

static VALUE
rusb_set_altinterface(VALUE v, VALUE alternate)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_set_altinterface(p, NUM2INT(alternate));
  check_usb_error("usb_set_altinterface", ret);
  return Qnil;
}
usb_set_configuration(p1) click to toggle source

#usb_set_configuration

static VALUE
rusb_set_configuration(VALUE v, VALUE configuration)
{
  usb_dev_handle *p = get_usb_devhandle(v);
  int ret = usb_set_configuration(p, NUM2INT(configuration));
  check_usb_error("usb_set_configuration", ret);
  return Qnil;
}