libusb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/libusb.rb +276 -32
- data/test/test_libusb_descriptors.rb +45 -0
- data/test/test_libusb_keyboard.rb +50 -0
- metadata +16 -25
data/History.txt
CHANGED
data/lib/libusb.rb
CHANGED
@@ -18,7 +18,7 @@ require 'ffi'
|
|
18
18
|
|
19
19
|
|
20
20
|
module LIBUSB
|
21
|
-
VERSION = "0.1.
|
21
|
+
VERSION = "0.1.3"
|
22
22
|
|
23
23
|
module Call
|
24
24
|
extend FFI::Library
|
@@ -235,6 +235,7 @@ module LIBUSB
|
|
235
235
|
Call::RequestRecipients.to_h.each{|k,v| const_set(k,v) }
|
236
236
|
Call::IsoSyncTypes.to_h.each{|k,v| const_set(k,v) }
|
237
237
|
|
238
|
+
# Base class of libusb errors
|
238
239
|
class Error < RuntimeError
|
239
240
|
end
|
240
241
|
ErrorClassForResult = {}
|
@@ -592,6 +593,7 @@ module LIBUSB
|
|
592
593
|
private :actual_length, :actual_buffer
|
593
594
|
end
|
594
595
|
|
596
|
+
# @private
|
595
597
|
class DeviceDescriptor < FFI::Struct
|
596
598
|
include Comparable
|
597
599
|
|
@@ -626,10 +628,61 @@ module LIBUSB
|
|
626
628
|
:extra, :pointer,
|
627
629
|
:extra_length, :int
|
628
630
|
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
631
|
+
# Size of this descriptor (in bytes).
|
632
|
+
def bLength
|
633
|
+
self[:bLength]
|
634
|
+
end
|
635
|
+
|
636
|
+
# Descriptor type (0x02)
|
637
|
+
def bDescriptorType
|
638
|
+
self[:bDescriptorType]
|
639
|
+
end
|
640
|
+
|
641
|
+
# Total length of data returned for this configuration.
|
642
|
+
def wTotalLength
|
643
|
+
self[:wTotalLength]
|
644
|
+
end
|
645
|
+
|
646
|
+
# Number of interfaces supported by this configuration.
|
647
|
+
def bNumInterfaces
|
648
|
+
self[:bNumInterfaces]
|
649
|
+
end
|
650
|
+
|
651
|
+
# Identifier value for this configuration.
|
652
|
+
def bConfigurationValue
|
653
|
+
self[:bConfigurationValue]
|
654
|
+
end
|
655
|
+
|
656
|
+
# Index of string descriptor describing this configuration.
|
657
|
+
def iConfiguration
|
658
|
+
self[:iConfiguration]
|
659
|
+
end
|
660
|
+
|
661
|
+
# Configuration characteristics.
|
662
|
+
#
|
663
|
+
# * Bit 7: Reserved, set to 1. (USB 1.0 Bus Powered)
|
664
|
+
# * Bit 6: Self Powered
|
665
|
+
# * Bit 5: Remote Wakeup
|
666
|
+
# * Bit 4..0: Reserved, set to 0.
|
667
|
+
#
|
668
|
+
# @return [Integer]
|
669
|
+
def bmAttributes
|
670
|
+
self[:bmAttributes]
|
671
|
+
end
|
672
|
+
|
673
|
+
# Maximum power consumption of the USB device from this bus in this configuration when the device is fully opreation.
|
674
|
+
#
|
675
|
+
# @result [Integer] Maximum Power Consumption in 2mA units
|
676
|
+
def maxPower
|
677
|
+
self[:maxPower]
|
678
|
+
end
|
679
|
+
|
680
|
+
# Extra descriptors.
|
681
|
+
#
|
682
|
+
# @return [String]
|
683
|
+
def extra
|
684
|
+
return if self[:extra].null?
|
685
|
+
self[:extra].read_string(self[:extra_length])
|
633
686
|
end
|
634
687
|
|
635
688
|
def initialize(device, *args)
|
@@ -663,15 +716,15 @@ module LIBUSB
|
|
663
716
|
"\#<#{self.class} #{attrs.join(' ')}>"
|
664
717
|
end
|
665
718
|
|
666
|
-
# Return name of
|
719
|
+
# Return name of this configuration as String.
|
667
720
|
def description
|
668
721
|
return @description if defined? @description
|
669
722
|
@description = device.try_string_descriptor_ascii(self.iConfiguration)
|
670
723
|
end
|
671
724
|
|
672
|
-
# Return all interface decriptions of the configuration as Array of
|
725
|
+
# Return all interface decriptions of the configuration as Array of {Setting}s.
|
673
726
|
def settings() self.interfaces.map {|d| d.settings }.flatten end
|
674
|
-
# Return all endpoints of all interfaces of the configuration as Array of
|
727
|
+
# Return all endpoints of all interfaces of the configuration as Array of {Endpoint}s.
|
675
728
|
def endpoints() self.settings.map {|d| d.endpoints }.flatten end
|
676
729
|
|
677
730
|
def <=>(o)
|
@@ -704,9 +757,9 @@ module LIBUSB
|
|
704
757
|
end
|
705
758
|
alias settings alt_settings
|
706
759
|
|
707
|
-
# The Device
|
760
|
+
# The {Device} this Interface belongs to.
|
708
761
|
def device() self.configuration.device end
|
709
|
-
# Return all endpoints of all alternative settings as Array of
|
762
|
+
# Return all endpoints of all alternative settings as Array of {Endpoint}s.
|
710
763
|
def endpoints() self.alt_settings.map {|d| d.endpoints }.flatten end
|
711
764
|
|
712
765
|
def <=>(o)
|
@@ -730,10 +783,57 @@ module LIBUSB
|
|
730
783
|
:extra, :pointer,
|
731
784
|
:extra_length, :int
|
732
785
|
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
786
|
+
# Size of this descriptor (in bytes).
|
787
|
+
def bLength
|
788
|
+
self[:bLength]
|
789
|
+
end
|
790
|
+
|
791
|
+
# Descriptor type (0x04)
|
792
|
+
def bDescriptorType
|
793
|
+
self[:bDescriptorType]
|
794
|
+
end
|
795
|
+
|
796
|
+
# Number of this interface.
|
797
|
+
def bInterfaceNumber
|
798
|
+
self[:bInterfaceNumber]
|
799
|
+
end
|
800
|
+
|
801
|
+
# Value used to select this alternate setting for this interface.
|
802
|
+
def bAlternateSetting
|
803
|
+
self[:bAlternateSetting]
|
804
|
+
end
|
805
|
+
|
806
|
+
# Number of endpoints used by this interface (excluding the control endpoint).
|
807
|
+
def bNumEndpoints
|
808
|
+
self[:bNumEndpoints]
|
809
|
+
end
|
810
|
+
|
811
|
+
# USB-IF class code for this interface.
|
812
|
+
def bInterfaceClass
|
813
|
+
self[:bInterfaceClass]
|
814
|
+
end
|
815
|
+
|
816
|
+
# USB-IF subclass code for this interface, qualified by the {bInterfaceClass} value.
|
817
|
+
def bInterfaceSubClass
|
818
|
+
self[:bInterfaceSubClass]
|
819
|
+
end
|
820
|
+
|
821
|
+
# USB-IF protocol code for this interface, qualified by the {bInterfaceClass} and {bInterfaceSubClass} values.
|
822
|
+
def bInterfaceProtocol
|
823
|
+
self[:bInterfaceProtocol]
|
824
|
+
end
|
825
|
+
|
826
|
+
# Index of string descriptor describing this interface.
|
827
|
+
def iInterface
|
828
|
+
self[:iInterface]
|
829
|
+
end
|
830
|
+
|
831
|
+
# Extra descriptors.
|
832
|
+
#
|
833
|
+
# @return [String]
|
834
|
+
def extra
|
835
|
+
return if self[:extra].null?
|
836
|
+
self[:extra].read_string(self[:extra_length])
|
737
837
|
end
|
738
838
|
|
739
839
|
def initialize(interface, *args)
|
@@ -762,15 +862,15 @@ module LIBUSB
|
|
762
862
|
"\#<#{self.class} #{attrs.join(' ')}>"
|
763
863
|
end
|
764
864
|
|
765
|
-
# Return name of
|
865
|
+
# Return name of this interface as String.
|
766
866
|
def description
|
767
867
|
return @description if defined? @description
|
768
868
|
@description = device.try_string_descriptor_ascii(self.iInterface)
|
769
869
|
end
|
770
870
|
|
771
|
-
# The Device
|
871
|
+
# The {Device} this Setting belongs to.
|
772
872
|
def device() self.interface.configuration.device end
|
773
|
-
# The
|
873
|
+
# The {Configuration} this Setting belongs to.
|
774
874
|
def configuration() self.interface.configuration end
|
775
875
|
|
776
876
|
def <=>(o)
|
@@ -795,10 +895,82 @@ module LIBUSB
|
|
795
895
|
:extra, :pointer,
|
796
896
|
:extra_length, :int
|
797
897
|
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
898
|
+
# Size of Descriptor in Bytes (7 bytes)
|
899
|
+
def bLength
|
900
|
+
self[:bLength]
|
901
|
+
end
|
902
|
+
|
903
|
+
# Descriptor type (0x05)
|
904
|
+
def bDescriptorType
|
905
|
+
self[:bDescriptorType]
|
906
|
+
end
|
907
|
+
|
908
|
+
# The address of the endpoint described by this descriptor.
|
909
|
+
#
|
910
|
+
# * Bits 0..3: Endpoint Number.
|
911
|
+
# * Bits 4..6: Reserved. Set to Zero
|
912
|
+
# * Bits 7: Direction 0 = Out, 1 = In (Ignored for Control Endpoints)
|
913
|
+
#
|
914
|
+
# @return [Integer]
|
915
|
+
def bEndpointAddress
|
916
|
+
self[:bEndpointAddress]
|
917
|
+
end
|
918
|
+
|
919
|
+
# Attributes which apply to the endpoint when it is configured using the {Configuration#bConfigurationValue}.
|
920
|
+
#
|
921
|
+
# * Bits 0..1: Transfer Type
|
922
|
+
# * 00 = Control
|
923
|
+
# * 01 = Isochronous
|
924
|
+
# * 10 = Bulk
|
925
|
+
# * 11 = Interrupt
|
926
|
+
# * Bits 2..7: are reserved. If Isochronous endpoint,
|
927
|
+
# * Bits 3..2: Synchronisation Type (Iso Mode)
|
928
|
+
# * 00 = No Synchonisation
|
929
|
+
# * 01 = Asynchronous
|
930
|
+
# * 10 = Adaptive
|
931
|
+
# * 11 = Synchronous
|
932
|
+
# * Bits 5..4: Usage Type (Iso Mode)
|
933
|
+
# * 00 = Data Endpoint
|
934
|
+
# * 01 = Feedback Endpoint
|
935
|
+
# * 10 = Explicit Feedback Data Endpoint
|
936
|
+
# * 11 = Reserved
|
937
|
+
#
|
938
|
+
# @return [Integer]
|
939
|
+
def bmAttributes
|
940
|
+
self[:bmAttributes]
|
941
|
+
end
|
942
|
+
|
943
|
+
# Maximum Packet Size this endpoint is capable of sending or receiving
|
944
|
+
def wMaxPacketSize
|
945
|
+
self[:wMaxPacketSize]
|
946
|
+
end
|
947
|
+
|
948
|
+
# Interval for polling endpoint data transfers. Value in frame counts.
|
949
|
+
# Ignored for Bulk & Control Endpoints. Isochronous must equal 1 and field
|
950
|
+
# may range from 1 to 255 for interrupt endpoints.
|
951
|
+
#
|
952
|
+
# The interval is respected by the kernel driver, so user mode processes
|
953
|
+
# using libusb don't need to care about it.
|
954
|
+
def bInterval
|
955
|
+
self[:bInterval]
|
956
|
+
end
|
957
|
+
|
958
|
+
# For audio devices only: the rate at which synchronization feedback is provided.
|
959
|
+
def bRefresh
|
960
|
+
self[:bRefresh]
|
961
|
+
end
|
962
|
+
|
963
|
+
# For audio devices only: the address if the synch endpoint.
|
964
|
+
def bSynchAddress
|
965
|
+
self[:bSynchAddress]
|
966
|
+
end
|
967
|
+
|
968
|
+
# Extra descriptors.
|
969
|
+
#
|
970
|
+
# @return [String]
|
971
|
+
def extra
|
972
|
+
return if self[:extra].null?
|
973
|
+
self[:extra].read_string(self[:extra_length])
|
802
974
|
end
|
803
975
|
|
804
976
|
def initialize(setting, *args)
|
@@ -824,11 +996,11 @@ module LIBUSB
|
|
824
996
|
"\#<#{self.class} #{num} #{inout} #{type.join(" ")}>"
|
825
997
|
end
|
826
998
|
|
827
|
-
# The Device
|
999
|
+
# The {Device} this Endpoint belongs to.
|
828
1000
|
def device() self.setting.interface.configuration.device end
|
829
|
-
# The
|
1001
|
+
# The {Configuration} this Endpoint belongs to.
|
830
1002
|
def configuration() self.setting.interface.configuration end
|
831
|
-
# The Interface
|
1003
|
+
# The {Interface} this Endpoint belongs to.
|
832
1004
|
def interface() self.setting.interface end
|
833
1005
|
|
834
1006
|
def <=>(o)
|
@@ -1072,13 +1244,85 @@ module LIBUSB
|
|
1072
1244
|
config
|
1073
1245
|
end
|
1074
1246
|
|
1075
|
-
#
|
1076
|
-
|
1077
|
-
|
1078
|
-
@pDevDesc[member]
|
1079
|
-
end
|
1247
|
+
# Size of the Descriptor in Bytes (18 bytes)
|
1248
|
+
def bLength
|
1249
|
+
@pDevDesc[:bLength]
|
1080
1250
|
end
|
1081
1251
|
|
1252
|
+
# Device Descriptor (0x01)
|
1253
|
+
def bDescriptorType
|
1254
|
+
@pDevDesc[:bDescriptorType]
|
1255
|
+
end
|
1256
|
+
|
1257
|
+
# USB specification release number which device complies too
|
1258
|
+
#
|
1259
|
+
# @return [Integer] in binary-coded decimal
|
1260
|
+
def bcdUSB
|
1261
|
+
@pDevDesc[:bcdUSB]
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
# USB-IF class code for the device (Assigned by USB Org)
|
1265
|
+
#
|
1266
|
+
# * If equal to 0x00, each interface specifies it's own class code
|
1267
|
+
# * If equal to 0xFF, the class code is vendor specified
|
1268
|
+
# * Otherwise field is valid Class Code
|
1269
|
+
def bDeviceClass
|
1270
|
+
@pDevDesc[:bDeviceClass]
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
# USB-IF subclass code for the device, qualified by the {bDeviceClass}
|
1274
|
+
# value (Assigned by USB Org)
|
1275
|
+
def bDeviceSubClass
|
1276
|
+
@pDevDesc[:bDeviceSubClass]
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
# USB-IF protocol code for the device, qualified by the {bDeviceClass}
|
1280
|
+
# and {bDeviceSubClass} values (Assigned by USB Org)
|
1281
|
+
def bDeviceProtocol
|
1282
|
+
@pDevDesc[:bDeviceProtocol]
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
# Maximum Packet Size for Endpoint 0. Valid Sizes are 8, 16, 32, 64
|
1286
|
+
def bMaxPacketSize0
|
1287
|
+
@pDevDesc[:bMaxPacketSize0]
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
# USB-IF vendor ID (Assigned by USB Org)
|
1291
|
+
def idVendor
|
1292
|
+
@pDevDesc[:idVendor]
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
# USB-IF product ID (Assigned by Manufacturer)
|
1296
|
+
def idProduct
|
1297
|
+
@pDevDesc[:idProduct]
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
# Device release number in binary-coded decimal.
|
1301
|
+
def bcdDevice
|
1302
|
+
@pDevDesc[:bcdDevice]
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
# Index of string descriptor describing manufacturer.
|
1306
|
+
def iManufacturer
|
1307
|
+
@pDevDesc[:iManufacturer]
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
# Index of string descriptor describing product.
|
1311
|
+
def iProduct
|
1312
|
+
@pDevDesc[:iProduct]
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
# Index of string descriptor containing device serial number.
|
1316
|
+
def iSerialNumber
|
1317
|
+
@pDevDesc[:iSerialNumber]
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
# Number of Possible Configurations
|
1321
|
+
def bNumConfigurations
|
1322
|
+
@pDevDesc[:bNumConfigurations]
|
1323
|
+
end
|
1324
|
+
|
1325
|
+
|
1082
1326
|
def inspect
|
1083
1327
|
attrs = []
|
1084
1328
|
attrs << "#{self.bus_number}/#{self.device_address}"
|
@@ -1147,13 +1391,13 @@ module LIBUSB
|
|
1147
1391
|
configs
|
1148
1392
|
end
|
1149
1393
|
|
1150
|
-
# Return all interfaces of
|
1394
|
+
# Return all interfaces of this device.
|
1151
1395
|
# @return [Array<Interface>]
|
1152
1396
|
def interfaces() self.configurations.map {|d| d.interfaces }.flatten end
|
1153
|
-
# Return all interface decriptions of
|
1397
|
+
# Return all interface decriptions of this device.
|
1154
1398
|
# @return [Array<Setting>]
|
1155
1399
|
def settings() self.interfaces.map {|d| d.settings }.flatten end
|
1156
|
-
# Return all endpoints of all interfaces of
|
1400
|
+
# Return all endpoints of all interfaces of this device.
|
1157
1401
|
# @return [Array<Endpoint>]
|
1158
1402
|
def endpoints() self.settings.map {|d| d.endpoints }.flatten end
|
1159
1403
|
|
@@ -29,10 +29,36 @@ class TestLibusbDescriptors < Test::Unit::TestCase
|
|
29
29
|
def test_descriptors
|
30
30
|
usb.devices.each do |dev|
|
31
31
|
assert_match(/Device/, dev.inspect, "Device#inspect should work")
|
32
|
+
|
33
|
+
assert_kind_of Integer, dev.bLength
|
34
|
+
assert_equal 1, dev.bDescriptorType
|
35
|
+
assert_kind_of Integer, dev.bcdUSB
|
36
|
+
assert_kind_of Integer, dev.bDeviceClass
|
37
|
+
assert_kind_of Integer, dev.bDeviceSubClass
|
38
|
+
assert_kind_of Integer, dev.bDeviceProtocol
|
39
|
+
assert_kind_of Integer, dev.bMaxPacketSize0
|
40
|
+
assert_kind_of Integer, dev.idVendor
|
41
|
+
assert_kind_of Integer, dev.idProduct
|
42
|
+
assert_kind_of Integer, dev.bcdDevice
|
43
|
+
assert_kind_of Integer, dev.iManufacturer
|
44
|
+
assert_kind_of Integer, dev.iProduct
|
45
|
+
assert_kind_of Integer, dev.iSerialNumber
|
46
|
+
assert_kind_of Integer, dev.bNumConfigurations
|
47
|
+
|
32
48
|
dev.configurations.each do |config_desc|
|
33
49
|
assert_match(/Configuration/, config_desc.inspect, "ConfigDescriptor#inspect should work")
|
34
50
|
assert dev.configurations.include?(config_desc), "Device#configurations should include this one"
|
35
51
|
|
52
|
+
assert_kind_of Integer, config_desc.bLength
|
53
|
+
assert_equal 2, config_desc.bDescriptorType
|
54
|
+
assert_kind_of Integer, config_desc.wTotalLength
|
55
|
+
assert_equal config_desc.interfaces.length, config_desc.bNumInterfaces
|
56
|
+
assert_kind_of Integer, config_desc.bConfigurationValue
|
57
|
+
assert_kind_of Integer, config_desc.iConfiguration
|
58
|
+
assert_kind_of Integer, config_desc.bmAttributes
|
59
|
+
assert_kind_of Integer, config_desc.maxPower
|
60
|
+
assert_kind_of String, config_desc.extra if config_desc.extra
|
61
|
+
|
36
62
|
config_desc.interfaces.each do |interface|
|
37
63
|
assert_match(/Interface/, interface.inspect, "Interface#inspect should work")
|
38
64
|
|
@@ -46,6 +72,17 @@ class TestLibusbDescriptors < Test::Unit::TestCase
|
|
46
72
|
assert config_desc.settings.include?(if_desc), "ConfigDescriptor#settings should include this one"
|
47
73
|
assert interface.alt_settings.include?(if_desc), "Inteerface#alt_settings should include this one"
|
48
74
|
|
75
|
+
assert_kind_of Integer, if_desc.bLength
|
76
|
+
assert_equal 4, if_desc.bDescriptorType
|
77
|
+
assert_kind_of Integer, if_desc.bInterfaceNumber
|
78
|
+
assert_kind_of Integer, if_desc.bAlternateSetting
|
79
|
+
assert_equal if_desc.endpoints.length, if_desc.bNumEndpoints
|
80
|
+
assert_kind_of Integer, if_desc.bInterfaceClass
|
81
|
+
assert_kind_of Integer, if_desc.bInterfaceSubClass
|
82
|
+
assert_kind_of Integer, if_desc.bInterfaceProtocol
|
83
|
+
assert_kind_of Integer, if_desc.iInterface
|
84
|
+
assert_kind_of String, if_desc.extra if if_desc.extra
|
85
|
+
|
49
86
|
if_desc.endpoints.each do |ep|
|
50
87
|
assert_match(/Endpoint/, ep.inspect, "EndpointDescriptor#inspect should work")
|
51
88
|
|
@@ -59,7 +96,15 @@ class TestLibusbDescriptors < Test::Unit::TestCase
|
|
59
96
|
assert_equal config_desc, ep.configuration, "backref should be correct"
|
60
97
|
assert_equal dev, ep.device, "backref should be correct"
|
61
98
|
|
99
|
+
assert_kind_of Integer, ep.bLength
|
100
|
+
assert_equal 5, ep.bDescriptorType
|
101
|
+
assert_kind_of Integer, ep.bEndpointAddress
|
102
|
+
assert_kind_of Integer, ep.bmAttributes
|
62
103
|
assert_operator 0, :<, ep.wMaxPacketSize, "packet size should be > 0"
|
104
|
+
assert_kind_of Integer, ep.bInterval
|
105
|
+
assert_kind_of Integer, ep.bRefresh
|
106
|
+
assert_kind_of Integer, ep.bSynchAddress
|
107
|
+
assert_kind_of String, ep.extra if ep.extra
|
63
108
|
end
|
64
109
|
end
|
65
110
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# This test requires a connected, but not mounted mass storage device with
|
2
|
+
# read/write access allowed. Based on the following specifications:
|
3
|
+
# http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf
|
4
|
+
# http://en.wikipedia.org/wiki/SCSI_command
|
5
|
+
#
|
6
|
+
|
7
|
+
require "test/unit"
|
8
|
+
require "libusb"
|
9
|
+
|
10
|
+
class TestLibusbKeyboard < Test::Unit::TestCase
|
11
|
+
include LIBUSB
|
12
|
+
|
13
|
+
attr_accessor :usb
|
14
|
+
attr_accessor :device
|
15
|
+
attr_accessor :dev
|
16
|
+
attr_accessor :endpoint_in
|
17
|
+
attr_accessor :endpoint_out
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@usb = Context.new
|
21
|
+
@usb.debug = 3
|
22
|
+
|
23
|
+
@device = usb.devices( :bDeviceClass=>CLASS_HID, :bDeviceProtocol=>1 ).first
|
24
|
+
abort "no keyboard device found" unless @device
|
25
|
+
|
26
|
+
@endpoint_in = @device.endpoints.find{|ep| ep.bEndpointAddress&ENDPOINT_IN != 0 }.bEndpointAddress
|
27
|
+
@endpoint_out = @device.endpoints.find{|ep| ep.bEndpointAddress&ENDPOINT_IN == 0 }.bEndpointAddress
|
28
|
+
|
29
|
+
@dev = @device.open
|
30
|
+
|
31
|
+
if RUBY_PLATFORM=~/linux/i && dev.kernel_driver_active?(0)
|
32
|
+
dev.detach_kernel_driver(0)
|
33
|
+
end
|
34
|
+
dev.claim_interface(0)
|
35
|
+
|
36
|
+
# clear any pending data
|
37
|
+
dev.clear_halt(endpoint_in)
|
38
|
+
end
|
39
|
+
|
40
|
+
def teardown
|
41
|
+
dev.release_interface(0) if dev
|
42
|
+
dev.close if dev
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_read
|
46
|
+
data_length = 8
|
47
|
+
recv = dev.interrupt_transfer(:endpoint=>endpoint_in, :dataIn=>data_length)
|
48
|
+
p recv
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libusb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &11238960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11238960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake-compiler
|
27
|
-
requirement: &
|
27
|
+
requirement: &11254720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,29 +32,18 @@ dependencies:
|
|
32
32
|
version: '0.6'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rdoc
|
38
|
-
requirement: &7423680 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '3.10'
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *7423680
|
35
|
+
version_requirements: *11254720
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: hoe
|
49
|
-
requirement: &
|
38
|
+
requirement: &11254160 !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
40
|
requirements:
|
52
41
|
- - ~>
|
53
42
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
43
|
+
version: '2.12'
|
55
44
|
type: :development
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *11254160
|
58
47
|
description: LIBUSB is a Ruby binding that gives Ruby programmers access to all functionality
|
59
48
|
of libusb, version 1.0
|
60
49
|
email:
|
@@ -82,6 +71,7 @@ files:
|
|
82
71
|
- test/test_libusb_iso_transfer.rb
|
83
72
|
- test/test_libusb_mass_storage.rb
|
84
73
|
- test/test_libusb_mass_storage2.rb
|
74
|
+
- test/test_libusb_keyboard.rb
|
85
75
|
homepage: http://github.com/larskanis/libusb
|
86
76
|
licenses: []
|
87
77
|
post_install_message:
|
@@ -105,15 +95,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
95
|
version: '0'
|
106
96
|
requirements: []
|
107
97
|
rubyforge_project: libusb
|
108
|
-
rubygems_version: 1.8.
|
98
|
+
rubygems_version: 1.8.10
|
109
99
|
signing_key:
|
110
100
|
specification_version: 3
|
111
101
|
summary: Access USB devices from Ruby via libusb-1.0
|
112
102
|
test_files:
|
113
|
-
- test/
|
103
|
+
- test/test_libusb_compat_mass_storage.rb
|
104
|
+
- test/test_libusb_gc.rb
|
114
105
|
- test/test_libusb_iso_transfer.rb
|
115
|
-
- test/test_libusb_mass_storage2.rb
|
116
106
|
- test/test_libusb_descriptors.rb
|
107
|
+
- test/test_libusb_compat.rb
|
108
|
+
- test/test_libusb_keyboard.rb
|
109
|
+
- test/test_libusb_mass_storage2.rb
|
117
110
|
- test/test_libusb_mass_storage.rb
|
118
|
-
- test/test_libusb_compat_mass_storage.rb
|
119
|
-
- test/test_libusb_gc.rb
|