Current location - Quotes Website - Team slogan - Correct posture of using node serial port in electronics
Correct posture of using node serial port in electronics
Node-serialport is a native module that allows nodes to access computer serial devices. Using it in electronic environment is not a simple npm installation serial port. It is basically impossible for people who have just started to contact node not to toss. If the one-time installation is successful, the next installation is likely to need to be tossed.

In the process of tossing, it is inevitable to dig three feet on Google, Baidu and GitHub to find a solution.

This paper introduces in detail how to write and use seialport as much as possible in the electronic version. The system environment used here is win 10, and several materials need to be prepared:

If VS is not installed on your machine and will not be used in the future, it is recommended to install Visual Studio build tools.

In the article using node native module, several methods of using native module are introduced. Here are the first two.

The installation of npm is realized by setting some environment variables. For convenience, you can choose to write a. bat file to import these parameters.

Notice the path of the first two lines here.

The first line is some batch processing obtained after installing Visual Studio Build tool, mainly importing some variables into cmd.

The second line is the path of python. If the computer has more than one python, it is recommended to import it to this command line by means of set.

The rest are parameters related to electrons. The target version number can be found on the home page.

At this point, you can try to install serialport by executing npm install serialport. If there is no error in the installation process, it is basically OK.

If there is an error, please check the error message.

If a 404 or GET request fails, it is a network problem.

In addition, if the previous npm report is lost, it is recommended to delete the node_modules folder and reinstall NPM.

Using rebuild (NPM installation electronics -rebuild-save-dev) to build serialport does not need to set too many variables, but the following two lines are essential.

Then perform npm installation to install various dependencies. After the installation is completed, execute. \ node module \. Bin \ electron-rebuild.cmd is recompiled, and serialport can be used in electronics.

Errors may occur during compilation, such as using python3 or msbuild version errors and a bunch of messy errors. Only by looking at the problem of error log positioning can we solve it.

See below for specific usage.