这是个有一搭、没一搭的记录。随时都可以停止、随时都可以接续。
XE系列好像早在XE5的时候就支持蓝牙,经典蓝牙和BLE。看过,没细看。因为当时图省事儿,去E4A胡混。这次打算看一看。
官方自带了一个BLEScanner示例,可以分别编译成Windows、Android和ios平台去。这个例子的位置在主程序目录下
\Extra\Samples\Object Pascal
\Multi-Device Samples
\Device Sensors and Services
\Bluetooth\BLEScanner
目录里。可以直接编译。
程序的解释和说明,在\Help\Doc下的CodeExamples.chm文件里,搜索BLEScanner文件名,就能找到。
说明如下:
This is a sample that shows the use of theBluetooth API to search for nearby Bluetooth devices and check whether they broadcastany services.
各个组件实现的功能:
Start Scan: Fires the Button1Click event handler.
STOP Scan: Fires the Button2Click event handler.
ProgressBar1: Shows the progress of the discovery.
ListBox1: Displays the information about discovereddevices.
ListBox2: Displays the information about discoveredservices.
TBluetoothLE: The BluetoothLE component thathandles discovery of devices.
Timer1: The timer that fires events used for theprogress bar tracking.
用TBluetoothLE组件实现的功能:
Search for nearby Bluetooth Low Energy devices.
Display names of discovered devices in the ListBox1control.
Search for services on a specific device.
Display the information about discovered servicesin the ListBox2 control.
Main FormOn initialization, the FormShow methodinitializes a Boolean that is used as a control for the discovery interruptionand to prevent multiple simultaneous scanning.
各组件事件处理程序:
Button1Click: Resets the progress bar, clears theListBox1 control, enables the timer and initiates discovery.
Button2Click: Resets the timer and cancelsdiscovery.
BluetoothLE1DiscoverLEDevice: Occurs for everydiscovered device. Adds the name of the discovered device to the ListBox1control. 发现BLE设备时发生。
BluetoothLE1EndDiscoverDevices: Occurs when thediscovery finishes. Disables the timer. 发现设备事件结束时发生。
BluetoothLE1ServicesDiscovered: Occurs for everydiscovered service. Reads the name and the UUID from the list ofcharacteristics and adds them to the ListBox2 control. 每发现一个服务发生一次。
ListBox1ItemClick: Clears the ListBox2 control andinitiates service discovery.
Timer1Timer: Occurs for every timer interval(default is 1 second). Calculates the progress of the discovery based on themaximum discovery time and updates the progress bar accordingly.
运行:
联系客服