如何使用Delphi 10.3检查BLE设备是否仍然连接

3

我已成功将我的 Delphi(FM) 应用程序连接到 ESP32 设备,并可以通过 BLE 发送命令/接收数据(连接成功/失败后会显示连接状态消息)。但问题是,如果用户关闭/关闭 ESP32 设备,则移动应用程序仍然显示已建立连接。

我尝试使用System.Bluetooth.TBluetoothConnectionStateSystem.Bluetooth.TBluetoothLEManager.ConnectionState与 TTimer,但没有成功。

if not (BLEDevice1.ConnectionState = TBluetoothConnectionState.Connected) then
  begin
  Showmessge('Connection not established!');
  // this type of control doesn't change anything.
  end;

1
BLEDevice1.OnDisconnect事件? - Dave Nottage
@DaveNottage感谢您的评论,我之前尝试过这个方法,但是它没有起作用,因为问题在于我没有等待OnDisconnect事件触发(这需要太长时间)。等待一段时间后,消息已经显示出来了。唯一的问题是这个控件大约需要10-15秒钟才能完成,但是您的建议似乎是正确的答案。所以请问您能否将此添加为答案。 - Alper
1个回答

1
使用蓝牙设备(TBluetoothLEDevice)的OnDisconnect事件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接