Wireless Communication Library Support Forum

Frameworks => Bluetooth Framework => Topic started by: gomsun2 on July 18, 2014, 05:17:12 PM

Title: TwclDiscovery.StopMonitoring problem
Post by: gomsun2 on July 18, 2014, 05:17:12 PM
Hello Mike Petrichenko.

I have two dongles.
- Toshiba
- Microsoft

A problem occurred when used Toshiba dongle/API.
My application executes a TwclBluetoothDiscovery.StartMonitoring and it handles in OnDeviceFound.
My problem is that the application freezes until "wclBlutoothDiscovery.StopMonitoring" is finished.

But if using a Microsoft dongle, the problem does not occur.

Please give me an advice to solve this problem.
Thank you for your time.

The following is my code.
Code: [Select]
procedure TbluetoothModule.wclDiscoveryDeviceFound(Sender: TObject;
  Radio: TwclBluetoothRadio; Device: TwclBluetoothDevice);
var
  LRadio: TwclBluetoothRadio;
  LDevice: TwclBluetoothDevice;
begin
  if FMonitoringActive then
  begin
    LRadio := TwclBluetoothRadio.Create;
    try
      LRadio.Assign(Radio);
      LDevice := TwclBluetoothDevice.Create;
      try
        LDevice.Address := Device.Address;
        DvcMakeAuthConnection(LDevice, Radio)
      finally
        FreeAndNil(LDevice);
      end;
    finally
      FreeAndNil(LRadio)
    end;
  end
  else if not TimerClient.Enabled then
    TimerClient.Enabled := True;
end;

function TbluetoothModule.DvcMakeAuthConnection(
  const ADevice: TwclBluetoothDevice; const ARadio: TwclBluetoothRadio): Boolean;
begin
  if Assigned(FDevice) and not FMonitoringActive then
    Exit;

  Result := ADevice.Name(ARadio).ToLower.Contains(BT_DEVICE);
  Log.Msg(Result, '  target: %s, device: %s %s', [BT_DEVICE, ADevice.Name(ARadio), ADevice.Addr]);
  if Result then
  begin
    if Assigned(FDevice) then
      FreeAndNil(FDevice);
    FDevice := TwclBluetoothDevice.Create;
    FDevice.Address := ADevice.Address;
    if wclAuth.Active then
      wclAuth.Close;
    wclAuth.Radio := ARadio;
    if wclExeLog(wclAuth.Open, 'Open Authenticator') then
    begin
      wclClient.BluetoothParams.Radio := ARadio;
      wclClient.BluetoothParams.Address := FDevice.Address;
      wclExeLog(wclClient.Connect, 'bluetooth device conntect');
    end;
  end;
end;

procedure TbluetoothModule.TimerClientTimer(Sender: TObject);
begin
  if TimerClient.Enabled then
  begin
    TimerClient.Enabled := False;

    if wclClient.State in [csConnecting, csConnected] then
      wclClient.Disconnect;

    if wclAuth.Active then
      wclAuth.Close;

    if wclDiscovery.Monitoring then
      wclExeLog(wclDiscovery.StopMonitoring, 'discovery monitoring stop');   
  end;
end;
Title: Re: TwclDiscovery.StopMonitoring problem
Post by: Mike Petrichenko on July 19, 2014, 07:13:01 AM
Hello,

Thank you for your report. I will check it out and try to fix.
Title: Re: TwclDiscovery.StopMonitoring problem
Post by: Mike Petrichenko on July 19, 2014, 10:13:29 PM
Ok, the problem has been fixed, The fix will be available in comming version.
Title: Re: TwclDiscovery.StopMonitoring problem
Post by: gomsun2 on July 21, 2014, 04:44:12 AM
Hello,

Thank you for your quick response  :)