Can總線如何檢測BUS-OFF
當(dāng)CAN
2.
下面以CAN發(fā)送數(shù)據(jù)為例,介紹如何檢測BUS-OFF錯誤狀態(tài)。
struct can_frame framesend = {
err = write(s_can0, &framesend, sizeof(framesend));
通過檢測framesend .can_id是否被BUS-OFF置位。
3.
最好的處理方法是:restart。can0出錯了,restart can0。
4.
檢測CAN BUS-OFF錯誤并進行處理,網(wǎng)上已經(jīng)有開源代碼,大家可以參考這個網(wǎng)址:http://www.pengutronix.de/software/libsocketcan/download/
int state; if ((can_get_state(if_name_can0, &state)) < 0) { fprintf(stderr, "cannot get bustate, " "something is seriously wrong"); } else if (state == CAN_STATE_BUS_OFF) { fprintf(stderr, "Device is in BUS_OFF" ); do_restart("can0"); }
do_restart("can0")的作用是restart can0。
評論