gpt4 book ai didi

vue.js - 来自 electron-vue 与 arduino 的串行通信

转载 作者:行者123 更新时间:2023-12-03 12:29:21 25 4
gpt4 key购买 nike

我的操作系统 - Linux Ubuntu 16.04,我有使用 Electron-Vue 制作的桌面应用程序

例如,我想添加具有通过串口向arduino uno发送数据功能的按钮。但我无法导入 串口 模块到我的 Vue 组件。另外,我尝试使用 串口 Electron 模块,但结果是一样的。有没有办法解决这个问题?我认为我的代码在这里并不重要,但是如果有人问,我会将其附在这篇文章中。谢谢

最佳答案

如果你在 Windows 上,这就是你将如何解决它

Install windows build tools in your computer by running this in your powershell with administrator access


 npm install --global --production windows-build-tools 

or npm --add-python-to-path='true' --debug install --global windows-build-tools


 setx PYTHON "%USERPROFILE%\.windows-build-tools/python27/python.exe"

set PYTHON

set PYTHON helps you check if its set up correctly.

This is not enough install electron rebuild globally in your project files


 npm install -g electron-prebuilt  
npm install --save serialport

We have to rebuild serialport to work with electron. To do this, we need to >install electron-rebuild:


 npm install --save-dev electron-rebuild  

The last step is to run electron-rebuild, once again, just in the root >directory of the app:


 ./node_modules/.bin/electron-rebuild -$(electron -v)

import and use in your electron-vue project


<script>     
const sp = require('serialport')
export default {
name: 'landing-page',
methods: {},
created () {
sp.list(function (error, ports) {
if (error) {
console.log(error)
} else {
console.log(ports)
}
})
}
}
</script>

关于vue.js - 来自 electron-vue 与 arduino 的串行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45212808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com