Git Product home page Git Product logo

cncjs-controller's Introduction

cncjs-controller build status Coverage Status

NPM

A controller library for event-based communication between client and CNCjs server

Installation

npm install --save cncjs-controller
npm install --save [email protected]  # socket.io-client 1.7 is recommended

Usage

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 = '<security-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

cncjs-controller's People

Contributors

cheton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cncjs-controller's Issues

controller.connect() hangs

Hello, I am trying to integrate this module into an app and am having some difficulty getting it running. I'm new to socket.io and fairly new to node. I tried to run the code in the readme, just modified the first 2 lines and updated token and port. This is what I try and run (sorry for formatting):


const io = require('socket.io-client'); //import io from 'socket.io-client';
const Controller = require('cncjs-controller'); //import Controller from 'cncjs-controller';

const controller = new Controller(io);
const host = 'http://127.168.0.12:8000'; // e.g. http://127.0.0.1:8000
const token = 'jt';
const options = {
    query: 'token=' + token
};

controller.connect(host, options, () => {
    const port = 'COM3';

    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();

        console.log('Timed Out');
    }, 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);
});

I connect my arduino, then run the file with node from CLI and nothing happens. No error or anything, can't connect to host.

Any help is much appreciated!

How to use cncjs-controller library

I could not find wiki on using cncjs-controller library. Some examples for usage is ok for me. I want to use it in client side gui of my machine. Sorry if I missed something in wiki. I have only beginner level skills in JS. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.