Skip to content

Commit ddfeded

Browse files
committed
first commit
0 parents  commit ddfeded

File tree

12 files changed

+520
-0
lines changed

12 files changed

+520
-0
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
["es2015", { "loose": true }],
4+
"stage-0"
5+
]
6+
}

.eslintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "trendmicro",
3+
"parser": "babel-eslint",
4+
"env": {
5+
"browser": true,
6+
"node": true
7+
}
8+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
/.nyc_output
3+
/coverage
4+
/dist
5+
/lib

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.nyc_output
2+
/coverage
3+
/dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Cheton Wu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# cncjs-controller [![build status](https://travis-ci.org/cncjs/cncjs-controller.svg?branch=master)](https://travis-ci.org/cncjs/cncjs-controller) [![Coverage Status](https://coveralls.io/repos/github/cncjs/cncjs-controller/badge.svg?branch=master)](https://coveralls.io/github/cncjs/cncjs-controller?branch=master)
2+
3+
[![NPM](https://nodei.co/npm/cncjs-controller.png?downloads=true&stars=true)](https://www.npmjs.com/package/cncjs-controller)
4+
5+
**A controller library for event-based communication between client and CNCjs server**
6+
7+
![image](https://cloud.githubusercontent.com/assets/447801/25939476/96bd5568-3665-11e7-9b6f-b96fe0dc73d8.png)
8+
9+
## Installation
10+
11+
```sh
12+
npm install --save cncjs-controller
13+
npm install --save [email protected] # socket.io-client 1.7 is recommended
14+
```
15+
16+
## Usage
17+
18+
```js
19+
import io from 'socket.io-client';
20+
import Controller from 'cncjs-controller';
21+
22+
const controller = new Controller(io);
23+
const host = ''; // e.g. http://127.0.0.1:8000
24+
const token = '<security-token>';
25+
const options = {
26+
query: 'token=' + token
27+
};
28+
29+
controller.connect(host, options, () => {
30+
const port = '/dev/cu.wchusbserialfa130';
31+
32+
controller.openPort(port, {
33+
controllerType: 'Grbl', // Grbl|Smoothie|TinyG
34+
baudrate: 115200
35+
}, (err) => {
36+
if (err) {
37+
console.error(err);
38+
return;
39+
}
40+
41+
controller.writeln('$$'); // View Grbl Settings
42+
});
43+
44+
// Disconnect after 60 seconds
45+
setTimeout(() => {
46+
// Close port
47+
controller.closePort();
48+
49+
// Close connection
50+
controller.disconnect();
51+
}, 60 * 1000);
52+
});
53+
54+
controller.on('serialport:open', (options) => {
55+
const {
56+
port,
57+
baudrate,
58+
controllerType
59+
} = options;
60+
console.log(`Connected to the port "${port}" with a baud rate of ${baudrate}.`, { port, baudrate });
61+
});
62+
63+
controller.on('serialport:close', (options) => {
64+
const { port } = options;
65+
console.log(`The port "${port}" is disconnected.`);
66+
});
67+
68+
controller.on('serialport:write', (data, context) => {
69+
console.log('>', data);
70+
});
71+
72+
controller.on('serialport:read', (data) => {
73+
console.log('<', data);
74+
});
75+
```
76+
77+
## License
78+
79+
MIT

package.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "cncjs-controller",
3+
"version": "1.0.0",
4+
"description": "A controller library for event-based communication between client and CNCjs server.",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"prepublish": "npm run eslint && npm test && npm run clean && npm run build && npm run dist",
8+
"build": "babel --out-dir ./lib ./src",
9+
"dist": "webpack",
10+
"clean": "rm -rf lib/*",
11+
"eslint": "eslint ./src",
12+
"test": "tap test/*.js --node-arg=--require --node-arg=babel-register --node-arg=--require --node-arg=babel-polyfill",
13+
"coveralls": "tap test/*.js --coverage --coverage-report=text-lcov --nyc-arg=--require --nyc-arg=babel-register --nyc-arg=--require --nyc-arg=babel-polyfill | coveralls"
14+
},
15+
"author": "Cheton Wu <[email protected]>",
16+
"contributors": [
17+
{
18+
"name": "Cheton Wu",
19+
"email": "[email protected]",
20+
"url": "https://github.com/cheton"
21+
}
22+
],
23+
"license": "MIT",
24+
"repository": {
25+
"type": "git",
26+
"url": "git+https://github.com/cncjs/cncjs-controller.git"
27+
},
28+
"keywords": [
29+
"cncjs",
30+
"controller",
31+
"socket",
32+
"io",
33+
"events",
34+
"client"
35+
],
36+
"dependencies": {},
37+
"devDependencies": {
38+
"babel-cli": "~6.24.1",
39+
"babel-core": "~6.24.1",
40+
"babel-eslint": "~7.2.3",
41+
"babel-preset-es2015": "~6.24.1",
42+
"babel-preset-stage-0": "~6.24.1",
43+
"coveralls": "~2.13.1",
44+
"eslint": "~3.19.0",
45+
"eslint-config-trendmicro": "~0.5.1",
46+
"eslint-plugin-import": "~2.2.0",
47+
"eslint-plugin-jsx-a11y": "~2.2.3",
48+
"eslint-plugin-react": "~6.10.0",
49+
"tap": "~10.3.2",
50+
"webpack": "~3.5.6"
51+
},
52+
"nyc": {
53+
"exclude": [
54+
"test/index.js"
55+
]
56+
}
57+
}

0 commit comments

Comments
 (0)