4diac forte 1.12.0 版本modbus 的修改

    技术2022-07-10  125

    问题

    4diac 项目的更新真的是个问题。没有对所有的模块完成测试。在forte 1.12.0 版本上编译就出现了问题。4diac 的论坛上讨论的比较少,而且大多数是早几年的内容。没办法,只能自己啃源代码。

    编译的问题。

    1.modbustimedevent.cpp 的36 行

    m_oStartTime = CTimerHandler::sm_poFORTETimer->getForteTime();

    2 modbustimedevent 45 行

    SForteTime currentTime = CTimerHandler::sm_poFORTETimer->getForteTime();

    中:sm_poFORTETimer 没有定义。

    解决方法

     参照了forte 1.10.3 版本:

    1 modbusplayer.cpp 的363 行,getExtEvHandler的前面加了一个&改为:

    m_pModbusConnection = new CModbusClientConnection(&getExtEvHandler<CModbusHandler>());

    2 modbustimedevent.h 中

    uint_fast64_t m_oStartTime;

    uint_fast64_t m_oUpdateInterval;

    3 modbustimedevent.cpp 的36 行改为 

    m_oStartTime = CTimerHandler::smFORTETimer->getForteTime();

    modbustimedevent 45 行 改为

    uint_fast64_t currentTime =CTimerHandler::smFORTETimer->getForteTime();

    4 在 arch/timerha.h 中添加了

    static CTimerHandler *smFORTETimer;

    在 arch/timeha.cpp 中添加了

    CTimerHandler *CTimerHandler::smFORTETimer = 0;

    5 这是定义了一个指向CTimerHandle类的指针,但是需要填入资源真正的handler ,不然就一直出现段错误。找了好久。在

    在core/devexec.cpp 中构造函数中添加了

    CTimerHandler::smFORTETimer= static_cast<CTimerHandler*>(mRegisteredEventHandlers[0].mHandler);

    结果好了。

    6 使用4diac 的client 功能块。

    ID  modbus[tcp:127.0.0.1:502:1000:3:1:0..3:]

    7 SForteTime 类型不兼容,可以改为 uint_fast64_t 。例如 uint_fast64_t m_oStartTime; uint_fast64_t m_oUpdateInterval; 

    测试

    写寄存器,forte 自动将 功能码06 转成了16.

    modbus[tcp:127.0.0.1:502:1000:6:1::0:]

    读寄存器

    modbus[tcp:127.0.0.1:502:1000:3:1:0:0..1:]

    Processed: 0.014, SQL: 9