EtherNET/IP开源从站OpENer多生产者连接功能开发记录
本文介绍了在工程应用中实现高低频控制需求的方法。通过修改opener_user_conf.h配置文件,支持两个生产者连接并设置2ms的最小同步周期。在ApplicationInitialization()中注册了两路连接,分别配置了高低优先级的输入输出参数。文章还提供了常见调试问题的解决方法,如连接实例错误、参数不一致导致的连接失败,以及任务阻塞引起的不稳定问题。这些配置和调试经验对实现可靠的多I
目录
背景
在实际的工程应用中,有高频率的控制需求,还有低频率的控制需求。
思路
opENer原生支持多IO连接,需要修改opener_user_conf.h,如支持两个生产者连接:
/** @brief Define the number of supported exclusive owner connections.
* Each of these connections has to be configured with the function
* void configureExclusiveOwnerConnectionPoint(unsigned int pa_unConnNum, unsigned int pa_unOutputAssembly, unsigned int pa_unInputAssembly, unsigned int pa_unConfigAssembly)
*
*/
#define OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS 2
如果两个连接分别运行在不同的 同步周期下,需要修改最小支持的周期值,如2ms:
/** @brief The time in ms of the timer used in this implementations, time base for time-outs and production timers
*/
static const MilliSeconds kOpenerTimerTickInMilliSeconds = 2;
在ApplicationInitialization()中注册两路连接对应的instance跟ConfigureExclusiveOwnerConnectionPoint(),
#define HIGHT_PRI_CONMMU_O_TO_T (100)
#define HIGHT_PRI_CONMMU_T_TO_O (150)
#define DEMO_ASSEMBLY_CONFIG (151)
#define LOW_PRI_CONMMU_T_TO_O (254)
#define LOW_PRI_CONMMU_O_TO_T (255)
#define DEMO_ASSEMBLY_SW_CONFIG (200)
#define DEMO_CONNECTION_LED_EXCLUSIVE_OWNER (0)
#define DEMO_CONNECTION_SW_EXCLUSIVE_OWNER (1)
EipUint8 g_assembly_data_led_input[DEMO_ASSEMBLY_LED_INPUT_BYTES] = {0}; /** Input */
EipUint8 g_assembly_data_led_output[DEMO_ASSEMBLY_LED_OUTPUT_BYTES] = {0}; /** Output */
static EipUint8 g_assembly_data_config[DEMO_ASSEMBLY_CONFIG_BYTES] = {0}; /** Configuration */
EipUint8 g_assembly_data_sw_input[DEMO_ASSEMBLY_SW_INPUT_BYTES] = {0}; /** Input */
EipUint8 g_assembly_data_sw_output[DEMO_ASSEMBLY_SW_OUTPUT_BYTES] = {0}; /** Output */
static EipUint8 g_assembly_data_sw_config[DEMO_ASSEMBLY_SW_CONFIG_BYTES] = {0}; /** Configuration */
/* global functions called by the stack */
EipStatus ApplicationInitialization(void) {
/** Create Assembly objects to be accessed by implicit connection. */
CreateAssemblyObject( HIGHT_PRI_CONMMU_O_TO_T, g_assembly_data_led_input, sizeof(g_assembly_data_led_input));
CreateAssemblyObject( DEMO_ASSEMBLY_CONFIG, g_assembly_data_config, sizeof(g_assembly_data_config));
CreateAssemblyObject(HIGHT_PRI_CONMMU_T_TO_O, g_assembly_data_led_output, sizeof(g_assembly_data_led_output));
CreateAssemblyObject( LOW_PRI_CONMMU_O_TO_T, g_assembly_data_sw_input, sizeof(g_assembly_data_sw_input));
CreateAssemblyObject( DEMO_ASSEMBLY_SW_CONFIG, g_assembly_data_sw_config, sizeof(g_assembly_data_sw_config));
CreateAssemblyObject( LOW_PRI_CONMMU_T_TO_O, g_assembly_data_sw_output, sizeof(g_assembly_data_sw_output));
ConfigureExclusiveOwnerConnectionPoint(DEMO_CONNECTION_LED_EXCLUSIVE_OWNER,
HIGHT_PRI_CONMMU_T_TO_O,
HIGHT_PRI_CONMMU_O_TO_T,
DEMO_ASSEMBLY_CONFIG);
ConfigureExclusiveOwnerConnectionPoint(DEMO_CONNECTION_SW_EXCLUSIVE_OWNER,
LOW_PRI_CONMMU_T_TO_O,
LOW_PRI_CONMMU_O_TO_T,
DEMO_ASSEMBLY_SW_CONFIG);
return kEipStatusOk;
}
到此,系统中就已经在assembly = 0x04中注册了两个生产者连接,对应的connection path分别是:
"20 04 24 97 2C 96 2C 64"; $ Path
"20 04 24 C8 2C FE 2C FF"; $ Path
验证
启动Scanner,按上述配置的eds文件配置主站,启动implicit_messaging 程序。
wireshark报文如下,从报文中可以看到,有两组生产者连接在正常通讯
调试问题记录
opENer断言报1/303故障
这种一般是T->O和O->T的连接Instance搞错了,如搞反了。
opENer断言报forword open失败
这种需要检查下生产者连接的Scanner 与 Adapter 配置参数是不是一致的,一般是这个问题导致的。
双连接不稳定
这种一般是log打印耗时长,opENer任务阻塞导致的。需要排查任务优先级设置,以及是否有其他阻塞项。
更多知识分享:
b站,知乎同名:沧海一条狗
咸鱼ID:tb764914262
更多推荐
所有评论(0)