ecx_context_t ctx; // SOEM 上下文
ecx_init(&ctx, "eth0");
ecx_config_init(&ctx, FALSE); // 扫描从站
uint16_t slaves = ecx_config_map_group(&ctx, IOmap, 0);
// IOmap 中每从站输入/输出区域已映射
// 实时周期任务(如 1ms):
while(1){
wait_dc_sync(); // 等分布式时钟同步
ecx_send_processdata(&ctx); // 发帧(飞过所有从站)
ecx_receive_processdata(&ctx, 0); // 收返回帧
// 读写 IOmap → 从站输入/输出
servo_pos = (int16_t*)&IOmap[0];
*servo_pos = target_pos;
}