1.0.1 • Published 9 years ago

can4linux v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

can4linux for Node.js

Dependency Status


This is simple wrapper for can4linux library. It provides methods only for reading and sending CAN messages. There is no option for setting baud rate etc. For support you can open a github issue.

Installation Instructions

You have to have everything in place for compiling native modules for node. Of course you also have to compile and start can4linux kernel module. Then installation is easy:

npm install can4linux

Usage

var Can = require('can4linux');

var can = new Can({
  device: '/dev/can0', //CAN device to use, can be omitted
  self: false, // turn to true to see message send by this device (with false only incomming messages are shown), can be omitted
});

can.on('data', function(data){
  console.log(data.id);   // CAN id
  console.log(data.ext);  // Is this extended id?
  console.log(data.rtr);  // Is this RTR message
  console.log(data.data); // Array with CAN data
  console.log(data.self); // Is this message send by this device?
  console.log(data.timestamp.sec + "s " + data.timestamp.usec + "us") // Timestamp
});

can.on('error', function(err){
  console.log("Error received", err);
  can.close();
});

can.send({
  id: 5,          // CAN id
  ext: false,     // Is this extended id?
  rtr: false,     // Is this RTR message
  data: [1,2,3]   // Max 8 bytes unless you have CAN FD enabled, can be omitted
});

Tested on BananaPi M1

1.0.1

9 years ago

1.0.0

9 years ago