sebi2k1 / node-can

NodeJS SocketCAN extension
214 stars 72 forks source link

CAN bus error status #133

Open Kheirlb opened 3 months ago

Kheirlb commented 3 months ago

Is there a way for me to check bus status? ERROR_ACTIVE vs PASSIVE?

sebi2k1 commented 3 months ago

We didn't implement getting the link state yet, but you can just listed to error frames (check 'err' variable of each frame and than interpret the payload as defined by SocketCAN).

sebi2k1 commented 3 months ago

Nevertheless would be cool to have an API to retrieve the current bus state.

dbeckwith01 commented 2 months ago

@sebi2k1 Do you have an example on how to listen for the error state? My can controller got into the ERROR_ACTIVE state and I'm trying handle this my application.

sebi2k1 commented 2 months ago

I don't have a hardware here with me to play around with, so I can give only some general advise.

Default state of your controller is error active, where it detects and reports error. If it detects to many issues it enters passive state (still transmit) and finally (depending on the error) bus off state (no rx/tx anymore).

Everytime the controller detects an error it raises the event to the host. In SocketCAN this is translated into an error frame (check if received frame has an 'err' member), if yes you can evaluate the exact error state by looking into the bytes of the frame. The mapping is defined in error.h. The first byte for example tells you the current bus state of the controller.

By default we enabled all error types, but you can change that via setErrorFilters(), parameter is a bit mask of the error class (see error.h again).

I found a nice illustration of the behaviour of a CAN controller online.