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.
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;