![](/img/trans.png)
[英]nodejs serialport module or bluetooth-serial-port module, which one?
[英]Getting Electron to work with node's bluetooth-serial-port
我正在尝试让我的Windows Electron-App与另一个设备(“正常”蓝牙,不是BLE)建立稳定的蓝牙连接。 我已经被困在安装node-gyp上,但是我终于可以正确安装它了(至少我是这么认为的)。 现在,我再次陷入困境,需要一些提示才能继续前进。
我尝试了各种不同的库,但似乎没有任何工作适合我。 在尝试使用节点蓝牙(无法将其重建为电子)之后,我决定尝试一下蓝牙串行端口。 但是我再次陷入重建问题。
我遵循了布鲁斯在这方面的建议(尝试了其他方法),但是当我应该更改bindings.gyp中的variables属性时,必须停下来。Neigther Electron文件夹或bluetooth-serial-port文件夹都包含此文件(我暂时将它们安装在其他文件夹中,因为否则它们会相互覆盖)。
尝试使用node-gyp rebuild --target=0.30.1 --dist-url=https://atom.io/download/atom-shell
重建蓝牙串行端口失败,并显示以下输出:
$ node-gyp rebuild --target=2.0.2 --dist-url=https://atom.io/download/atom-shell
gyp info it worked if it ends with ok
gyp info using node-gyp@3.7.0
gyp info using node@8.11.3 | win32 | x64
gyp info spawn C:\python27\python.EXE
gyp info spawn args [ 'C:\\Users\\sbraendle\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-G',
gyp info spawn args 'msvs_version=auto',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\sbraendle\\Desktop\\Electron\\BluetoothTest\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\sbraendle\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\sbraendle\\.node-gyp\\iojs-2.0.2\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\sbraendle\\.node-gyp\\iojs-2.0.2',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\sbraendle\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\Users\\sbraendle\\.node-gyp\\iojs-2.0.2\\<(target_arch)\\iojs.lib',
gyp info spawn args '-Dmodule_root_dir=C:\\Users\\sbraendle\\Desktop\\Electron\\BluetoothTest',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'C:\\Users\\sbraendle\\Desktop\\Electron\\BluetoothTest\\build',
gyp info spawn args '-Goutput_dir=.' ]
gyp: binding.gyp not found (cwd: C:\Users\sbraendle\Desktop\Electron\BluetoothTest) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\sbraendle\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\sbraendle\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=2.0.2" "--dist-url=https://atom.io/download/atom-shell"
gyp ERR! cwd C:\Users\sbraendle\Desktop\Electron\BluetoothTest
gyp ERR! node -v v8.11.3
gyp ERR! node-gyp -v v3.7.0
gyp ERR! not ok
实际设置为:
赢7 x64
节点8.11.3
节点gyp 3.7.0
电子2.0.2(不是完全确定,但安装时会说)。
另外,只要有人已经可以使用它,我也可以就如何与Electron建立蓝牙连接接受其他方法。
我不知道昨天做错了什么,但是今天我重新安装了所有东西,这一次电子安装似乎可以正常工作,以及蓝牙串行端口的安装(或者是我第二次尝试的节点蓝牙) 。 我尝试运行该应用程序而未添加对蓝牙的任何引用。 程序正确启动。 但是,一旦我添加一行像const bluetooth = require('node-bluetooth');
在两种情况下(node-bluetooth和bluetooth-serial-port)都崩溃,并显示以下错误:
$ npm start
> bluetoothtest@1.0.0 start C:\Users\sbraendle\Desktop\Electron\BluetoothTest
> electron .
App threw an error during load
Error: Das System hat keinen Meldungstext für die Meldungsnummer 0x%1 in der Meldungsdatei %2 gefunden.
\\?\C:\Users\sbraendle\Desktop\Electron\BluetoothTest\node_modules\node-bluetooth\build\Release\BluetoothSerialPort.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:172:20)
at Object.Module._extensions..node (module.js:671:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:172:20)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at bindings (C:\Users\sbraendle\Desktop\Electron\BluetoothTest\node_modules\node-bluetooth\node_modules\bindings\bindings.js:76:44)
at Object.<anonymous> (C:\Users\sbraendle\Desktop\Electron\BluetoothTest\node_modules\node-bluetooth\index.js:3:48)
对不起,德语在错误消息:我想准确地复制它。 The system has not found any message text for the message number 0x% 1 in the message file% 2.
有什么建议么?
我知道这个线程是在一年前打开的,但是今天早上我遇到了同样的问题,终于让Electron可以与蓝牙串行端口一起工作了! 所以这是步骤:
删除您的node_modules
文件夹和package.lock
文件。
打开您的终端: npm install --save-dev electron@4.2.6
和npm install --save-dev electron-rebuild
。
注意:电子版本应为确切版本。 最新版本建立在Node 12上,这将无法建立蓝牙库。 您可以在此处了解更多信息: https : //www.npmjs.com/package/electron-releases
同样在您的终端中: npm install --save bluetooth-serial-port
。 在撰写本文时,我的版本是2.2.4。
将此脚本添加到package.json: "scripts":{"rebuild": "electron-rebuild"}
在您的终端中: npm install
然后npm run rebuild
现在,您的项目应已编译,并且在电子内部您有一个正常工作的蓝牙串行端口模块。 我用HC-06收发器测试了该模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.