[Vuejs]-Serial communication with arduino from electron-vue

0👍

If you were on windows this is how you would solve it

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>

Leave a comment