Module: Adept::LowLevel::DeviceManager
- Extended by:
- Library
- Defined in:
- lib/adept/low_level/device_manager.rb
Overview
DeviceManager (DMGR) Wrapper for the low-level Adept device management functionality.
Class Method Summary collapse
-
.close_device(handle) ⇒ Object
Closes the device which is referenced by the given interface handle.
-
.free_device_list ⇒ Object
Free the internal list of connected devices.
-
.get_device_info(device_number) ⇒ Object
Returns a single record from the internal device enumeration list.
-
.get_transport_name(transport_id) ⇒ Object
Returns the transport name for a given transport ID (“DTP”).
-
.open_device(path) ⇒ Object
Opens the device at the given path, and returns an interface handle.
-
.populate_device_list ⇒ Object
Populate the internal list of connected devices.
Methods included from Library
Class Method Details
.close_device(handle) ⇒ Object
Closes the device which is referenced by the given interface handle.
134 135 136 |
# File 'lib/adept/low_level/device_manager.rb', line 134 def self.close_device(handle) Close(handle) end |
.free_device_list ⇒ Object
Free the internal list of connected devices.
53 54 55 |
# File 'lib/adept/low_level/device_manager.rb', line 53 def self.free_device_list FreeDvcEnum() end |
.get_device_info(device_number) ⇒ Object
Returns a single record from the internal device enumeration list. This record contains low-level information about how to connect to the device.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/adept/low_level/device_manager.rb', line 72 def self.get_device_info(device_number) #Create a new, empty low-level device structure. device = Device.new #Get the device's information from the internal enumeration table. GetDvc(device_number, device.pointer) #And return the newly-fetched device object as a ruby hash. device.to_h end |
.get_transport_name(transport_id) ⇒ Object
Returns the transport name for a given transport ID (“DTP”).
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/adept/low_level/device_manager.rb', line 88 def self.get_transport_name(transport_id) #Create a string buffer for the transport's name... string_pointer = FFI::MemoryPointer.new(TransportMaxLength) #... and fill it with the relevant transport's description. GetDtpString(transport_id, string_pointer) #Return the retrieved string. string_pointer.read_string end |
.open_device(path) ⇒ Object
Opens the device at the given path, and returns an interface handle.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/adept/low_level/device_manager.rb', line 114 def self.open_device(path) #Create a pointer to a new C long. handle_pointer = FFI::MemoryPointer.new(:ulong) #Open the device at the given path, retrieving the newly-created device handle. Open(handle_pointer, path) #Dereference the handle pointer, retrieving the handle itself. handle = handle_pointer.get_ulong(0) #If we recieved a handle of zero (C's NULL), convert that to nil; #otherwise, return the handle directly. handle.zero?() ? nil : handle end |
.populate_device_list ⇒ Object
Populate the internal list of connected devices. Returns the total amount of devices enumerated.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/adept/low_level/device_manager.rb', line 37 def self.populate_device_list #Create a pointer to a new C integer. count_pointer = FFI::MemoryPointer.new(:int) #Enumerate all of the connected devices, and retrieve the amount of enumerated devices. EnumDevices(count_pointer) #Dereference the count pointer, extracting the number of devices present. count_pointer.get_int(0) end |