Method: BLE::Device#pair

Defined in:
lib/ble/device.rb

#pairBoolean

This method will connect to the remote device, initiate pairing and then retrieve all SDP records (or GATT primary services). If the application has registered its own agent, then that specific agent will be used. Otherwise it will use the default agent. Only for applications like a pairing wizard it would make sense to have its own agent. In almost all other cases the default agent will handle this just fine. In case there is no application agent and also no default agent present, this method will fail.

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ble/device.rb', line 80

def pair
  block_given? ? @o_dev[I_DEVICE].Pair(&Proc.new) :
                 @o_dev[I_DEVICE].Pair()
  true
rescue DBus::Error => e
  case e.name
  when E_INVALID_ARGUMENTS      then false
  when E_FAILED                 then false
  when E_ALREADY_EXISTS         then true
  when E_AUTH_CANCELED          then raise NotAuthorized
  when E_AUTH_FAILED            then raise NotAuthorized
  when E_AUTH_REJECTED          then raise NotAuthorized
  when E_AUTH_TIMEOUT           then raise NotAuthorized
  when E_AUTH_ATTEMPT_FAILED    then raise NotAuthorized
  else raise ScriptError
  end
end