node.js - Electron 和串口

标签 node.js serial-port electron

我已尽一切努力让 Electron 与 PC 串口一起工作。按照 serialport 的所有说明进行操作(甚至尝试构建 native 模块)但运气不佳。

有没有人有幸让 Electron 使用串行端口?如果是这样,请分享您的智慧。

最佳答案

这是我们在执行 npm install(或升级 electron 或 node-serial 之后)后运行的命令。

  • 在苹果机上

    rm -rf node_modules/serialport/build/* 
    node_modules/.bin/electron-rebuild -w serialport -f 
    ls node_modules/serialport/build/Release
    
  • 赢了

    rmdir /S /Q node_modules\serialport\build\ 
    node_modules\.bin\electron-rebuild -w serialport -f
    dir node_modules\serialport\build\Release
    

根本问题是 node-serialport 是一个本地模块,因此您必须编译它或使用与您的 Node 版本相对应的预构建版本。但是 Node Electron 期望的版本通常(几乎总是)与您在全局安装的 Node 版本不同。 当您重建 Node 串口时,您需要以 electron 期望的 Node 版本为目标。谢天谢地,electron-rebuild处理这个。如上所述安装并运行它。它会找出您使用的 Electron 版本(假设您没有将它隐藏在某个意想不到的地方)。

我们遇到的另一个问题是您需要在运行 electron-rebuild 之前手动删除构建工件,否则它不会生成新的工件。自从我上次查看此内容以来,该问题可能已得到修复。

我将一个直接列表作为第三个命令包含在内,这样我就可以看到一些让我确信文件已生成的输出。

我们的解决方案基于关于 Node 串口问题的主题的长时间讨论。你不需要阅读它,但如果你真的从这里开始 https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/538#issuecomment-273927595 ,他们说:

I think this issue should be closed, right? This is not an issue, haven't been for a long time cause node-serialport works just fine with Electron.

The main problem is that of Electron, everyone who starts using Electron will have issues with native modules, and most issues in this thread is about getting native modules to work.

...然后问题就关闭了。

关于node.js - Electron 和串口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40254287/

相关文章:

javascript - 语法错误 : unexpected Token {

c++ - 在 C++ 中从 Ubuntu Linux (11.10) 上的串口读取

python - 在后台进程中捕获串行数据

javascript - MongoDB 中的日期和时间错误

node.js - 将文件从一个文件夹移动到 s3 中的另一个文件夹

reactjs - 结合多个原子/Electron 应用

javascript - 是否可以在Electron中禁用failIfMajorPerformanceCaveat安全措施?

node.js - 如何通过辅助进程使用 Electron remote?

node.js - 尝试在 Mac 上安装 npm 时出现奇怪的错误

c++ - 在 C++/Win7 中访问 COM 设备名称