如何在Electron App中使用树莓派的GPIO?

问题描述 投票:0回答:3

我正在尝试使用 ElectronJs 为树莓派 3 (b) 构建一个应用程序。我无法使用nodejs的“onoff”模块与树莓派的GPIO进行通信。当我将其导入主进程并尝试使用

electron .
命令运行应用程序时,该命令退出且没有错误信息。谁能建议如何在电子应用程序中使用树莓派3的GPIO。

另外,如果 ElectronJs 无法实现,那么请建议我如何为树莓派实现一个可以使用 GPIO 的 GUI 应用程序。

相同的示例存储库 https://github.com/AkshayKanchan/electron_gpio

node.js electron raspberry-pi3
3个回答
1
投票

将nodeJS更新到最新版本并运行electron-rebuild解决了我的问题。谢谢戴夫·牛顿的帮助。似乎 onoff 包使用的 epoll 编译存在问题。


0
投票
  1. 首先使用 npm install --save-dev 安装 Electron-Rebuild 电子重建。
  2. 然后输入 npx electro-rebuild。
  3. 如果还是不行请卸载onoff模块然后重新安装 然后输入 npx electro-rebuild。 这对我来说就是这样。

0
投票

你能解释一下更多吗?,我也犯了同样的错误

A JavaScript error occurred in the main process
Uncaught Exception:
Error: The module '/home/ti/Documentos/teste/node_modules/epoll/build/Release/epoll.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 115. This version of Node.js requires
NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822)
    at Object.<anonymous> (node:internal/modules/cjs/loader:1356:18)
    at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822)
    at Module.load (node:internal/modules/cjs/loader:1126:32)
    at node:internal/modules/cjs/loader:967:12
    at Function._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1150:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at bindings (/home/ti/Documentos/teste/node_modules/bindings/bindings.js:112:48)
    at /home/ti/Documentos/teste/node_modules/epoll/epoll.js:7:31
© www.soinside.com 2019 - 2024. All rights reserved.