基于W5500的freemodbus用TCPIP通信的传输时长测试

为了区别于485模式的传输速度(那个是以9600波特率传输的,每秒1200个字节,然后一个包算12字节,就是10ms左右,感觉有点长……)

这里刚移植完基于以太网的freemodbus,顺便测一波速度

main函数这样写先

	TIM3_Int_Init(65535,72-1);
    while(1)                            /*循环执行的函数*/
    {
			TIM3->CNT=0;
			eMBPoll();
			time=TIM3->CNT;
			printf("time:%d\r\n",time);
			delay_ms(100);
      // do_tcp_server();                  /*TCP_Client 数据回环测试程序*/
    }

用定时器3测时间,CNT单位是us。

eMBErrorCode
eMBPoll( void )
{
    static UCHAR   *ucMBFrame;
    static UCHAR    ucRcvAddress;
    static UCHAR    ucFunctionCode;
    static USHORT   usLength;
    static eMBException eException;

    int             i;
    eMBErrorCode    eStatus = MB_ENOERR;
    eMBEventType    eEvent;

    /* Check if the protocol stack is ready. */
    if( eMBState != STATE_ENABLED )
    {
        return MB_EILLSTATE;
    }

    /* Check if there is a event available. If not return control to caller.
     * Otherwise we will handle the event. */
    if( xMBPortEventGet( &eEvent ) == TRUE )
    {
        printf("type:%d\r\n",eEvent);
        switch ( eEvent )
        {
        ......
        

这里在eMBPoll中检查到事件的情况下输出下事件类型,后面的代码就省略了。

typedef enum
{
    EV_READY,                   /*!< Startup finished. */
    EV_FRAME_RECEIVED,          /*!< Frame received. */
    EV_EXECUTE,                 /*!< Execute function. */
    EV_FRAME_SENT               /*!< Frame sent. */
} eMBEventType;

串口助手打印时间如下,可以看出,在有数据的同时,两次poll会先接收,再执行函数并回复结果。

time:45
time:45
time:46
time:45
time:45
time:46
time:46
time:212
type:1
time:670
type:2
time:945
time:45
time:46
time:45
time:45
time:45
time:45
time:45
time:212
type:1
time:671
type:2
time:945
time:46
time:46
time:45
time:46

为了精确点测时间,我们把poll中的printf删去,再看看串口打印时间:

time:45
time:45
time:46
time:212
time:4
time:280
time:46
time:45
time:45
time:45
time:46
time:45
time:45
time:213
time:4
time:279
time:45
time:46
time:46
time:45
time:45
time:46
time:46
time:212
time:4
time:280
time:45
time:45
time:45
time:45
time:45
time:45
time:46
time:213
timg:4
time:280
time:45
time:46

spi接收+协议处理大概要212us,发送需要280us,整个过程不超过0.5ms,至于中间为什么会出现一个4us的操作……
emm……即使没有事件也会有45us的执行时间呀,难道说eMBState 连接失败了?
但是运行过程中并没有函数去修改过eMBState 呀……

一脸懵逼等待网友研究这个bug……

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值