问题描述
添加此语句
const port = new serialport('COM1',{ autoOpen: true,baudrate: 9600,stopBits: 1},((err) => {if (err){console.log('Error:',err)}
else {console.log('COM1 opened!')}})
)
到 Electron-serialport-quick-start (https://github.com/serialport/electron-serialport-quick-start) 导致 'npm run start' 失败(遵循 'rm -rf node_modules','rm package-lock.json','npm i' 命令序列) 如下,如果推荐的“postinstall”脚本包含在 package.json 中:
Error: TypeError: Third argument must be a function
at internal/util.js:297:30
at new Promise (<anonymous>)
at open (internal/util.js:296:12)
at WindowsBinding.open (G:\CodeDev\quickStartSerialPort\node_modules\@serialport\bindings\lib\win32.js:56:22)
at processticksAndRejections (internal/process/task_queues.js:97:5)
无论是否使用可选的构造函数参数都会导致失败,同样,如果 autoOpen 设置为 false 并且随后调用 port.open(据我所知,port.open 的回调在串行端口文档中未标识为选项)。
不知道这是串行端口还是安装后脚本问题,但如果在下面的 package.json 中省略安装后脚本,可以确认端口打开没有错误:
{
"name": "electron-serialport","version": "1.0.2","description": "A minimal Electron application with node serialport","main": "main.js","scripts": {
"start": "electron .","install": "electron-rebuild","postinstall": "electron-builder install-app-deps","build": "electron-builder -w nsis"
},"repository": {
"type": "git","url": "git@github.com:serialport/electron-serialport.git"
},"keywords": [
"Electron","quick","start","tutorial","demo"
],"author": "GitHub","license": "CC0-1.0","devDependencies": {
"electron": "^11.2.0","electron-rebuild": "^2.3.4"
},"dependencies": {
"serialport": "^9.0.7","tableify": "^0.0.3"
}
}
问题出现在Windows VS Code git bash环境中;尚未在其他平台上进行测试。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)