gpt4 book ai didi

javascript - 如何用Electron检测蓝牙适配器?

转载 作者:行者123 更新时间:2023-11-28 04:03:17 26 4
gpt4 key购买 nike

是否可以在 Electron 中检测 PC(Mac 或 Linux)是否连接了蓝牙适配器?我正在使用“蓝牙串行端口”库进行蓝牙通信。如果 BT 适配器未连接到 PC,应用程序会不断重新加载。

这就是应用尝试查找设备的方式。

var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();

try {
btSerial.inquire();
}
catch (e) {
callback(new Error('something bad happened ' + e));
}
btSerial.on('failure', function(error){console.log(error);});

最佳答案

According to this issue on GitHub当计算机未安装任何蓝牙设备时,bluetooth-serial-port 将会崩溃。

据我所知,Electron 没有任何蓝牙 API。根据您的用例,您可以使用 web bluetooth使用蓝牙(或者只是检查计算机是否有蓝牙)。查看electron-web-bluetooth on GitHub查看工作示例。

关于javascript - 如何用Electron检测蓝牙适配器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46909180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com