Platforms to show: All Mac Windows Linux Cross-Platform

/Bluetooth/Mac Bluetooth/CoreBluetooth Devices


Required plugins for this example: MBS Bluetooth Plugin, MBS MacBase Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Bluetooth/Mac Bluetooth/CoreBluetooth Devices

This example is the version from Sun, 15th Jan 2022.

Project "CoreBluetooth Devices.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() cm = New MyCBCentralManagerMBS(Nil) Try Dim n As Integer = cm.authorization Select Case n Case cm.kAuthorizationStatusNotDetermined MsgBox "Authorization not determined." Case cm.kAuthorizationStatusRestricted MsgBox "Authorization restricted." Case cm.kAuthorizationStatusDenied MsgBox "Authorization denied." Case cm.kAuthorizationStatusAuthorized MsgBox "Authorized." End Select Catch r As RuntimeException End Try End EventHandler
Property CM As MyCBCentralManagerMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyCBCentralManagerMBS Inherits CBCentralManagerMBS
EventHandler Sub DidDiscoverPeripheral(peripheral as CBPeripheralMBS, advertisementData as Dictionary, RSSI as String) System.DebugLog CurrentMethodName Dim l As listbox = MainWindow.List Dim u As Integer = l.ListCount-1 For i As Integer = 0 To u If l.RowTag(i) = peripheral Then // same l.Cell(i, 1) = peripheral.Name l.Cell(i, 2) = peripheral.RSSI Return End If Next l.AddRow Str(peripheral.Handle), peripheral.Name, peripheral.RSSI l.RowTag(l.LastIndex) = peripheral End EventHandler
EventHandler Sub DidUpdateState() Dim state As Integer = Me.State System.DebugLog CurrentMethodName+" with state: "+state.ToString Select case state Case Me.kStatePoweredOff Case Me.kStatePoweredOn System.DebugLog "scanForPeripheralsWithServices..." If True Then // scan for all devices Me.scanForPeripheralsWithServices Else // scan for a specific service like weight scale (181D) Dim weightUID As CBUUIDMBS = CBUUIDMBS.UUIDWithString("181D") Me.scanForPeripheralsWithServices Array(weightUID) End If End Select End EventHandler
End Class
ExternalFile info
End ExternalFile
End Project

See also:

The items on this page are in the following plugins: MBS Bluetooth Plugin.


The biggest plugin in space...