I am wrapping a CAN Bus manager API in a node.js extension. Everything works well, this would be the final result:
// list interfaces
var interfaces = addon.listDevices();
console.log(interfaces);
// Allocating a new port
var port = new addon.CANPort();
port.setCallback(function(msg) {
// I would like to receive all CAN datagrams
console.log(msg);
});
// Connect to the 1st port
port.connect(0);
// Send a datagram
port.sendStruct(127508, 6, Array(0, 70, 5, 50, 0, 131, 114, 0));
Every function is OK but the setCallback function. Actually, I don't know what to do. I have a c++ callback of this this type :
void CANPort::SetReceiveCallback(functionCallback func);
which will call the function when it receives a new datagram.
I found in http://nikhilm.github.io/uvbook/threads.html some help, but I can't find the right way to do the same as the last example. I know I should use uv, but I don't know how...
Moreover, I'm using the v0.11.14-pre of Node.js, so a lot of documentation is out of date...
Thanks, Nicolas.
function(msg) { // I would like to receive all CAN datagrams console.log(msg); }declare the function outside somewhere and callport.setCallback(function);functionCallback? i hope you have written some valid v8 bindings in cpp side;