• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

delphi蓝牙TBluetoothLE

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

delphi 蓝牙 TBluetoothLE、TBluetoothLEManager BLE

http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_Bluetooth_Low_Energy

指定UUID

HRSERVICE: TBluetoothUUID = '{0000180D-0000-1000-8000-00805F9B34FB}';
HRMEASUREMENT_CHARACTERISTIC: TBluetoothUUID = '{00002A37-0000-1000-8000-00805F9B34FB}';
BODY_SENSOR_LOCATION_CHARACTERISTIC: TBluetoothUUID = '{00002A38-0000-1000-8000-00805F9B34FB}';

1、搜索设备

方法一、

   BluetoothLE1.DiscoverDevices(4000);

方法二、

  HRSERVICE: TBluetoothUUID = '{0000180D-0000-1000-8000-00805F9B34FB}';

  BluetoothLE1.DiscoverDevices(2500, [HRSERVICE]);

触发事件

BluetoothLE1EndDiscoverDevices

BluetoothLE1DiscoverLEDevice

2、搜索服务

BluetoothLE1.DiscoverServices(FCurrentDevice)//搜索所有服务

BluetoothLE1.DiscoveredDevices[ListBox1.ItemIndex].DiscoverServices

 

FGattService:=BluetoothLE1.GetService(FBLEDevice, HRSERVICE);//搜索指定UUID服务,同于第一步的UUID

3、查询特征

BluetoothLE1.GetCharacteristics(FWeightGattService);//特征列表

BluetoothLE1.GetCharacteristic(FWeightGattService, UUIDchar);//UUID指定的某个特征

FWeightMeasurementGattCharacteristic := BluetoothLE1.GetCharacteristic(FGattService,Weight_CHARACTERISTIC);

触发事件

BluetoothLE1EndDiscoverServices

 

搜索Characteristics

for C := 0 to AServiceList[I].Characteristics.Count - 1 do
ListBox2.Items.Add(' - ' + AServiceList[I].Characteristics[C].UUIDName + ' - ' + AServiceList[I].Characteristics[C].UUID.ToString);

 

4、订阅

BluetoothLE1.SubscribeToCharacteristic(FBLEDevice, FHRMeasurementGattCharact);

BluetoothLE1.SubscribeToCharacteristic(FBLEDevice, FWeightMeasurementGattCharacteristic);

ADevice.SetCharacteristicNotification(ACharacteristic, True)

 5、发送数据

BluetoothLE1.WriteCharacteristic(TBluetoothLEDevice ADevice,TBluetoothGattCharacteristic ACharacteristic);

ADevice.WriteCharacteristic(AChar);

 

 

FGattChar.SetValue(sbytes);
bflag := FCurrentDevice.WriteCharacteristic(FGattChar)

 

6、接收数据

procedure BluetoothLE1CharacteristicRead(const Sender: TObject; const ACharacteristic: TBluetoothGattCharacteristic;
AGattStatus: TBluetoothGattStatus);

 

 

7、断开

BluetoothLE1.UnSubscribeToCharacteristic(FBLEDevice, FWeightMeasurementGattCharacteristic);

BluetoothLE1.UnSubscribeToCharacteristic(FBLEDevice, FHRMeasurementGattCharact);

 ADevice.SetCharacteristicNotification(ACharacteristic, False)

 

http://blogs.embarcadero.com/sarinadupont/2014/10/20/creating-a-bluetooth-le-cloud-enabled-luggage-scale-application/


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi中的异常处理发布时间:2022-07-18
下一篇:
Delphi中的XMLDocument类详解(7)-获取节点名称与节点的属性名称发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap