微 网 高 通

P6. 接收无线数据
来源: | 作者:微网高通 | 发布时间: 2025-06-12 | 6 次浏览 | 分享到:

6.1查询接收状态


函数名

char QueryRxMsgStatus( char iShell, char * pStatus )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

char * pStatus

指向一个已分配好实体内存空间的单字节变量,用于记录接收状态,详细定义见“接收状态”表所示。

返回值

0X01=操作成功,0X00=操作失败





名称

接收状态

数值

说明

0XFF

系统空闲,没有接收任务

0-100

正在接收报文,当前数值为接收的百分进度比,比如35代表接收了总长度35%的报文

0X81

接收成功,且已经附加了前导描述信息,报文总长度,32位的CRC等校验信息

0X82

接收失败

0X83

接收成功,但是没有附加前导描述信息



6.2读取报文发送站点


 函数名

char GetRxMessageNode ( char iShell, short * pNode )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

short * pNode

指向一个已经分配好实体内存空间的双字节变量,用于记录报文的原始发送站点

返回值

0X01=操作成功,0X00=操作失败



6.3读取接收报文属性


 函数名

char GetRxMessageAttr( char iShell, char * pAttr )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

char * pAttr

指向一个已经分配好实体内存空间的单字节变量,用于记录报文的属性

返回值

0X01=操作成功,0X00=操作失败



6.4读取接收报文长度


函数名

char GetRxMessageSize( char   iShell, unsigned long * pSize )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

unsigned long * pSize

指向一个已经分配好实体内存空间的四字节变量,用于记录报文的长度

返回值

0X01=操作成功,0X00=操作失败



6.5读取接收报文内容


 函数名

char ReadInputMessage( char iShell, char * pBuffer, long dwSize )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

char * pBuffer

指向一个已经分配好实体内存空间的内存块地址,该内存块用于保存需要发送的数据

参数三

long dwSize

内存块中的数据长度

返回值

0X01=操作成功,0X00=操作失败



6.6数据接收测试例子程序

数据接收测试例子程序

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "API-WiMinet.h"
int main( int argc, char* argv[] )
{
   char iRetVal;
   char * pBuffer;
   unsigned short iSource;
   unsigned char iAttr;
   unsigned char iStatus;
   unsigned char iProgress;
   unsigned long dwBinMode;
   unsigned long dwTimerA;
   unsigned long dwTimerB;   
   unsigned long dwTimerX;
   unsigned long dwIndex;
   unsigned long dwSize;
   
   // COM port interface
   iRetVal = OpenWiMinetShell( "COM3",115200, 0X01 );
   // Ethernet interface
   //iRetVal = OpenWiMinetShell( "192.168.0.240",12580, 0X01 );
   // Validate the shell open interface
   if ( !iRetVal )
   {
      printf( "Open shell failed!rn" );
      return 0X00;
   }
   // The output mode
   printf( "Please select the output mode:rn" );
   printf( "[0]=TXT modern" );
   printf( "[1]=BIN modern" );
   printf( "The choice=" );
   scanf( "%d", &dwBinMode );
   // The default progrss
   iProgress = 0XFF;
   // The exit information
   printf( "rnReceiving Now......rn" );
   // Get the user input key
   while ( !_kbhit() )
   {
      // Release the processor control
      Sleep( 0X01 );
      // Query the Rx status
      QueryRxMsgStatus( 0X00, ( char * )&iStatus );
      // No received packet arrived
      if ( iStatus == RXD_TASK_STATUS_JOB_WAITING )
      {
         // Reset the initial timer
         dwTimerA = GetTickCount();
         continue;
      }
      // Check if ready to report
      if ( !( iStatus & RXD_TASK_STATUS_REPORTTABLE ) )
      {
         // Update the receive progress
         if ( iStatus != iProgress )
         {
            // Update the receive progress
            iProgress = iStatus;
           
            // Current timer
            dwTimerB = GetTickCount();
           
            // The timer offset
            dwTimerX = dwTimerB - dwTimerA;
           
            // Current Tx progress
            printf( "%9lu ms --> %d%%rn", dwTimerX, iStatus );
         }
         continue;
      }
      // The Rx timer
      GetRxMessageTime( 0X00, &dwTimerX );
      // The receive status
      switch ( iStatus )
      {
      case RXD_TASK_STATUS_END_SUCCESS:
         {
            printf( "rnRx Completed Successfully,Time=%lu(ms)rnrn", dwTimerX );
         }
         break;
      case RXD_TASK_STATUS_END_FAILURE:
         {
            printf( "rnRx Completed With Error,Time=%lu(ms)rnrn", dwTimerX );
         }
         break;
      case RXD_TASK_STATUS_END_NOCRC32:
         {
            printf( "rnRx Completed Without CRC32,Time=%lu(ms)rnrn", dwTimerX );
         }
         break;
      default:
         {
            printf( "rnTx Completed With Unknown Error,Time=%lu(ms)rnrn", dwTimerX );
         }
         break;
      }
      // The source node address
      GetRxMessageNode( 0X00, ( short * )&iSource );
      // The packet attribute
      GetRxMessageAttr( 0X00, ( char * )&iAttr );
      // The packet size
      GetRxMessageSize( 0X00, &dwSize );
      // Allocate the buffer for the message
      pBuffer = ( char * )malloc( dwSize );
      // Read this message
      ReadInputMessage( 0X00, pBuffer, dwSize );
      // Report the message: source node address
      printf( "rnSource=0X%04Xrn", iSource );
      // Report the message: attribute
      printf( "Attribute=0X%02Xrn", iAttr );
      // Report the message: size
      printf( "Size=%lu bytesrn", dwSize );
     
      // Report the message: contents     
      printf( "Contents:rnrn" );
      // Check if print mode
      if ( dwBinMode )
      {
         // The byte contents of the input buffer
         for ( dwIndex = 0X00; dwIndex < dwSize; dwIndex++ )
         {
            printf( "%02X ", (unsigned char)pBuffer[dwIndex] );
         }        
      }
      else
      {
         printf( "%srn", pBuffer );
      }
      // free the buffer
      free( pBuffer );
   }
   // Stop the shell
   StopWiMinetShell( 0X00 );
   // Exit this main program
   return 0X01;
}

6.7 测试程序说明

首先询问收到报文之后的内容显示格式,输入0代表输入为字符串型可打印字符,以文本格式显示;输入1位二进制不可打印字符,以十六进制显示。(如下图所示)



在开始接收之后,会显示时间和接收进度的信息。(如下图所示)


二进制格式显示模式:接收完成之后,以显示接收的结果,原站点地址,报文属性,报文大小;最后以二进制格式显示报文内容。(如下图所示)


文本格式显示模式:接收完成之后,以显示接收的结果,原站点地址,报文属性,报文大小;最后以文本格式显示报文内容。(如下图所示)