Class: USB::DevHandle
- Inherits:
-
Data
- Object
- Data
- USB::DevHandle
- Defined in:
- lib/usb.rb,
ext/usb/usb.c
Instance Method Summary collapse
- #claim_interface(interface) ⇒ Object
- #clear_halt(ep) ⇒ Object
- #get_string_simple(index) ⇒ Object
- #release_interface(interface) ⇒ Object
- #set_altinterface(alternate) ⇒ Object
- #set_configuration(configuration) ⇒ Object
-
#usb_bulk_read(vep, vbytes, vtimeout) ⇒ Object
USB::DevHandle#usb_bulk_read(endpoint, bytes, timeout).
-
#usb_bulk_write(vep, vbytes, vtimeout) ⇒ Object
USB::DevHandle#usb_bulk_write(endpoint, bytes, timeout).
-
#usb_claim_interface(interface) ⇒ Object
USB::DevHandle#usb_claim_interface(interface).
-
#usb_clear_halt(ep) ⇒ Object
USB::DevHandle#usb_clear_halt(endpoint).
-
#usb_close ⇒ Object
USB::DevHandle#usb_close.
-
#usb_control_msg(vrequesttype, vrequest, vvalue, vindex, vbytes, vtimeout) ⇒ Object
USB::DevHandle#usb_control_msg(requesttype, request, value, index, bytes, timeout).
-
#usb_detach_kernel_driver_np(vinterface) ⇒ Object
USB::DevHandle#usb_detach_kernel_driver_np(interface).
-
#usb_get_descriptor(vtype, vindex, vbuf) ⇒ Object
USB::DevHandle#usb_get_descriptor(type, index, buf).
-
#usb_get_descriptor_by_endpoint(vep, vtype, vindex, vbuf) ⇒ Object
USB::DevHandle#usb_get_descriptor_by_endpoint(endpoint, type, index, buf).
-
#usb_get_driver_np(vinterface, vname) ⇒ Object
USB::DevHandle#usb_get_driver_np(interface, name).
-
#usb_get_string(vindex, vlangid, vbuf) ⇒ Object
USB::DevHandle#usb_get_string(index, langid, buf).
-
#usb_get_string_simple(vindex, vbuf) ⇒ Object
USB::DevHandle#usb_get_string_simple(index, buf).
-
#usb_interrupt_read(vep, vbytes, vtimeout) ⇒ Object
USB::DevHandle#usb_interrupt_read(endpoint, bytes, timeout).
-
#usb_interrupt_write(vep, vbytes, vtimeout) ⇒ Object
USB::DevHandle#usb_interrupt_write(endpoint, bytes, timeout).
-
#usb_release_interface(interface) ⇒ Object
USB::DevHandle#usb_release_interface(interface).
-
#usb_reset ⇒ Object
USB::DevHandle#usb_reset.
-
#usb_set_altinterface(alternate) ⇒ Object
USB::DevHandle#usb_set_altinterface(alternate).
-
#usb_set_configuration(configuration) ⇒ Object
USB::DevHandle#usb_set_configuration(configuration).
Instance Method Details
#claim_interface(interface) ⇒ Object
401 402 403 404 |
# File 'lib/usb.rb', line 401 def claim_interface(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber self.usb_claim_interface(interface) end |
#clear_halt(ep) ⇒ Object
396 397 398 399 |
# File 'lib/usb.rb', line 396 def clear_halt(ep) ep = ep.bEndpointAddress if ep.respond_to? :bEndpointAddress self.usb_clear_halt(ep) end |
#get_string_simple(index) ⇒ Object
411 412 413 414 415 416 417 418 419 420 |
# File 'lib/usb.rb', line 411 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
406 407 408 409 |
# File 'lib/usb.rb', line 406 def release_interface(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber self.usb_release_interface(interface) end |
#set_altinterface(alternate) ⇒ Object
391 392 393 394 |
# File 'lib/usb.rb', line 391 def set_altinterface(alternate) alternate = alternate.bAlternateSetting if alternate.respond_to? :bAlternateSetting self.usb_set_altinterface(alternate) end |
#set_configuration(configuration) ⇒ Object
386 387 388 389 |
# File 'lib/usb.rb', line 386 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)
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
# File 'ext/usb/usb.c', line 691 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)
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'ext/usb/usb.c', line 669 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)
528 529 530 531 532 533 534 535 |
# File 'ext/usb/usb.c', line 528 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)
507 508 509 510 511 512 513 514 |
# File 'ext/usb/usb.c', line 507 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 ⇒ Object
USB::DevHandle#usb_close
477 478 479 480 481 482 483 484 |
# File 'ext/usb/usb.c', line 477 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)
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'ext/usb/usb.c', line 548 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)
783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'ext/usb/usb.c', line 783 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)
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'ext/usb/usb.c', line 621 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)
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'ext/usb/usb.c', line 644 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)
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 |
# File 'ext/usb/usb.c', line 760 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)
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'ext/usb/usb.c', line 577 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)
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'ext/usb/usb.c', line 600 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)
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
# File 'ext/usb/usb.c', line 736 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)
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
# File 'ext/usb/usb.c', line 714 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)
538 539 540 541 542 543 544 545 |
# File 'ext/usb/usb.c', line 538 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 ⇒ Object
USB::DevHandle#usb_reset
517 518 519 520 521 522 523 524 525 |
# File 'ext/usb/usb.c', line 517 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)
497 498 499 500 501 502 503 504 |
# File 'ext/usb/usb.c', line 497 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)
487 488 489 490 491 492 493 494 |
# File 'ext/usb/usb.c', line 487 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; } |