Step 1: Configure environment
1. Install Python2.7 configuration environment variable (official website to download) to see online instructions must be version 2.7, does not support 3
2. Install --global --production Windows-install npm Build-Tools
3. install the Node-gyp npm install -g node-gyp
Step 2: Install
1. Installation SerialPort NPM the install --save SerialPort
2. Installation Electron the rebuild- NPM-dev Electron---save the install the rebuild
3. recompiled (direct input command):. \ Node_modules.bin \ electron- rebuild.cmd
The third step: the introduction of use
import serialport from ‘serialport‘
serialport.list().then(
ports => {
//ports 串口信息
console.log(ports)
}
)
Step four: About serial transceiver function
serial.on('open', () => {
serial.on('data', (e) => {
console.log(e)
})
serial.write('', (e) => {
console.log(e)
})
})