gpt4 book ai didi

node.js - 让 Electron 与 Node 的蓝牙串行端口一起工作

转载 作者:太空宇宙 更新时间:2023-11-04 01:47:40 26 4
gpt4 key购买 nike

我正在尝试让我的 Windows Electron 应用程序与另一个设备建立稳定的蓝牙连接(“正常”蓝牙,而不是 BLE)。我已经被安装node-gyp困住了,但我终于正确安装了它(至少我这么认为)。现在我又陷入困境,需要一些提示才能继续。

我尝试了各种不同的库,但似乎没有什么对我有用。在尝试使用 Node 蓝牙(未能为 Electron 重建它)之后,我决定尝试一下蓝牙串行端口。但我又陷入了重建问题。

我遵循了 Bruce 在 this 上的建议侧面(在尝试了一些其他方法之后),但当我应该更改绑定(bind)中的变量属性时不得不停止。gypElectron 文件夹和 bluetooth-serial-port 文件夹都不包含此文件(我暂时将它们安装在不同的文件夹中,因为否则它们会相互覆盖)。

尝试使用node-gyprebuild --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

实际设置是:

  • Win 7 x64

  • Node 8.11.3

  • node-gyp 3.7.0

  • Electron 2.0.2(不完全确定,但安装时是这么说的)。

或者,我也愿意接受其他关于如何与 Electron 建立蓝牙连接的方法,只要有人已经让它工作即可。

<小时/>

我不知道我昨天做错了什么,但今天我重新安装了所有东西,这次 Electron 的安装似乎工作正常,蓝牙串行端口(或我的 Node 蓝牙)的安装也正常工作第二次尝试)。我尝试运行该应用程序而不添加任何对蓝牙的引用。程序正常启动。但是,一旦我添加像 const bluetooth = require('node-bluetooth'); 这样的行,它就会在两种情况下( Node 蓝牙和蓝牙串行端口)崩溃,并出现以下错误:

$ 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 与蓝牙串口一起工作!所以步骤如下:

  1. 删除 node_modules 文件夹和 package.lock 文件。

  2. 打开终端:npm install --save-dev electro@4.2.6npm install --save-dev electro-rebuild

Note: The version of electron should be that exact version. Recent releases are built on Node 12 and this will fail to build the bluetooth library. You can learn more here: https://www.npmjs.com/package/electron-releases

  • 也在您的终端中:npm install --save bluetooth-serial-port。在撰写本文时,我的版本是 2.2.4。

  • 将此脚本添加到您的 package.json 中:“脚本”:{“重建”:“Electron 重建”}

  • 在您的终端中:npm install,然后npm runrebuild

  • 您的项目现在应该可以编译,并且您在 Electron 内部有一个工作的蓝牙串行端口模块。我使用 HC-06 收发器测试了该模块。

  • 关于node.js - 让 Electron 与 Node 的蓝牙串行端口一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50860088/

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