sebi2k1 / node-can

NodeJS SocketCAN extension
222 stars 72 forks source link

'onStopped' is not invoked #42

Closed curisiro closed 4 years ago

curisiro commented 6 years ago

Hi, the example code as below: After 1 second timeout, I can see 'timeout' log in the console. But I cannot see 'stop' log in the console, it means 'onStopped' isn't invoked.

Can anyone help me to check and fix this?

var can = require('socketcan'); var channel= can.createRawChannel("can1");

channel.addListener("onStopped", function() { console.log('stop'); });

channel.start();

setTimeout(function() { console.log('timeout'); channel.stop(); }, 1000);

swapsCAPS commented 5 years ago

It is only invoked on iface down. As a side note implementing this now could mean a breaking change, as some users wont expect it to be called.

juleq commented 5 years ago

onIfaceDown might have been the original purpose and onStopped is just a misleading name? It would make more sense to me since I do not need an event to tell me that I have just called the stop method.

What exactly is you use case for the onStopped listener?

I think you should probably consider wrapping the stop method, inherit from event emitter and emit a custom stop event if you want to give other parts of your application a notification.

Further, if you are interested in the bus error states: If a received message has an err property, it contains error frame information that you can use to determine the state of the bus.

This is more of a comment to the fairly dated report of the OP. @swapsCAPS thanks for adding that, I was not aware before.

sebi2k1 commented 4 years ago

Fixed with #78