当前位置:网站首页>FreeModBus解析1
FreeModBus解析1
2022-06-23 03:51:00 【苍茫也初心】
网上对于FreeModBus的解析有很多,我也是参照这些解析多少读懂了FreeModBus。FreeModBus在千头万绪,这里,我捡其中的一条线索,就其中一个函数的调用,理清一下,学到不少东西。
对比下面两个函数:
peMBFrameReceiveCur 与 eMBRTUReceive看看它们是怎么定义,怎么调用。
下面是第一个函数的声明:
typedef eMBErrorCode( *peMBFrameReceive )( UCHAR * pucRcvAddress,
UCHAR ** pucFrame,
USHORT * pusLength );
static peMBFrameReceive peMBFrameReceiveCur;第二个函数的声明:
eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength);选择RTU模式时,前者钩住后者:
peMBFrameReceiveCur = eMBRTUReceive;在状态机 eMBPoll 中,当时间投递为 EV_FRAME_RECEIVED 时,执行函数
eStatus = peMBFrameReceiveCur( & ucRcvAddress, & ucMBFrame, & usLength );
三个参数在状态机 eMBPoll 中的定义为:
static UCHAR ucRcvAddress;
static UCHAR *ucMBFrame;
static USHORT usLength;这个例子可以学到:
1,这不知道该叫回调函数,还是钩子函数,反正我现在的理解是,peMBFrameReceiveCur可已在不同的ModBus模式下钩住不同的函数,在合适的条件下执行这些不同的函数。这样的好处之一是,调用者和被调用者分开,调用者在合适的条件下可以调用其他的被调用者。
2,最后看这个函数的调用,这里是典型的指针传递,函数调用时同时把ucRcvAddress,*ucMBFrame,usLength,这三个参数的地址传递给回调函数,回调函数执行完成后,这三个参数的值改变,即得到了这一帧数据的地址,长度以及数据内容。
问题:
1,钩子函数和回调函数的区别
2,被调用者是回调函数,我理解的没错吧
3,在用指针传递的函数声明里 eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength);
参数UCHAR ** pucFrame 实际上传递的是数组名,是指向指针的指针,此处要注意。
边栏推荐
- PTA:7-63 计算高考状元
- 制造型企业开发的SRM供应商管理系统特点是什么
- Leetcode 1208. Make strings as equal as possible
- [deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime
- Laravel 通过服务提供者来自定义分页样式
- Permission Operation in dynamics 365 plug-in
- After Huawei online battle service players quickly match, different players receive different lists of players in the same room
- 大一学生课设c——服装管理系统
- Mobile terminal city list sorting JS plug-in vertitylist js
- The spring recruitment in 2022 begins, and a collection of interview questions will help you
猜你喜欢

What is metadata

Volatile and threads

【Pytorch】用自动微分求sin(x)的导数

What are the characteristics of SRM supplier management system developed by manufacturing enterprises

It supports running in kubernetes, adds multiple connectors, and seatunnel version 2.1.2 is officially released!

The spring recruitment in 2022 begins, and a collection of interview questions will help you

X24cxx series EEPROM chip C language universal reading and writing program

JVM调优简要思想及简单案例-为什么需要JVM调优?

一款MVC5+EasyUI企业快速开发框架源码 BS框架源码

How does flutter achieve different zoom animation effects
随机推荐
volatile 与线程的那些事
抖音x-bogus和_signature参数分析
thinkPHP6解决跳转问题
PTA:7-60 宠物的生长
Tiktok x-bogus and_ Signature parameter analysis
大一学生课设c——服装管理系统
notepad++ 查找替换之分组替换保留
Does the network disk also roll inside?
Openjudge noi 1.13 49: calculate logarithm
Distance measure - cosine distance
Particle animation background login page particles js
Pta:7-64 what day of the year is this day
[binary tree] flip equivalent binary tree
Pta:6-71 clock simulation
[binary tree] completeness test of binary tree
如何解决独立站多渠道客户沟通难题?这款跨境电商插件一定要知道!
1183. 电力
如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!
TS advanced infer
第二次作业笔记