Giter Site home page Giter Site logo

danielboe / node-serialbuster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from breakfastny/node-serialbuster

0.0 2.0 0.0 187 KB

Lib for communication over serial, with support for addressing and crc8 check. Suitable for an RS485 bus.

License: Other

Makefile 0.21% JavaScript 99.79%

node-serialbuster's Introduction

#Node SerialBuster

A protocol for communicating between several nodes on a single serial bus. This protocol is mainly developed for an RS485 network with one master and a number of slave devices.

The library uses https://github.com/voodootikigod/node-serialport for underlying communication.

##Protocol structure

ChunkItemTypeLengthExampleNote
0Startuint810x02Signals start of package
1Recipientuint810x01Recipient address `0xFF` for broadcast
2Senderuint810x02Sender address `0x00` for master
3Lengthuint162Length of payload (excluding headers)
4Payloaduint8[]NHello world!Any (binary safe) data
5CRC8uint81Checksum of header and payload
6Enduint810x03Signals end of package

Broadcast

To send a message to all listening clients use the BROADCAST address 0xFF.

Master

The master device has address MASTER or 0x00.

Error checking

A very lightweight 8bit checksum is calculated for the header + payload data in the envelope. Packages that aren't valid gets dropped. CRC8 is calculated before the packet contents have be escaped. Everything but the start and end bytes are escaped.

Send packet

var serialbuster = require('serialbuster');

var my_node_address = serialbuster.CONSTANTS.MASTER;

var serial = new serialbuster.SerialBuster('/dev/tty.usbserial-A800f7Vn', {
    'baudrate' : 9600
  , 'parser' : serialbuster.parser(my_node_address)
  , 'buffersize' : 1024
});

// Give the serial connection some time to 
// get established after it's first created
setTimeout(function() {
  var packet = new serialbuster.Packet({
      'recipient' : serialbuster.CONSTANTS.BROADCAST // send to all nodes
    , 'sender' : my_node_address
  });
  packet.setPayload("Hello everyone! \n\nlove, master");
  serial.sendPacket(packet);
}, 2000);

Install

npm install git+https://github.com/breakfastny/node-serialbuster

Test

make test

Version History

0.0.6

Perform DNS lookup before connecting to TCP socket. Also preventing clients from writing data to a closed TCP socket.

node-serialbuster's People

Contributors

mgunneras avatar mickm avatar

Watchers

 avatar  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.