Posted on

electron使用serialport

准备
node-gyp:https://github.com/nodejs/node-gyp

npm install --save-dev electron-rebuild serialport electron-prebuilt

编辑package.json

"scripts": {
  "rebuild" :"electron-rebuild -f -w serialport",
  "start":"electron ."
},
"devDependencies": {
 "electron-prebuilt": "^1.3.8",
 "electron-rebuild": "^1.3.0",
 "serialport": "^4.0.3"
 }

编译

npm run rebuild

编辑main.js,运行npm start

var s = require("serialport")
s.list(function(err,ports){
 console.log(ports)
});