How can I list Bluetooth radios/devices with Delphi?

When working with Bluetooth under Delphi, it might be handy to list all connected Bluetooth devices to a certain Bluetooth radio (host device). So the question is:

How can I list Bluetooth radios/devices with Delphi?

Answers


This can be done via the JEDI API JwaBluetoothAPIs (find it here: http://sourceforge.net/projects/jedi-apilib/) and the following snippet:

uses
  JwaBluetoothAPIs;

procedure ScanBluetoothRadiosDevices;
var
  RadioHandle, DeviceFindHandle: THandle;
  FindHandle: HBLUETOOTH_RADIO_FIND;
  BtFrp: TBlueToothFindRadioParams;
  RadioInfo: BLUETOOTH_RADIO_INFO;
  DeviceInfo: BLUETOOTH_DEVICE_INFO;
  DeviceSearchParams: BLUETOOTH_DEVICE_SEARCH_PARAMS;
  Err : integer;
begin
  // specify record sizes
  BtFrp.dwSize := SizeOf(BtFrp);
  DeviceInfo.dwSize := SizeOf(DeviceInfo);
  RadioInfo.dwSize := SizeOf(RadioInfo);

  FindHandle := BluetoothFindFirstRadio(@BtFrp, RadioHandle);
  if (FindHandle = 0) then
    RaiseLastOSError;

  repeat
    BluetoothEnableDiscovery(RadioHandle, True);
    if BluetoothGetRadioInfo(RadioHandle, RadioInfo) = ERROR_SUCCESS then
      ShowMessage('Radio found: '+ RadioInfo.szName);

    with DeviceSearchParams do
    begin
      dwSize := SizeOf(DeviceSearchParams);
      fReturnUnknown := True;
      fReturnRemembered := True;
      hRadio := RadioHandle;
    end;

    DeviceFindHandle := BluetoothFindFirstDevice(DeviceSearchParams, DeviceInfo);
    if DeviceFindHandle = 0 then
      Continue;

    repeat
      if BluetoothGetDeviceInfo(RadioHandle, DeviceInfo) = ERROR_SUCCESS then
      begin
        BluetoothUpdateDeviceRecord(DeviceInfo);
        if DeviceInfo.fConnected then
          ShowMessageFmt('Device %s is connected', [DeviceInfo.szName])
        else
          ShowMessageFmt('Device %s is not connected', [DeviceInfo.szName]);
      end;
    until not BluetoothFindNextDevice(DeviceFindHandle, DeviceInfo);
    BluetoothFindDeviceClose(DeviceFindHandle)
  until not (BluetoothFindNextRadio(FindHandle, RadioHandle));
  BluetoothFindRadioClose(FindHandle);
end;

From that point one can easily replace the ShowMessageFmt(..) calls and replace it with custom code.


Need Your Help

Sending list of objects to Web API

c# asp.net-web-api

I am having trouble sending a list of objects to a webapi controller.

Get Output From the logging Module in IPython Notebook

python logging jupyter-notebook jupyter

When I running the following inside IPython Notebook I don't see any output: