Using Bluetooth
The RTL provides classes to implement Bluetooth support in your applications. When your application is running on a Bluetooth-enabled device, your application can use the Bluetooth capabilities of the device to connect to applications in remote devices and exchange data with those remote applications.
Contents
Platform Support
*Windows Server does not support Bluetooth (see: General Bluetooth Support in Windows).
For macOS and iOS, BluetoothLE is only supported on the following hardware:
- macOS:
- Mac Mini
- Mac Air: mid2011+
- MacBook Pro: mid2012+
- iOS:
- iPhone 4S+
- iPad 3+ (Retina)
- iPod Touch 5th Gen.+
Classic Bluetooth on iOS
RTL does not support Classic Bluetooth on iOS. The reason is that only hardware manufacturers are given access to the SDK for Classic Bluetooth. For more information, see Apple Developers: MFi Program.
Classic Bluetooth vs Bluetooth Low Energy
Image by the the Bluetooth SIG.
Classic Bluetooth
- Useful for applications with data streaming because it achieves greater throughput than Bluetooth LE technology.
- Data transfer rate : 2Mbps.
- High power consumption. Not suitable for certain devices such as wereables.
- Commonly used on cars, Handsfree profile.
- Technology based on standard Bluetooth profiles (SPP, DUN, PAN).
- The protocol is limited up to 7 slaves.
Bluetooth Low Energy
- Useful for applications that require periodic transfer of small amounts of data.
- Data transfer rate : < 100 kbps.
- Very low power consumption, ensured by a set of technical and radio techniques.
- Technology based on the Generic Attribute Profile.
- Supports a large number of slaves.
- Less connection time, no pairing process. Bluetooth LE just needs to connect to the device to read/write information.
Topics
See Also
Connect via Bluetooth with Delphi XE7 using portable printer
I’m trying to communicate with a Sewoo LK-P32 printer via Bluetooth. For this, I am using Delphi XE7. I made a few examples that come with Delphi and am not having success. I put the paired printer on tablet and even then I am not able to print continuously. When I print something have to restart the application, so I can print something again. Below my sources. Could someone help me? Support on this issue? My time is short to try other technologies. Method that initiates communication with the printer
procedure TForm2.ButtonClickStart(Sender: TObject); var Msg, Texto: string; I, B: Integer; BluetoothAdapter: TBluetoothAdapter; ListaDeAparelhosPareados: TBluetoothDeviceList; LServices: TBluetoothServiceList; begin try Memo1.Lines.Add('Ponto 1'); FBluetoothManager := TBluetoothManager.Current; if FBluetoothManager = nil then Memo1.Lines.Add('FBluetoothManager esta nulo'); Memo1.Lines.Add('Ponto 2'); BluetoothAdapter := FBluetoothManager.CurrentAdapter; if BluetoothAdapter = nil then Memo1.Lines.Add('BluetoothAdapter esta nulo'); ListaDeAparelhosPareados := BluetoothAdapter.PairedDevices; Memo1.Lines.Add('Ponto 3'); if ListaDeAparelhosPareados = nil then Memo1.Lines.Add('ListaDeAparelhosPareados esta nulo'); for I := 0 to ListaDeAparelhosPareados.Count - 1 do begin LDevice := ListaDeAparelhosPareados[I] as TBluetoothDevice; if LDevice.IsPaired then begin LServices := LDevice.GetServices; for B := 0 to LServices.Count - 1 do begin ServiceGUI := GUIDToString(LServices[B].UUID); Guid := LServices[B].UUID; ServiceName := LServices[B].Name; Memo1.Lines.Add(LServices[B].Name + ' --> ' + ServiceGUI); Memo1.GoToTextEnd; end; end; end; except on E: Exception do begin Msg := E.Message; Memo1.Lines.Add('Erro ao Conectar na Impressora: ' + Msg); Memo1.GoToTextEnd; end; end; end;
procedure TForm2.ButtonClickSendText(Sender: TObject); var FSocket: TBluetoothSocket; ToSend: TBytes; Msg, Texto: String; begin try Memo1.Lines.Add('Aparelho pareado:' + BoolToStr(LDevice.IsPaired)); Memo1.Lines.Add('Dados do Guid:' + GUIDToString(Guid)); FSocket := LDevice.CreateClientSocket(Guid, true); if FSocket = nil then Memo1.Lines.Add('FSocket nulo'); Memo1.Lines.Add('Criou Bluetooth Cliente.'); Memo1.GoToTextEnd; if FSocket <> nil then begin // FSocket.Connect; FSocket.Connect; Memo1.Lines.Add('Criou socket cliente com o ServerSocket'); Texto := #27 + '|cA' + 'Teste' + #13#10; ToSend := TEncoding.UTF8.GetBytes(Texto); FSocket.SendData(ToSend); Memo1.Lines.Add('Enviou ' + Texto + ' para a impressora.'); end else begin Memo1.Lines.Add('FSocket nulo.'); end; except on E: Exception do begin Msg := E.Message; Memo1.Lines.Add('Erro ao Conectar na Impressora: ' + Msg); Memo1.GoToTextEnd; end; end; end;