AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Bluetooth Low Energy Delphi 6

Ein Thema von v2afrank · begonnen am 27. Mai 2016 · letzter Beitrag vom 20. Nov 2018
 
Ravenpool

Registriert seit: 19. Nov 2018
1 Beiträge
 
#26

AW: Bluetooth Low Energy Delphi 6

  Alt 19. Nov 2018, 15:36
Hallo Delphi Praxis Community,

Ich habe das Forum durchsucht und nur diesen passenden Thread gefunden.
Ich hoffe es ist in Ordnung, dass ich es hier reinstelle.

Ich versuche in RAD Studio 10.2 ein Pulsoximeter auszulesen.
Mit DiscoverDevices kann ich auch das Gerät finden und mir in einer Liste anzeigen lassen.


Der Befehl DiscoverServices führt immer zur Fehlermeldung: 'Device not paired'.

Unter Windows 10 kann ich das Pulsoximeter auf keinem PC pairen. Ich habe es auf vier Computern sowohl über Dongle als auch eingebautem Bluetooth getestet. Ich habe das pairen und DiscoverServices mit einem Pulsgurt getestet, das lief problemlos.

Auch Versuche mit GetServices oder GetService haben bisher keinen Erfolg gebracht, das Ergebnis ist immer nil.
Ich hatte es schon fast aufgegeben mit all den Hinweisen bezüglich Delphi kann nur bei verbundenem Gerät die Daten auslesen, als ich den Bluetooth LE Explorer von Windows gefunden hatte.

Das pairen schlägt dort zwar auch fehl, aber bei direktem Klick auf das Gerät sind alle Daten auslesbar und auch abonierbar. Generell scheint es also unter Windows 10 ohne pairen zu gehen.

Den Sourcecode zum BLE Explorer habe ich hier gefunden: https://blogs.msdn.microsoft.com/btb...en-source-now/

Leider hat mir das auch nicht viel weitergeholfen. Ich hoffe, dass jemand von euch vielleicht eine Idee hat, wie ich das Ding vielleicht doch noch zum Laufen bekomme.
Vielen Dank schon mal.

Lucas


Ich hänge hier nochmal den kompletten Code an:
Delphi-Quellcode:
unit Bluetooth_MD300CI;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Bluetooth,
  System.Generics.Collections,
  System.Bluetooth.Components, Vcl.StdCtrls;

type
  TLucas = record
    Geraetenummer: Integer;

  end;

  Tmainfrm = class(TForm)
    Scan_Button: TButton;
    Beenden_Btn: TButton;
    BluetoothLE1: TBluetoothLE;
    ListBox1: TListBox;
    Subscribe_Btn: TButton;
    Label1: TLabel;
    procedure Scan_ButtonClick(Sender: TObject);
    procedure Beenden_BtnClick(Sender: TObject);
    procedure Subscribe_BtnClick(Sender: TObject);
    procedure BluetoothLE1EndDiscoverServices(const Sender: TObject;
      const AServiceList: TBluetoothGattServiceList);
    procedure BluetoothLE1CharacteristicRead(const Sender: TObject;
      const ACharacteristic: TBluetoothGattCharacteristic;
      AGattStatus: TBluetoothGattStatus);
    procedure BluetoothLE1DiscoverLEDevice(const Sender: TObject;
      const ADevice: TBluetoothLEDevice; Rssi: Integer;
      const ScanResponse: TScanResponse);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    Device_List: TList<System.Bluetooth.TBluetoothLEDevice>;
    FBLEDevice: TBluetoothLEDevice;

    SPOService: TBluetoothGattService;
    Read_Charact: TBluetoothGattCharacteristic;
    ServiceList: TBluetoothGattServiceList;

  public

    const

    ServiceUUID = '';
    CharactUUID = '';

    CI218_SERVICE: TBluetoothUUID = '{00001822-0000-1000-8000-00805F9B34FB}';
    CI218_Characteristic
      : TBluetoothUUID = '{00002A60-0000-1000-8000-00805F9B34FB}';
  end;

var
  mainfrm: Tmainfrm;

implementation

{$R *.dfm}

procedure Tmainfrm.Beenden_BtnClick(Sender: TObject);
begin
  application.Terminate;
end;

procedure Tmainfrm.Subscribe_BtnClick(Sender: TObject);
Var
  SelectedText: String;
  Device_Identifier: String;
  Current_Device: TBluetoothLEDevice;
begin

  Scan_Button.Enabled := true;
  if (ListBox1.ItemIndex >= 0) then
  begin
    Current_Device := ListBox1.Items.Objects[ListBox1.ItemIndex]
      as TBluetoothLEDevice;

  if Current_Device.Connect then
  begin
    showMessage('connected');
  end
  else
  begin

  end;
    SPOService := nil;
    Read_Charact := nil;
    ServiceList := nil;
    BluetoothLE1.DiscoverServices(Current_Device);
      //SPOService := BluetoothLE1.GetService(Current_Device, CI218_SERVICE);
      //Read_Charact := BluetoothLE1.GetCharacteristic(SPOService,
      // CI218_Characteristic);

      // ServiceList := BluetoothLE1.GetServices(Current_Device);
// BluetoothLE1.SubscribeToCharacteristic(Current_Device, Read_Charact);

// if SPOService <> nil then
// begin
// ShowMessage('Service found');
// // FHRMeasurementGattCharact := BluetoothLE1.GetCharacteristic(FHRGattService, HRMEASUREMENT_CHARACTERISTIC);
// // FBodySensorLocationGattCharact := BluetoothLE1.GetCharacteristic(FHRGattService, BODY_SENSOR_LOCATION_CHARACTERISTIC);
// end
// else
// begin
// ShowMessage('Service not found');
//
// end;
    //end
    //else
      //ShowMessage('Could not connect device');
  end
  else
    ShowMessage('Please select a device from the List');
end;



procedure Tmainfrm.Scan_ButtonClick(Sender: TObject);

begin
  Scan_Button.Enabled := false;
  BluetoothLE1.DiscoverDevices(5000, [CI218_SERVICE]);

end;

procedure Tmainfrm.BluetoothLE1CharacteristicRead(const Sender: TObject;
  const ACharacteristic: TBluetoothGattCharacteristic;
  AGattStatus: TBluetoothGattStatus);
var
  LAmbient: Double;
  LTarget: Double;
  LAccel: Double;
  LHum: Integer;
  LHHum: Double;
begin
  // if ACharacteristic.UUIDName = 'UUID_IRT_DATA' then
  // begin
  // LAmbient := extractAmbientTemperature(ACharacteristic);
  // LTarget := extractTargetTemperature(ACharacteristic, LAmbient);
  // EdAmbient.Text := Format('%f °C',[LAmbient]);
  // EdTarget.Text := Format('%f °C',[LTarget]);
  // end
  // else if ACharacteristic.UUIDName = 'UUID_ACC_DATA' then
  // begin
  // LAccel := ACharacteristic.GetValueAsInt8(0) /64;
  // EdAccelX.Text := Format('%f',[LAccel]);
  // LAccel := ACharacteristic.GetValueAsInt8(1) /64;
  // end;
  //
  //
  //
end;

procedure Tmainfrm.BluetoothLE1DiscoverLEDevice(const Sender: TObject;
  const ADevice: TBluetoothLEDevice; Rssi: Integer;
  const ScanResponse: TScanResponse);
var
  Device: System.Bluetooth.TBluetoothLEDevice;
  I: Integer;
  DCount: Integer;
  NumberOfDevices: Integer;
  ListBoxText: String;
begin
  DCount := BluetoothLE1.DiscoveredDevices.Count;
  NumberOfDevices := ListBox1.Count;
  for I := 0 to DCount - 1 do
  begin
    Device := BluetoothLE1.DiscoveredDevices[I];


    // if (Device.DeviceName = 'MD300CI218') then
    begin
      if Not Device_List.Contains(Device) Then
      begin
        Device_List.Add(Device);
        // Name := 'Unknown device';
        // Name := Name + BluetoothLE1.DiscoveredDevices[I].Identifier;
        // ListBoxText := '- ' + Device.DeviceName + ' - ' + Device.Identifier;
        // ListBox1.Items.Add(ListBoxText);

        ListBox1.Items.AddObject(Device.DeviceName, Device);
      end;

      // if (List.IndexOf(Device_Count - 1) <> I) then
      // begin
      // List.Insert(Device_Count, I);
      // // device_array[NumberOfDevices] := I;
      // Name := ' - ' + Name + ' - ' + BluetoothLE1.DiscoveredDevices[I]
      // .Identifier;
      // ListBox1.Items.Add(IntToStr(NumberOfDevices + 1) + Name);
      // Device_Count := Device_Count + 1;
      // end;
      // end
      // else
      // begin
      // List.Insert(Device_Count, I);
      // Name := ' - ' + Name + ' - ' + BluetoothLE1.DiscoveredDevices[I]
      // .Identifier;
      // ListBox1.Items.Add(IntToStr(NumberOfDevices + 1) + Name);
      // Device_Count := Device_Count + 1;
      //
      // end;
    end;

  end;
end;

//
procedure Tmainfrm.BluetoothLE1EndDiscoverServices(const Sender: TObject;
  const AServiceList: TBluetoothGattServiceList);
var
  I, J: Integer;
begin
  // for I:= 0 to AServiceList.Count - 1 do
  // begin
  // if AServiceList[I].UUIDName = 'UUID_IRT_Serv' then //Temperature service
  // begin
  // for J := 0 to AServiceList[I].Characteristics.Count - 1 do
  // begin
  // if AServiceList[I].Characteristics[J].UUIDName = 'UUID_IRT_CONF' then
  // begin
  // AServiceList[I].Characteristics[J].SetValueAsUInt8(1);
  // BluetoothLE1.WriteCharacteristic(FcurrentDevice, AServiceList[I].Characteristics[J])
  // end
  // else if AServiceList[I].Characteristics[J].UUIDName = 'UUID_IRT_DATA' then
  // BluetoothLE1.SubscribeToCharacteristic(FCurrentDevice, AServiceList[I].Characteristics[J])
  // end;
  // end
  // else if AServiceList[I].UUIDName = 'UUID_ACC_SERV' then //Accelerometer
  // begin
  // for J := 0 to AServiceList[I].Characteristics.Count - 1 do
  // begin
  // if AServiceList[I].Characteristics[J].UUIDName = 'UUID_ACC_CONF' then
  // begin
  // AServiceList[I].Characteristics[J].SetValueAsUInt8(1);
  // BluetoothLE1.WriteCharacteristic(FcurrentDevice, AServiceList[I].Characteristics[J])
  // end
  // else if AServiceList[I].Characteristics[J].UUIDName = 'UUID_ACC_DATA' then
  // BluetoothLE1.SubscribeToCharacteristic(FCurrentDevice, AServiceList[I].Characteristics[J])
  // end;
  // end
  //
  // end;
end;

procedure Tmainfrm.FormCreate(Sender: TObject);
begin
  Device_List := TList<System.Bluetooth.TBluetoothLEDevice>.Create;
end;

procedure Tmainfrm.FormDestroy(Sender: TObject);
begin
  Device_List.Free;
  BluetoothLE1.CancelDiscovery();
end;

end.
Angehängte Grafiken
Dateityp: jpg BLE Explorer.jpg (65,3 KB, 31x aufgerufen)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz