資源描述:
《freemodbus--完全的分析》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、FreeModbus--完全分析說明:freemodbus-v1.5.0主流程[objc]?viewplaincopy1./*?-----------------------?Start?implementation?-----------------------------*/??2.int??3.main(?void?)??4.{??5.????eMBErrorCode????eStatus;??6.??7.????eStatus?=?eMBInit(?MB_RTU,?0x0A,?0,?38400,?
2、MB_PAR_EVEN?);??8.??9.????/*?Enable?the?Modbus?Protocol?Stack.?*/??10.????eStatus?=?eMBEnable(??);??11.??12.????for(?;;?)??13.????{??14.????????(?void?)eMBPoll(??);??15.??16.????????/*?Here?we?simply?count?the?number?of?poll?cycles.?*/??17.????????usRegIn
3、putBuf[0]++;??18.????}??19.}??由上述主函數(shù)可知協(xié)議棧經(jīng)eMBInit和eMBEnable初始化、使能后進入?yún)f(xié)議棧的循環(huán)eMBPoll中。eMBInit分析首先,使用eMBInit初始化協(xié)議棧,根據(jù)你使用的參數(shù)eMBModeeMode初始化相應(yīng)的函數(shù)入口![objc]?viewplaincopy1.#if?MB_RTU_ENABLED?>?0??2.????????case?MB_RTU:??3.????????????pvMBFrameStartCur?=?eMBRTUSta
4、rt;??4.????????????pvMBFrameStopCur?=?eMBRTUStop;??5.????????????peMBFrameSendCur?=?eMBRTUSend;??6.????????????peMBFrameReceiveCur?=?eMBRTUReceive;??7.????????????pvMBFrameCloseCur?=?MB_PORT_HAS_CLOSE???vMBPortClose?:?NULL;??8.????????????pxMBFrameCBByteR
5、eceived?=?xMBRTUReceiveFSM;??9.????????????pxMBFrameCBTransmitterEmpty?=?xMBRTUTransmitFSM;??10.????????????pxMBPortCBTimerExpired?=?xMBRTUTimerT35Expired;??11.??12.????????????eStatus?=?eMBRTUInit(?ucMBAddress,?ucPort,?ulBaudRate,?eParity?);??13.????????
6、????break;??14.#endif??15.#if?MB_ASCII_ENABLED?>?0??16.????????case?MB_ASCII:??17.????????????pvMBFrameStartCur?=?eMBASCIIStart;??18.????????????pvMBFrameStopCur?=?eMBASCIIStop;??19.????????????peMBFrameSendCur?=?eMBASCIISend;??20.????????????peMBFrameRec
7、eiveCur?=?eMBASCIIReceive;??21.????????????pvMBFrameCloseCur?=?MB_PORT_HAS_CLOSE???vMBPortClose?:?NULL;??22.????????????pxMBFrameCBByteReceived?=?xMBASCIIReceiveFSM;??23.????????????pxMBFrameCBTransmitterEmpty?=?xMBASCIITransmitFSM;??24.????????????pxMBPo
8、rtCBTimerExpired?=?xMBASCIITimerT1SExpired;??25.??26.????????????eStatus?=?eMBASCIIInit(?ucMBAddress,?ucPort,?ulBaudRate,?eParity?);??27.????????????break;??28.#endif??以上代碼中pvMBFrameStartCur、pvMBFrameStopCur等即協(xié)議棧函數(shù)的