lib/hidapi/device.rb
def close
      self.open_count = open_count - 1
      if open_count <= 0
        HIDAPI.debug("open_count for device #{path} is #{open_count}") if open_count < 0
        if handle
          begin
            self.shutdown_thread = true
            transfer.cancel! rescue nil if transfer
            thread.join
          rescue =>e
            HIDAPI.debug "failed to kill read thread on device #{path}: #{e.inspect}"
          end
          begin
            handle.release_interface(interface)
          rescue =>e
            HIDAPI.debug "failed to release interface on device #{path}: #{e.inspect}"
          end
          begin
            handle.close
          rescue =>e
            HIDAPI.debug "failed to close device #{path}: #{e.inspect}"
          end
          HIDAPI.debug "closed device #{path}"
        end
        self.handle = nil
        mutex.synchronize { self.input_reports = [] }
        self.open_count = 0
      end
      self
    end
def close
      self.open_count = open_count - 1
      if open_count <= 0
        HIDAPI.debug("open_count for device #{path} is #{open_count}") if open_count < 0
        if handle
          begin
            self.shutdown_thread = true
            transfer.cancel! rescue nil if transfer
            thread.join
          rescue =>e
            HIDAPI.debug "failed to kill read thread on device #{path}: #{e.inspect}"
          end
          begin
            handle.release_interface(interface)
          rescue =>e
            HIDAPI.debug "failed to release interface on device #{path}: #{e.inspect}"
          end
          begin
            handle.close
          rescue =>e
            HIDAPI.debug "failed to close device #{path}: #{e.inspect}"
          end
          HIDAPI.debug "closed device #{path}"
        end
        self.handle = nil
        mutex.synchronize { self.input_reports = [] }
        self.open_count = 0
      end
      self
    end
Closes the device (if open).

 Returns the device.