preface

I am the Fried chicken, coconut paste and glutinous rice. I want to ascend to Lv2. Well, because the company’s latest project was maritime, and they built an AIS. My manager just let me do ????? How did I feel? I was only one year of helpless and pitiful front-end. But as a qualified society livestock money for people to eliminate disasters prepared to write after the raise wages, also did go up, but did not go up how many tears.

process

First of all, this device is an AIS device. I searched for it and thought it would be rejected if it didn’t exist, but I found an AIS-JSON. I don’t know whether to cry or to be happy. The official provides an example that AIS decoding is actually very simple

# const ais = require('ais-json') import ais from 'ais-json' let aisinfo = ais('! AIVDM, 1, 1,, A, 15 cgah00008lont > 1 cf ` s6NT00SU, 0 * 3 d ')Copy the code

It just provides an AIS () method for you to just type it in. Ah, simplicity. I love it. Post the link by the way

Github.com/YunYouJun/a…

When I thought this job was so simple, the manager told me that I needed to read the data in the AIS device from a serial port, I was immediately confused. Claw thief? You want a thief? The ais-JSON document also provides a node-serialport

When I saw the language with c++, I felt that the situation might be a bit bad, but I didn’t think too much about it and went directly to the official website and copied the example to use

const SerialPort = require('serialport') const port = new SerialPort('/dev/tty-usbserial1', {//'/dev/tty-usbserial1' = COM+ number baudRate: 57600})Copy the code

The direct copy structure is an error, and then I do a search on the Internet and I see why it’s wrong, until somebody says the Web side can’t directly control the local hardware to get the data, and basically there’s a structure order like this, right

Serial port data <-> Node server <-> Web client

I’ve been trying to figure out a way to solve this problem, and I came across a post that basically means using electron vue to turn the code shell into a desktop-level application, and decompilating node-SerialProt to use it, and the corresponding tutorial. Overjoyed, immediately began to try up, the middle encountered a lot of other small problems, I will write out the problems I encountered for everyone.

hands-on

1. Open your CMD in admin mode!! To open in administrator mode!! To open in administrator mode!! Install the vue – cli

npm install -g vue-cli
Copy the code

2. Electron offers official VUe-based projects, creating projects directly

CD into your demo disk vue init SimulatedGreg/electronic-vue electronic-vue-aisCopy the code

3. Go to the project directory

CD Your project nameCopy the code

4. Install node_modules

NPM install or CNPM install note!! With CNPM, there may be a probability problem of not being able to pack. I haven't packed sinceCopy the code

After the installation is complete, NPM run dev can normally open a desktop application

5. Installation node – gyp

NPM install -g node-gyp With CNPM, there may be a probability problem of not being able to pack. I haven't packed sinceCopy the code

6. Install PYTHon2.7&vc2015. You can download the software or use the command line to install python2.7&vc2015

Attention!!!!! NPM install --global --production Windows-build-tools NPM config set Python Python2.7 NPM config set msvs_version 2015Copy the code

# NPM install –global –production Windows-build-tools # NPM install –global –production Windows-build-tools ① Download Python2.7, ② Run NPM install –global –production –verbose windows-build-tools or NPM install –global –dev –verbose Windows-build-tools is actually used and it’s not working but it’s not going anywhere if you open up your windows-build-tools folder you’ll see a little bit more in your Windows build-Tools folder and normally it should be vs_BuildTools and normally you can click on that as well Then use this command

NPM install –global –production [email protected] If this fails, search for the.NET Framework, install the latest one, and then run again. You should get more stuff this time

In fact, I think it worked at this point but there’s a little bit of a problem with this thing and it probably won’t end on its own

① Run the NPM install –global –production [email protected] command

② When the CLI does not move, open the task manager and finish the Build Tools task.

Add Variable: IsInstalled = 1 to the build-tools-log. TXT file in the Windows-build-tools folder. Save the file and close the file.

Basically, when you get stuck, you end the task and then open the task log and tell him that it’s done and you can rest

7. Test gyp

node-gyp
Copy the code

Successful show

PS E:\exe\electron-vue> node-gyp Usage: node-gyp <command> [options] where <command> is one of: - build - Invokes `msbuild` and builds the module - clean - Removes any generated build files and the "out" dir - configure - Generates MSVC project files for the current module - rebuild - Runs "clean", "configure" and "build" all at once - install - Install node development files for the specified node version. - list - Prints a listing of the currently installed node development files - remove - Removes the node development files for the Specified version [email protected] C:\Users\zhupengfei\AppData\Roaming\ NPM \node_modules\node-gyp [email protected]Copy the code

8. Serialport installation

npm install serialport
Copy the code

9. Install the electron rebuild to recompile the c++ native module

npm install --save-dev electron-rebuild
Copy the code

10. Recompile serialPort

.\node_modules.bin\electron-rebuild.cmd 
Copy the code

Compilation errors can be manually compiled, CD to./node_modules/@serialport/bindings

Node - gyp rebuild -- target = 2.0.4 - arch = x64 - dist-url=https://npm.taobao.org/mirrors/atom-shellCopy the code

And then NPM run dev usually the console will give you an error and what’s that error again I forget you can just search for it and just change the comment in a JS file and it doesn’t affect use, okay

And then it’s working. If you still want to use AIS to parse data, you can use virtual serial ports and debugging tools to do that. I’ll start with the code

serialPort() { var a = [] const SerialPort = require('serialport') const Readline = Require ('@serialport/parser-readline') const port = new serialport ('COM5', {// this is your serial number baudRate: }) const parser = port.pipe(new Readline()); Parser. On ('data', function (data) {a.paush (data)}) //Copy the code

So that’s the basic process

In fact, SERIAL debugging tools I recommend using a Serial debugging assistant in the Microsoft Store, whether interface or other far better than online debugging tools

Configure Virtual Serial Port Driver Configure Virtual Serial Port Driver Configure Virtual Serial Port Driver

I don’t know if the Nuggets can post a share link so I’ll just skip it and show you the way

End ★,°:.☆( ̄▽ ̄)/$:.°★.

I want to go up Lv2