串行蓝牙断开检测C++

发布于 2025-02-13 17:42:29 字数 353 浏览 0 评论 0原文

如何检测Windows上是否断开连接的蓝牙设备?

这是我尝试的:

//return true if there is a connection
bool works()
{
    //portcom(handle to virtual serial port) and dcb are already initialised
    if(!GetCommState(portcom, &dcb)) return 0; 
    return SetCommState(portcom, &dcb);
}

但是它仅检查端口是否存在并且存在(因为蓝牙端口根本没有关闭)。所以这无效:(

How to detect if bluetooth device disconnected on windows?

Here is what I tried:

//return true if there is a connection
bool works()
{
    //portcom(handle to virtual serial port) and dcb are already initialised
    if(!GetCommState(portcom, &dcb)) return 0; 
    return SetCommState(portcom, &dcb);
}

But it only checks whether the port exists and it exists(because bluetooth ports aren't closed at all). So this doesnt work :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可是我不能没有你 2025-02-20 17:42:29

我认为您可以通过枚举蓝牙设备来检查蓝牙是否连接。

” bluetoothfindfirstdevice 和bluetoothfindnextdevice列举设备,并确定fconnected参数是否是bluetooth_device_info_info_struct_info_struct结构结构。

  typedef struct _bluetooth_device_info {
  dword dwsize;
  bluetooth_address地址;
  Ulong ulclassofdevice;
  布尔连接;
  布尔训练;
  bool fauthented;
  SystemTime Stlastseen;
  SystemTime Stlastused;
  wchar szname [bluetooth_max_name_size];
} bluetooth_device_info_struct;
 

I think you can check if the bluetooth is connected by enumerating the bluetooth devices.

bluetooth api

Use BluetoothFindFirstDevice and BluetoothFindNextDevice to enumerate devices, and determine whether Bluetooth is connected through the fConnected parameter in the BLUETOOTH_DEVICE_INFO_STRUCT structure.

typedef struct _BLUETOOTH_DEVICE_INFO {
  DWORD             dwSize;
  BLUETOOTH_ADDRESS Address;
  ULONG             ulClassofDevice;
  BOOL              fConnected;
  BOOL              fRemembered;
  BOOL              fAuthenticated;
  SYSTEMTIME        stLastSeen;
  SYSTEMTIME        stLastUsed;
  WCHAR             szName[BLUETOOTH_MAX_NAME_SIZE];
} BLUETOOTH_DEVICE_INFO_STRUCT;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文