Download Winsoft Bluetooth Library for macOS v1.1 Full Source for Delphi 10.3 - 11

Winsoft Bluetooth Library for macOS v1.1 Full Source for Delphi 10.3 - 11

Winsoft Bluetooth Library for macOS v1.1 Full Source for Delphi 10.3 - 11
Winsoft Bluetooth Library for macOS v1.1 Full Source for Delphi 10.3 - 11


Delphi Bluetooth library for macOS.

Features

Uses Core Bluetooth API
Supports BLE clients
Available for Delphi 10.3 - 11
Source code included in registered version
Royalty free distribution in applications

Installation

1. unpack mbtlib.zip file to some folder
2. copy all files from Delphi11 subfolder
(when using Delphi 11) to Examples\Delphi subfolder
3. open demo example Demo.dproj located in
Examples\Delphi subfolder and compile it

What's new

Version 1.1
added Delphi 11 files


type
  EBtError = class(Exception)
  end;

  TBtError = record
  public
    constructor Create(Error: NSError);
    property Code: LongInt read;
    property Description: string read;
    property Domain: string read;
    property Error: NSError read;
    property FailureReason: string read;
    property IsError: Boolean read;
    property RecoverySuggestion: string read;
  end;

  TBtAssignment = record
    Name: string;
    Number: Word;
  end;

  TBtConnectEvent = procedure(Manager: TBtManager; Peripheral: TBtPeripheral) of object;
  TBtConnectFailEvent = procedure(Manager: TBtManager; Peripheral: TBtPeripheral; const Error: TBtError) of object;
  TBtDisconnectEvent = procedure(Manager: TBtManager; Peripheral: TBtPeripheral; const Error: TBtError) of object;
  TBtDiscoverEvent = procedure(Manager: TBtManager; Peripheral: TBtPeripheral; RSSI: Integer) of object;
  TBtStateUpdatedEvent = procedure(Manager: TBtManager) of object;

  TBtAuthorization = (NotDetermined, Restricted, Denied, AllowedAlways);
  TBtManagerState = (Unknown, Resetting, Unsupported, Unauthorized, PoweredOff, PoweredOn);

  TBtManager = class
    constructor Create;

    procedure Connect(Peripheral: TBtPeripheral);
    procedure Disconnect(Peripheral: TBtPeripheral);
    procedure Scan;
    procedure StopScan;

    property CentralManager: CBCentralManager read;
    property Scanning: Boolean read;
    property State: TBtManagerState read;

    property OnConnect: TBtConnectEvent read write;
    property OnConnectFail: TBtConnectFailEvent read write;
    property OnDisconnect: TBtDisconnectEvent read write;
    property OnDiscover: TBtDiscoverEvent read write;
    property OnStateUpdated: TBtStateUpdatedEvent read write;

    class property Authorization: TBtAuthorization read;
  end;

  TBtPeripheralState = (Disconnected, Connecting, Connected, Disconnecting);

  TBtCharacteristicReadEvent = procedure(Peripheral: TBtPeripheral; Characteristic: TBtCharacteristic; const Error: TBtError) of object;
  TBtCharacteristicNotifyEvent = procedure(Peripheral: TBtPeripheral; Characteristic: TBtCharacteristic; const Error: TBtError) of object;
  TBtCharacteristicWriteEvent = procedure(Peripheral: TBtPeripheral; Characteristic: TBtCharacteristic; const Error: TBtError) of object;
  TBtCharacteristicsDiscoveredEvent = procedure(Peripheral: TBtPeripheral; Service: TBtService; const Error: TBtError) of object;
  TBtDescriptorsDiscoveredEvent = procedure(Peripheral: TBtPeripheral; Characteristic: TBtCharacteristic; const Error: TBtError) of object;
  TBtIncludedServicesDiscoveredEvent = procedure(Peripheral: TBtPeripheral; Service: TBtService; const Error: TBtError) of object;
  TBtReadRSSIEvent = procedure(Peripheral: TBtPeripheral; RSSI: Integer; const Error: TBtError) of object;
  TBtReadyToWriteWithoutResponseEvent = procedure(Peripheral: TBtPeripheral) of object;
  TBtServicesDiscoveredEvent = procedure(Peripheral: TBtPeripheral; const Error: TBtError) of object;

  TBtPeripheral = class
    procedure DisableNotify(const Characteristic: TBtCharacteristic);
    procedure DiscoverCharacteristics(const Service: TBtService);
    procedure DiscoverDescriptors(const Characteristic: TBtCharacteristic);
    procedure DiscoverIncludedServices(const Service: TBtService);
    procedure DiscoverServices;
    procedure EnableNotify(const Characteristic: TBtCharacteristic);
    function GetMaxWriteLength(Response: Boolean = True): Integer;
    function GetService(AssignedNumber: Word): TBtService;
    function GetService(const UUID: TGUID): TBtService;
    function GetWriteWithoutResponse: Boolean;
    procedure Read(const Characteristic: TBtCharacteristic);
    procedure Read(const Descriptor: TBtDescriptor);
    procedure ReadRSSI;
    procedure Write(const Characteristic: TBtCharacteristic; const Value: TBytes; Response: Boolean = True);
    procedure Write(const Characteristic: TBtCharacteristic; Value: Pointer; Length: Integer; Response: Boolean = True);
    procedure Write(const Descriptor: TBtDescriptor; const Value: TBytes);
    procedure Write(const Descriptor: TBtDescriptor; Value: Pointer; Length: Integer);

    property Identifier: TGUID read GetIdentifier;
    property Manager: TBtManager read FManager;
    property Name: string read GetName;
    property Peripheral: CBPeripheral read FPeripheral;
    property Services: TArray<TBtService> read GetServices;
    property State: TBtPeripheralState read GetState;
    property WriteWithoutResponse: Boolean read GetWriteWithoutResponse;

    property OnCharacteristicRead: TBtCharacteristicReadEvent read FOnCharacteristicRead write FOnCharacteristicRead;
    property OnCharacteristicNotify: TBtCharacteristicNotifyEvent read FOnCharacteristicNotify write FOnCharacteristicNotify;
    property OnCharacteristicWrite: TBtCharacteristicWriteEvent read FOnCharacteristicWrite write FOnCharacteristicWrite;
    property OnCharacteristicsDiscovered: TBtCharacteristicsDiscoveredEvent read FOnCharacteristicsDiscovered write FOnCharacteristicsDiscovered;
    property OnDescriptorsDiscovered: TBtDescriptorsDiscoveredEvent read FOnDescriptorsDiscovered write FOnDescriptorsDiscovered;
    property OnIncludedServicesDiscovered: TBtIncludedServicesDiscoveredEvent read FOnIncludedServicesDiscovered write FOnIncludedServicesDiscovered;
    property OnReadRSSI: TBtReadRSSIEvent read FOnReadRSSI write FOnReadRSSI;
    property OnReadyToWriteWithoutResponse: TBtReadyToWriteWithoutResponseEvent read FOnReadyToWriteWithoutResponse write FOnReadyToWriteWithoutResponse;
    property OnServicesDiscovered: TBtServicesDiscoveredEvent read FOnServicesDiscovered write FOnServicesDiscovered;
  end;

  TBtService = class
    const
      GenericAccessService = $1800;
      ...

      Assignments: array [0..41] of TBtAssignment =
      (
        (Name: 'Generic Access'; Number: GenericAccessService),
        ...
      );

    function GetCharacteristic(AssignedNumber: Word): TBtCharacteristic;
    function GetCharacteristic(const UUID: TGUID): TBtCharacteristic;

    property AssignedNumber: Word read;
    property Characteristics: TArray<TBtCharacteristic> read;
    property IncludedServices: TArray<TBtService> read;
    property Peripheral: TBtPeripheral read;
    property Primary: Boolean read;
    property Service: CBService read;
    property ServiceName: string read;
    property UUID: TGUID read;
  end;

  TBtProperty = (Broadcast, Read, WriteWithoutResponse, Write, Notify, Indicate,
    SignedWrite, ExtendedProperties, NotifyEncryption, IndicateEncryption);

  TBtProperties = set of TBtProperty;

  TBtCharacteristic = class
    const
      AerobicHeartRateLowerLimit = $2A7E;
      ...

      Assignments: array [0..233] of TBtAssignment =
      (
        (Name: 'Aerobic Heart Rate Lower Limit'; Number: AerobicHeartRateLowerLimit),
        ...
      );

    function GetDescriptor(AssignedNumber: Word): TBtDescriptor;
    function GetDescriptor(const UUID: TGUID): TBtDescriptor;

    function GetInt8Value(Offset: Integer = 0): Int8;
    function GetInt16Value(Offset: Integer = 0): Int16;
    function GetInt32Value(Offset: Integer = 0): Int32;
    function GetInt64Value(Offset: Integer = 0): Int64;
    function GetUInt8Value(Offset: Integer = 0): UInt8;
    function GetUInt16Value(Offset: Integer = 0): UInt16;
    function GetUInt32Value(Offset: Integer = 0): UInt32;
    function GetUInt64Value(Offset: Integer = 0): UInt64;
    function GetFloat32(Offset: Integer = 0): Float32;
    function GetFloat64(Offset: Integer = 0): Float64;
    function GetStringValue(Encoding: TEncoding = nil): string;

    procedure Write(Value: Int8; Response: Boolean = True);
    procedure Write(Value: Int16; Response: Boolean = True);
    procedure Write(Value: Int32; Response: Boolean = True);
    procedure Write(Value: Int64; Response: Boolean = True);
    procedure Write(Value: UInt8; Response: Boolean = True);
    procedure Write(Value: UInt16; Response: Boolean = True);
    procedure Write(Value: UInt32; Response: Boolean = True);
    procedure Write(Value: UInt64; Response: Boolean = True);
    procedure Write(Value: Float32; Response: Boolean = True);
    procedure Write(Value: Float64; Response: Boolean = True);
    procedure Write(const Value: TBytes; Response: Boolean = True);
    procedure Write(const Value: string; Encoding: TEncoding = nil; Response: Boolean = True);

    property AssignedNumber: Word read;
    property Broadcasted: Boolean read;
    property Characteristic: CBCharacteristic read;
    property CharacteristicName: string read;
    property Descriptors: TArray<TBtDescriptor> read;
    property Notifying: Boolean read;
    property Peripheral: TBtPeripheral read;
    property Properties: TBtProperties read;
    property Service: TBtService read;
    property UUID: TGUID read;
    property Value: TBytes read;
  end;

  TBtDescriptor = class
    const
      CharacteristicAggregateFormat = $2905;
      ...

      Assignments: array [0..14] of TBtAssignment =
      (
        (Name: 'Characteristic Aggregate Format'; Number: CharacteristicAggregateFormat),
        ...
      );

    procedure Write(Value: Int8);
    procedure Write(Value: Int16);
    procedure Write(Value: Int32);
    procedure Write(Value: Int64);
    procedure Write(Value: UInt8);
    procedure Write(Value: UInt16);
    procedure Write(Value: UInt32);
    procedure Write(Value: UInt64);
    procedure Write(Value: Float32);
    procedure Write(Value: Float64);
    procedure Write(const Value: TBytes);
    procedure Write(const Value: string; Encoding: TEncoding = nil);

    property AssignedNumber: Word read;
    property Characteristic: TBtCharacteristic read;
    property Descriptor: CBDescriptor read;
    property DescriptorName: string read;
    property Service: TBtService read;
    property Peripheral: TBtPeripheral read;
    property UUID: TGUID read;
  end;

procedure Check(Value: Boolean; const Message: string);

function ToGUID(AssignedNumber: Word): TGUID;
function IsAssignedNumber(const Value: TGUID): Boolean;
function ToAssignedNumber(const Value: TGUID): Word;


Only for V.I.P
Warning! You are not allowed to view this text.
  • 29