electron制作上位机软件篇(一):编译安装serialport

摘要:
参考资源:https://blog.csdn.net/qq_25430563/article/details/87968837https://blog.csdn.net/weixin_36250061/article/details/103472978https://github.com/serialport/node-串行端口/问题/1789https://www.cnblogs

参考:
https://blog.csdn.net/qq_25430563/article/details/87968837
https://blog.csdn.net/weixin_36250061/article/details/103472978
https://github.com/serialport/node-serialport/issues/1789
https://www.cnblogs.com/yangxiaobai123/p/11386799.html

最近打算做个家居环境监测系统,需要制作一个上位机控制下位机stm32对数据的采集,使用的是串口通信,故需要用到serialport,其中走了不少弯路,但是,经过两天的研究,还是成功编译安装成功

(使用了vue进行制作)
第一步:electron-vue环境的搭建、项目的创建

npm install -g vue-cli

vue init simulatedgreg/electron-vue my-project(这个是项目名称,根据实际需要修改)

cd my-project

npm install

(查看项目是否运行成功)
npm run dev

第二步:安装node-gyp(需要注意node如果为64位,可能需要转为32位,64位可能导致后面编译失败)
需要安装VS2017和python

npm install -g node-gyp

npm install --global --production windows-build-tools(直接安装这两个工具)

npm config set python python2.7 

npm config set msvs_version 2017

npm config set python C:Python27(指定python2的路径)

测试是否安装完成:

node-gyp

成功显示:

  Usage: node-gyp <command> [options]

  where <command> is one of:
    - build - Invokes `msbuild` and builds the module
    - clean - Removes any generated build files and the "out" dir
    - configure - Generates MSVC project files for the current module
    - rebuild - Runs "clean", "configure" and "build" all at once
    - install - Install node development files for the specified node version.
    - list - Prints a listing of the currently installed node development files
    - remove - Removes the node development files for the specified version

node-gyp@6.1.0  H:
pm
ode_global
ode_modules
ode-gyp
node@8.16.2

第三步: 安装serialport,通过 electron-rebuild 包重新编译原生模块

npm install serialport

npm install --save-dev electron-rebuild

重新编译

.
ode_modules.binelectron-rebuild.cmd 
重新编译完成之后, 如果运行 npm run dev  就会报错,
说明编译失败了,需要进行手动编译

防止出现gyp: binding.gyp not found的错误,我使用手动编译,步骤如下:

cd ./node_modules/@serialport/bindings

(项目路径不能有中文,否则编译识别)
(npm是64位的)
node-gyp rebuild --target=2.0.4 --arch=x64 --dist-url=https://npm.taobao.org/mirrors/atom-shell

(npm是32位的)
node-gyp rebuild --target=2.0.4 --arch=ia32 --dist-url=https://npm.taobao.org/mirrors/atom-shell

第四步:如果代码运行后,出现require is not defined的报错,在webpack中添加以下代码

{
  externals:  {
    serialport: 'serialport'
  }
}

electron制作上位机软件篇(一):编译安装serialport第1张

测试是否成功的页面代码:

import serialport from 'serialport'

serialport.list().then(ports => {
  //ports 串口信息
  console.log(ports);
});

成功后,打印串口信息:
electron制作上位机软件篇(一):编译安装serialport第2张

免责声明:文章转载自《electron制作上位机软件篇(一):编译安装serialport》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇springcloud的配置文件的读取顺序VUE:如何设置当前页面的背景色下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

nodejs常用npm包

express常用npm包整理如下 art-template  一款js模板引擎,性能不错 jayson       一款纯node的rpc应用包,可实现rpc服务、tcp、http等服务 multer       文件上传 nedb         纯js实现的文件型数据库 node-http-proxy   http代理 async        ...

node程序的部署神器pm2的基本使用

pm2是从nodejs衍生出来的服务器进程管理工具,可以做到开机就启动nodejs。当然了,也可以用nohup来做这件事情的。 前言 众所周知,Node.js运行在Chrome的JavaScript运行时平台上,我们把该平台优雅地称之为V8引擎。不论是V8引擎,还是之后的Node.js,都是以单线程的方式运行的,因此,在多核心处理器的系统中并不能发挥其最大...

在 Node.js 中引入模块:你所需要知道的一切都在这里

本文作者:Jacob Beltran 编译:胡子大哈 翻译原文:http://huziketang.com/blog/posts/detail?postId=58eaf471a58c240ae35bb8e3 英文连接:Requiring modules in Node.js: Everything you need to know Node 中有两个...

vue项目中安装cnpm和node_modules

1.安装cnpm的nodejs包管理工具,命令行: npm install -g cnpm --registry=https://registry.npm.taobao.org   2. 每个vue项目需要配置自己单独的node_modules模块,具体构建过程如下: step1: cd到你的项目根目录下 step1: 执行 “cnpm insta...

Deno会在短期内取代Node吗?

转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。 原文出处:https://blog.bitsrc.io/what-is-deno-and-will-it-replace-nodejs-a13aa1734a74   Deno是什么? Deno v1.0.0已于5月13日正式发布。 其开发者为Ryan Dahl...

[爬虫]采用Go语言爬取天猫商品页面

最近工作中有一个需求,需要爬取天猫商品的信息,整个需求的过程如下: 修改后端广告交易平台的代码,从阿里上传的素材中解析url,该url格式如下: https://handycam.alicdn.com/slideshow/26/7ef5aed1e3c39843e8feac816a436ecf.mp4?content=%7B%22items%22%3A%5B...