Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cncjs/cncjs-controller
A controller library for event-based communication between client and CNCjs server.
https://github.com/cncjs/cncjs-controller
client cncjs controller events socket-io
Last synced: about 1 month ago
JSON representation
A controller library for event-based communication between client and CNCjs server.
- Host: GitHub
- URL: https://github.com/cncjs/cncjs-controller
- Owner: cncjs
- License: mit
- Created: 2017-09-10T16:25:13.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-28T05:35:07.000Z (about 5 years ago)
- Last Synced: 2024-05-19T15:35:03.764Z (6 months ago)
- Topics: client, cncjs, controller, events, socket-io
- Language: JavaScript
- Size: 24.4 KB
- Stars: 9
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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)
[![NPM](https://nodei.co/npm/cncjs-controller.png?downloads=true&stars=true)](https://www.npmjs.com/package/cncjs-controller)
**A controller library for event-based communication between client and CNCjs server**
## Installation```sh
npm install --save cncjs-controller
npm install --save [email protected] # socket.io-client 1.7 is recommended
```## Usage
```js
import io from 'socket.io-client';
import Controller from 'cncjs-controller';const controller = new Controller(io);
const host = ''; // e.g. http://127.0.0.1:8000
const token = '';
const options = {
query: 'token=' + token
};controller.connect(host, options, () => {
const port = '/dev/cu.wchusbserialfa130';controller.openPort(port, {
controllerType: 'Grbl', // Grbl|Smoothie|TinyG
baudrate: 115200
}, (err) => {
if (err) {
console.error(err);
return;
}controller.writeln('$$'); // View Grbl Settings
});// Disconnect after 60 seconds
setTimeout(() => {
// Close port
controller.closePort();// Close connection
controller.disconnect();
}, 60 * 1000);
});controller.addListener('serialport:open', (options) => {
const {
port,
baudrate,
controllerType
} = options;
console.log(`Connected to the port "${port}" with a baud rate of ${baudrate}.`, { port, baudrate });
});controller.addListener('serialport:close', (options) => {
const { port } = options;
console.log(`The port "${port}" is disconnected.`);
});controller.addListener('serialport:write', (data, context) => {
console.log('>', data);
});controller.addListener('serialport:read', (data) => {
console.log('<', data);
});
```## License
MIT