Skip to content

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

License

Notifications You must be signed in to change notification settings

breakfastny/node-serialbuster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published