SOEM使用Raw Socket收发EtherCAT帧,通过系统调用bind、send和recv实现EtherCAT通信。

1、创建Socket

初始化函数ec_init(ifname)最终会调用/oshw/linux/nicdrv.c下的以下这个函数完成绑定网卡和创建1个Raw Socket。
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
Line179:
     /* we use RAW packet socket, with packet type ETH_P_ECAT */
     *psock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ECAT));
其中ETH_P_ECAT定义为:
#define ETH_P_ECAT              0x88A4

2、绑定Socket到网卡

   /* connect socket to NIC by name */
   strcpy(ifr.ifr_name, ifname);
   r = ioctl(*psock, SIOCGIFINDEX, &ifr);
   ...
   r = bind(*psock, (struct sockaddr *)&sll, sizeof(sll));

3、收发EtherCAT帧

收发和处理EtherCAT帧的函数调用关系如下图所示:

这里写图片描述

GitHub 加速计划 / li / linux-dash
13
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐