是否可以在Electron中检测PC (Mac或Linux)是否连接了蓝牙适配器?我正在使用" Bluetooth -serial-port“库进行蓝牙通信。如果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);});发布于 2017-10-24 22:43:06
According to this issue on GitHub如果计算机没有安装任何蓝牙设备,bluetooth-serial-port将会崩溃。
据我所知,Electron没有任何蓝牙API。根据您的使用情况,您可以使用web bluetooth来使用蓝牙(或者只检查计算机是否具有蓝牙)。请查看electron-web-bluetooth on GitHub以查看工作示例。
发布于 2019-06-20 11:34:47
您可以使用inquireSync()来避免崩溃
try {
btSerial.inquireSync();
}
catch (e){
callback(new Error('something bad happened ' + e));
}https://stackoverflow.com/questions/46909180
复制相似问题