打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Delphi XE 11.1下官方BLE示例学习(1)

这是个有一搭、没一搭的记录。随时都可以停止、随时都可以接续。

XE系列好像早在XE5的时候就支持蓝牙,经典蓝牙和BLE。看过,没细看。因为当时图省事儿,去E4A胡混。这次打算看一看。

官方自带了一个BLEScanner示例,可以分别编译成WindowsAndroidios平台去。这个例子的位置在主程序目录下

\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.

运行:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VBA中的函数Timer用法
Delphi XE2 之 FireMonkey 入门(34)
Winform中使用Timer实现滚动字幕效果(附代码下载)
关于IdIcmpClient的错误提示
Discovery 有趣的發現...
Android 4.3: How to connect to multiple Bluetooth Low Energy devices
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服