Class: SimpleHID::Device
- Inherits:
-
Object
- Object
- SimpleHID::Device
- Defined in:
- lib/simple_hid.rb
Constant Summary collapse
- MAX_STR_LEN =
255
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path) ⇒ Device
constructor
A new instance of Device.
- #manufacturer_string ⇒ Object
- #product_string ⇒ Object
- #serial_number_string ⇒ Object
- #write(byte_array) ⇒ Object
Constructor Details
Instance Method Details
#close ⇒ Object
119 120 121 122 123 |
# File 'lib/simple_hid.rb', line 119 def close return if @handle.nil? SimpleHID.hid_close(@handle) @handle = nil end |
#manufacturer_string ⇒ Object
125 126 127 |
# File 'lib/simple_hid.rb', line 125 def manufacturer_string read_wide_string_with(:hid_get_manufacturer_string) end |
#product_string ⇒ Object
129 130 131 |
# File 'lib/simple_hid.rb', line 129 def product_string read_wide_string_with(:hid_get_product_string) end |
#serial_number_string ⇒ Object
133 134 135 |
# File 'lib/simple_hid.rb', line 133 def serial_number_string read_wide_string_with(:hid_get_serial_number_string) end |
#write(byte_array) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/simple_hid.rb', line 112 def write(byte_array) raise "Device is closed." if @handle.nil? data_string = byte_array.pack('C*') data_ptr = FFI::MemoryPointer.from_string(data_string) SimpleHID.hid_write(@handle, data_ptr, data_string.bytesize) end |