Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example to send a can message every 100ms using node.js and socketcan.
/**
* Example to send a can message every 100ms using node.js and socketcan.
*
* Run `npm i socketcan` once to install the node module.
*
* License: CC-BY-NC-SA 4.0
* (c) 2021 Peter Müller <peter@crycode.de> (https://crycode.de)
*/
const socketcan = require('socketcan');
const channel = socketcan.createRawChannel('can0');
channel.start();
function sendData () {
channel.send({
id: 0x042, // the can id
ext: false, // true for extendes frames
rtr: false,
data: Buffer.from([0x01, 0x02, 0x03]), // the data to send
});
}
setInterval(sendData, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment