IPWorks BLE 2020 ActiveX Edition

Questions / Feedback?

StartScanning Method

Causes the control to begin scanning for BLE GATT servers.

Syntax

bleclientcontrol.StartScanning ServiceUuids

Remarks

This method causes the control 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 control 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 control 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 ActiveX Edition - Version 20.0 [Build 8162]