Class: USB::DevHandle

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

Instance Method Summary collapse

Instance Method Details

#claim_interface(interface) ⇒ Object



399
400
401
402
# 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) ⇒ Object



394
395
396
397
# 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) ⇒ Object



409
410
411
412
413
414
415
416
417
418
# 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) ⇒ Object



404
405
406
407
# 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) ⇒ Object



389
390
391
392
# 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) ⇒ Object



384
385
386
387
# 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(vep, vbytes, vtimeout) ⇒ Object

USB::DevHandle#usb_bulk_read(endpoint, bytes, timeout)



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'ext/usb.c', line 687

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(vep, vbytes, vtimeout) ⇒ Object

USB::DevHandle#usb_bulk_write(endpoint, bytes, timeout)



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
# File 'ext/usb.c', line 665

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(interface) ⇒ Object

USB::DevHandle#usb_claim_interface(interface)



524
525
526
527
528
529
530
531
# File 'ext/usb.c', line 524

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(ep) ⇒ Object

USB::DevHandle#usb_clear_halt(endpoint)



503
504
505
506
507
508
509
510
# File 'ext/usb.c', line 503

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_closeObject

USB::DevHandle#usb_close



473
474
475
476
477
478
479
480
# File 'ext/usb.c', line 473

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(vrequesttype, vrequest, vvalue, vindex, vbytes, vtimeout) ⇒ Object

USB::DevHandle#usb_control_msg(requesttype, request, value, index, bytes, timeout)



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'ext/usb.c', line 544

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(vinterface) ⇒ Object

USB::DevHandle#usb_detach_kernel_driver_np(interface)



779
780
781
782
783
784
785
786
787
788
789
790
# File 'ext/usb.c', line 779

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(vtype, vindex, vbuf) ⇒ Object

USB::DevHandle#usb_get_descriptor(type, index, buf)



617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'ext/usb.c', line 617

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(vep, vtype, vindex, vbuf) ⇒ Object

USB::DevHandle#usb_get_descriptor_by_endpoint(endpoint, type, index, buf)



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'ext/usb.c', line 640

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(vinterface, vname) ⇒ Object

USB::DevHandle#usb_get_driver_np(interface, name)



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'ext/usb.c', line 756

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(vindex, vlangid, vbuf) ⇒ Object

USB::DevHandle#usb_get_string(index, langid, buf)



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'ext/usb.c', line 573

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(vindex, vbuf) ⇒ Object

USB::DevHandle#usb_get_string_simple(index, buf)



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'ext/usb.c', line 596

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(vep, vbytes, vtimeout) ⇒ Object

USB::DevHandle#usb_interrupt_read(endpoint, bytes, timeout)



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'ext/usb.c', line 732

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(vep, vbytes, vtimeout) ⇒ Object

USB::DevHandle#usb_interrupt_write(endpoint, bytes, timeout)



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'ext/usb.c', line 710

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(interface) ⇒ Object

USB::DevHandle#usb_release_interface(interface)



534
535
536
537
538
539
540
541
# File 'ext/usb.c', line 534

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_resetObject

USB::DevHandle#usb_reset



513
514
515
516
517
518
519
520
521
# File 'ext/usb.c', line 513

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(alternate) ⇒ Object

USB::DevHandle#usb_set_altinterface(alternate)



493
494
495
496
497
498
499
500
# File 'ext/usb.c', line 493

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(configuration) ⇒ Object

USB::DevHandle#usb_set_configuration(configuration)



483
484
485
486
487
488
489
490
# File 'ext/usb.c', line 483

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;
}