当前位置:网站首页>Freemodbus parsing 1

Freemodbus parsing 1

2022-06-23 04:47:00 Boundless also initial heart

Online for FreeModBus There are many ways to parse , I also read it by referring to these analyses FreeModBus.FreeModBus In a thousand ways , here , I picked up one of the clues , Just call one of the functions , Sort it out , Learn a lot .

Compare the following two functions :

peMBFrameReceiveCur  And  eMBRTUReceive

See how they are defined , How to call .
Here is the declaration of the first function :

typedef eMBErrorCode( *peMBFrameReceive )( UCHAR * pucRcvAddress,
                                           UCHAR ** pucFrame,
                                           USHORT * pusLength );
static peMBFrameReceive peMBFrameReceiveCur;

Declaration of the second function :

eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength);

choice RTU Mode time , The former hooks the latter :

peMBFrameReceiveCur = eMBRTUReceive;

In the state machine eMBPoll in , When the time is EV_FRAME_RECEIVED when , Execute function

eStatus = peMBFrameReceiveCur( & ucRcvAddress, & ucMBFrame, & usLength );
 Three parameters in the state machine  eMBPoll  Is defined as :
static UCHAR   ucRcvAddress;
static UCHAR   *ucMBFrame;
static USHORT  usLength;

This example can learn :
1, This is not known as a callback function , Hook function , Anyway, my understanding now is ,peMBFrameReceiveCur May have been in a different ModBus Hook different functions in mode , Execute these different functions under appropriate conditions . One of the benefits of this is , The caller and the callee are separated , The caller can call other callees under appropriate conditions .
2, Finally, let's look at the function call , Here is a typical pointer passing , When the function is called, the ucRcvAddress,*ucMBFrame,usLength, The addresses of these three parameters are passed to the callback function , After the callback function is executed , The values of these three parameters change , That is, the address of this frame data is obtained , Length and data content .

problem :
1, The difference between hook function and callback function
2, The callee is a callback function , I understand right
3, In a function declaration passed with a pointer
eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength);
Parameters UCHAR ** pucFrame In fact, the array name is passed , It's a pointer to a pointer , Notice here .

原网站

版权声明
本文为[Boundless also initial heart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230006250996.html