福彩3D走势图

技术天地

libsocketcan — 通过应用程序配置CAN接口作者:黄志超    发布时间:2020-3-23 17:44:33    被阅览数:次

福彩3D走势图  CANZONGXIANZUOWEIGONGYEXIANCHANGZUICHANGYONGDEZONGXIANXIEYIZHIYI,YINGYONGSHIFENGUANGFAN。YINGCHUANGGONGSITUICHUDEESMARCXILIEGONGKONGZHUBANZHONGDEESM3352、ESM3354、ESM6800、ESM680、ESM7000DENGDOUBANZAILELIANGLUCANZONGXIANGONGKEHUSHIYONG,TONGSHIYETUICHULEKUOZHANFANGANLAIYINGDUIGEZHONGXUQIU(KUOZHANFANGANZHINENGZHICHIDAIYOUISAZONGXIANDEZHUBANXINGHAO),KEHUKEYITONGGUOYINGCHUANGGONGKONGZHUBANSHANGDEISAZONGXIANKUOZHANCHU4LUCANZONGXIAN,JUTIDEFANGANKEYICANKAOWENZHANG:,SUOYIZAIYINGCHUANGTIGONGDEFANGANZHONGCANZONGXIANZIYUANSHISHIFENFENGFUDE。


  LinuxXITONGDUIYUCANZONGXIANDEZHICHISHICAIYONGDESocket CANFANGSHI,Scoket CANSHIYONGLEsocketJIEKOUHELinuxWANGLUOXIEYIZHAN,ZHEIZHONGFANGFASHIDECANSHEBEIQUDONGKEYITONGGUOWANGLUOJIEKOUHANSHULAIDIAOYONG,ZHEIYANGDADADIFANGBIANLESHUXILinuxWANGLUOBIANCHENGDECHENGXUYUAN,YOUYUDIAOYONGDEDOUSHIBIAOZHUNDEsocket HANSHU,YESHIDEYINGYONGCHENGXUBIANYUYIZHI,ERBUHUIYINWEIYINGJIANDEDIAOZHENGERXIUGAIYINGYONGCHENGXU,ZHEIYANGJIAQIANGLEYINGYONGCHENGXUDEKEWEIHUXING。GUANYUSocket CANDEZILIAOZAILinuxNEIHEWENDANGZHONGYOUGENGWEIXIANGXIDEJIESHAO。ZAIYINGCHUANGGONGSITIGONGDEZILIAOZHONG,YEBAOHANLESHIYONGScoket CANDELICHENG。


  Socket CANTIGONGDEJIEKOUMEIYOUBAOHANDUICANZONGXIANSHEZHIDEGONGNENG,SUOYIZAICHENGXUZHONGSHIYONGCANZONGXIANTONGXUNZHIQIAN,XUYAOXIANSHIYONGYINGCHUANGGONGSIYIZHIDEiproute2ZHONGDEipMINGLINGLAISHEZHICANZONGXIAN,BIRUBOTELV、CAIYANGDIANDESHEZHIDENG,GUANYUSHIYONGipMINGLINGLAISHEZHICANZONGXIANDEXIANGXIFANGFAKEYICANKAOWENZHANG:,MUQIANWOMENDELICHENGYESHISHIYONGDEZHEIZHONGFANGFASHEZHICANZONGXIAN,KEHUHAIKEYICANKAOWOMENTIGONGDELICHENG。


福彩3D走势图  WEILEJIANHUAKEHUDECAOZUO,RANGCHENGXUGENGJIAJIANDANYIDU,YINGCHUANGGONGSITEDIYIZHILElibsocketcanKU,ZHEIGEKUTIGONGLEJIEKOUHANSHULAISHEZHICANZONGXIAN,MIBULESocket CANZHONGQUESHAODEBUFEN。XIAMIANWOMENJIULAIJIESHAORUHELIYONGlibsocketcanTIGONGDEHANSHUSHEZHICANZONGXIAN,SHOUXIANJIESHAOCHANGYONGDEHANSHUYOUSIGE:



/**

 *    关闭CAN总线

*

*    函数会关闭指定的CAN总线,将状态置为down,最好在设置之前调用一次

*

*    参数说明:

*    name:代入CAN总线的名称(即使用ifconfig –a命令查看到的名称),例如can0或者

*    can1等

*

 *    返回值说明:

*    0 成功

*    -1 失败

*

 */

 int can_do_stop(const char *name)



/**

 *    设置CAN总线波特率

*

*    函数设置CAN总线的波特率

*

*    参数说明:

*    name:代入CAN总线的名称(即使用ifconfig –a命令查看到的名称),例如can0或者

*    can1等

*    bitrate:需要设置的波特率。

*

 *    返回值说明:

*    0 成功

*    -1 失败

*

 */

 int can_set_bitrate(const char * __u32)


/**

 *    设置CAN总线复位时间

*

*    函数设置CAN总线的复位时间(单位毫秒),一旦CAN总线出现bus_off,经过设置时长会自动复位

*

*    参数说明:

*    name:代入CAN总线的名称(即使用ifconfig –a命令查看到的名称),例如can0或者can1

*    restart_ms:需要设置的复位时间

*

 *    返回值说明:

*    0 成功

*    -1 失败

*

 */

 int can_set_restart_ms( const char *name, __u32 restart_ms)


/**

 *    启动CAN总线

*

*    函数会启动指定的CAN总线,将状态置为up

*

*    参数说明:

*    name:代入CAN总线的名称(即使用ifconfig –a命令查看到的名称),例如can0或者

*    can1

*

 *    返回值说明:

*    0 成功

*    -1 失败

*

 */

福彩3D走势图 int can_do_start( const char *name )


  利用这四个函数就能够完成对CAN总线的设置,如果在代码中需要使用libsocketcan提供的函数,需要包含头文件libsocketcan.h,并且在链接库中增加libsocketcan的选项,增加库的方法和使用必读手册中介绍的增加线程库方法是完全相同的,示例代码如下:



#include <libsocketcan.h>

 

int main()

{     

       int  i, devnum, bitrate, restime;

       char       devname[5];

 

       devnum = 0;

       sprintf(devname, "can%d", devnum);

      

       i = can_do_stop(devnum);

      

       bitrate = 500000;

       i += can_set_bitrate(devnum, bitrate);

      

       restime = 50;

       i += can_set_restart_ms(devnum, restime);

      

       i += can_do_start(devnum);

       if(i < 0)

       {

              printf("fail to set %s!\n", devname);

              return i;

       }

}


  SHANGMIANDEDAIMAKEYIDAITICANZONGLICHENGZHONGSHIYONGipMINGLINGDUICANZONGXIANDECHUSHIHUASHEZHI,RUGUOKEHUHAIYOUYIXIEBIJIAOTESHUDEXUQIU,BIRUSHEZHITEDINGDECAIYANGHEGONGZUOMOSHIDENG,KEYIZAIlibsocketcanDEGUANFANGWANGZHAN:SHANGCHAKANQITAGENGDUODEHANSHUJIQIGONGNENGJIESHAO。


  RUGUOYOUGANXINGQUDEKEHU,KEYIHEYINGCHUANGGONGCHENGSHILIANXI,SUOQUWANZHENGGONGCHENGWENJIAN。

Go Top