IPWorks BLE 2020 Delphi Edition

Questions / Feedback?

StartScanning Method

Causes the component to begin scanning for BLE GATT servers.

procedure StartScanning(ServiceUuids: String);

Remarks

This method causes the component to start scanning for BLE GATT servers, optionally filtered to include only servers which are advertising one or more services of interest.

To scan for all servers, pass empty string as the ServiceUuids parameter.

To scan for only servers advertising specific services, pass a comma-separated list of service UUIDs as the ServiceUuids parameter. (Only servers advertising all of the given services will be detected. Be aware that, due to the limited space in an advertisement packet, it's common for servers to support more services than they advertise.)

The StartScan event will be fired when the scanning has begun, after which the Advertisement event is fired whenever an advertisement from a server is received; the Error event is fired if an error occurs.

If you wish to use active scanning, enable the ActiveScanning property before you call StartScanning (refer to its documentation for more information).

You may start scanning while already connected to a server, but the component will stop scanning automatically if you attempt to initiate a new server connection (regardless of whether or not that connection attempt ends up succeeding).

Please be aware that scanning is a power-intensive activity, and you should call the StopScanning method as soon as is appropriate in order to prevent unnecessary power consumption.

Calling StartScanning when the component is already scanning does nothing.

Basic Scanning and Advertisement Handling Example

// StartScan event handler.
bleclient1.OnStartScan += (s, e) => Console.WriteLine("Scanning has started");
// StopScan event handler.
bleclient1.OnStopScan += (s, e) => Console.WriteLine("Scanning has stopped");
// Advertisement event handler.
bleclient1.OnAdvertisement += (s, e) => {
  // Your application should make every effort to handle the Advertisement event quickly.
  // BLEClient fires it as often as necessary, often multiple times per second.
  Console.WriteLine("Advertisement Received:" +
    "\r\n\tServerId: " + e.ServerId +
    "\r\n\tName: " + e.Name +
    "\r\n\tRSSI: " + e.RSSI +
    "\r\n\tTxPower: " + e.TxPower +
    "\r\n\tServiceUuids: " + e.ServiceUuids +
    "\r\n\tServicesWithData: " + e.ServicesWithData +
    "\r\n\tSolicitedServiceUuids: " + e.SolicitedServiceUuids +
    "\r\n\tManufacturerCompanyId:  " + e.ManufacturerCompanyId +
    // We use BitConverter.ToString() to print data as hex bytes; this also prevents
    // an issue where the string could be cut off early if the data has a 0 byte in it.
    "\r\n\tManufacturerCompanyData:  " + BitConverter.ToString(e.ManufacturerDataB) +
    "\r\n\tIsConnectable:  " + e.IsConnectable +
    "\r\n\tIsScanResponse:  " + e.IsScanResponse);
};

// Scan for all devices.
bleclient1.StartScanning("");
// Wait a while...
bleclient1.StopScanning();

Filtered Scanning Example

// Scan for devices which are advertising at least these UUIDs. You can use a mixture 
// of 16-, 32-, and 128-bit UUID strings, they'll be converted to 128-bit internally.
bleclient1.StartScanning("180A,0000180F,00001801-0000-1000-8000-00805F9B34FB");
// ...
bleclient1.StopScanning();

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks BLE 2020 Delphi Edition - Version 20.0 [Build 8158]