Git Product home page Git Product logo

etherlab-nodejs's Introduction

Etherlab Node.js

Bind etherlab process and use it directly in node.

Prerequisites

Etherlab must be installed first. To install etherlab, you can follow the instruction from etherlab repository

This package needs the etherlab shared library and header to be installed in /usr/local/.

If etherlab is installed in different location, i.e. /opt/etherlab, then you can create symlink to /usr/local/

ln -s /opt/etherlab/lib/libethercat.so /usr/local/lib/libethercat.so
ln -s /opt/etherlab/include/ecrt.h /usr/local/include/ecrt.h

Slaves Configuration

How to create slave json configuration

Each slave is configured via json file. For example, if a master has 1 Beckhoff EL2008 slave attached, then the configuration would look like this

[
   {
      "alias":0,
      "position":0,
      "vendor_id":"0x00000002",
      "product_code":"0x07d83052",
      "syncs":[
         {
            "index":2,
            "watchdog_enabled":false,
            "pdos":[
               {
                  "index":"0x1600",
                  "entries":[
                     {
                        "index":"0x7000",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1601",
                  "entries":[
                     {
                        "index":"0x7010",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1602",
                  "entries":[
                     {
                        "index":"0x7020",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1603",
                  "entries":[
                     {
                        "index":"0x7030",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1604",
                  "entries":[
                     {
                        "index":"0x7040",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1605",
                  "entries":[
                     {
                        "index":"0x7050",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1606",
                  "entries":[
                     {
                        "index":"0x7060",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               },
               {
                  "index":"0x1607",
                  "entries":[
                     {
                        "index":"0x7070",
                        "subindex":"0x01",
                        "size":1,
                        "add_to_domain":true,
                        "swap_endian":false,
                        "signed":false
                     }
                  ]
               }
            ]
         }
      ]
   }
]

Example

const __etherlab = require('etherlab-nodejs');

const config = './slaves.json';
const frequency = 5000; // in hertz

const etherlab = new __etherlab(config, frequency);

etherlab.on('data', (data, latency) => {
	console.log(data, latency);
	console.log(etherlab.getLatencyAndJitter());
});

etherlab.on('state', current => {
	console.log('master\'s current state ', current);
});

etherlab.on('ready', async () => {
	const domain = await etherlab.getDomain();
	console.log(domain);
});

etherlab.on('error', error => {
	console.error(error);
});

etherlab.start();

etherlab-nodejs's People

Contributors

iqrok avatar

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.