电子和串行端口 [英] Electron and serial ports

查看:71
本文介绍了电子和串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尽一切努力使Electron可以与PC的串行端口一起使用。遵循 serialport 的所有说明(甚至尝试构建本机模块),也没有碰到运气。

I have tried everything to try to get Electron to work with the PCs serial port. Followed all instructions for the serialport (even tried building native modules) without luck.

任何人都有幸让Electron与串行端口一起工作?如果是这样,请分享您的智慧。

Has anyone had any luck getting Electron to work with serial ports? If so please share your wisdom.

推荐答案

以下是我们在执行npm安装(或升级electronic或node-

Here are the commands we run after doing npm install (or after upgrading electron or node-serial).


  • 在Mac上

  • on Mac

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


  • 赢了

  • on Win

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


  • 根本问题是节点串行端口是一个本机模块,因此您必须对其进行编译或使用与您的节点版本相对应的预构建版本。但是,电子节点期望的版本通常(几乎总是)与您全局安装的节点版本不同。 重建节点串行端口时,您需要定位电子期望的节点版本。幸运的是, electron-rebuild 可以解决这个问题。安装并按上述方式运行。它将找出您正在使用的电子版本(假设您没有将其隐藏在意外的地方)。

    The root issue is that node-serialport is a native module so you have to compile it or use a pre-built version that corresponds to your version of node. But the version of node electron expects will often (almost always) differ from the version of node you have installed globally. When you rebuild node-serialport you need to target the node version that electron expects. Thankfully, electron-rebuild deals with this. Install it and run it as above. It will figure out what version of electron you are using (assuming you aren't hiding it in some unexpected place).

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

    One other issue we tripped over is that you need to manually delete the build artifacts, before running electron-rebuild, otherwise it doesn't generate new artifacts. It is possible that that's been fixed since I last looked at this.

    我将直接列出的内容作为第三条命令列出来,只是这样,我看到一些输出可确保我生成了文件。

    I include a directly listing as a 3rd command just so I see some output that reassures me the files were generated.

    我们的解决方案基于节点串行端口问题中对该主题的长期讨论。您不需要阅读它,但是如果您从这里开始
    https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/538#issuecomment-273927595 ,他们说:

    Our solution was based on a super long discussion on the subject in a node-serialport issue. You shouldn't need to read it, but if you do start here https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/538#issuecomment-273927595, where they say:


    我认为这个问题应该解决,对吗?这不是问题,
    很久没出现了,因为node-serialport在Electron上可以正常工作

    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.

    主要问题是Electron的问题,每个开始使用
    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.

    ...然后问题就解决了。

    ...and then the issue is closed.

    这篇关于电子和串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆