PrintfClient工具的使用

 

一、实验目的

通过本实验的课程教学,主要是让用户了解以下内容:

1.通过本实验了解串口调试的方法

2.通过本实验掌握串口调试函数的使用     

3.通过本实验掌握PrintfClient工具的使用

二、实验步骤

1.上传编译代码

点击浏览按钮上传TestPrintf代码,点击编译按钮编译实验代码,编译提示信息如下


图3-1 实验代码上传


图3-2上传编译界面

2.烧录代码

选择0号点烧录TestPrintf代码,烧录提示信息如下:


图3-3 烧录提示信息

3.工具使用

选中0号节点,点击收数按钮,可选择Printf收数和Listen收数,收数成功会在右方提示信息里显示。


图3-4 收数操作


图3-5 操作提示信息

4.实验结果显示

点击下一步查看实验结果。如果想停止收数,回到Step2选中节点点击停止按钮即可。图8-6是Listen机制监听到的数据包,图8-7是用PrintfClient机制打印出的信息。


图3-6 实验结果展示1


图3-7 实验结果展示2

三、实验分析

1.TinyOS编程模式分析

TinyOS的编程方式采用nesc语言,这是一种类C语言,nesc语言有几个最重要概念:组件,接口,模块。如下图TestPrintf组件图:

图3-8 TestPrintfC组件图

TestPrintf示例很简单,这里主要讲解Printf原理。

首先介绍下打印的原理, PrintfClient工具在PC端TinyOS系统下的命令为:

$ java net.tinyos.tools.PrintfClient –comm serial@/dev/ttyUSB0:telosb

命令中的net.tinyos.tools. PrintfClient是TinyOS下support/sdk/java中的一个程序, /dev/ttyUSB0是对应的串口号,当我们选中0号节点打印时,客户端就会告诉服务器去执行此命令,这样我们就能获得该节点对应的打印信息。

这里介绍一下TestPrintfC.nc的代码。

TestPrintfC.nc

 
源码
/*-----------代码截取于TestPrintf/TestPrintfC.nc----------*/  
    
#include "printf.h"  
module TestPrintfC {  
    uses {  
        interface Boot;  
        interface Timer< TMilli> as Timer0;  
    }  
}  
implementation {  
      
    uint8_t dummyVar1 = 123;  
    uint16_t dummyVar2 = 12345;  
    uint32_t dummyVar3 = 1234567890;  
      
    event void Boot.booted() {  
        call Timer0.startPeriodic( 1000 );    
    }  
      
    //节点上电后触发Boot.booted事件,该事件触发定时器,每1秒打印一次调试信息   
    event void Timer0.fired()   
      
        printf("Hi I am writing to you from my TinyOS application!!\n");  
        printf("Here is a uint8: %u\n", dummyVar1);  
        printf("Here is a uint16: %u\n", dummyVar2);  
        printf("Here is a uint32: %ld\n\n", dummyVar3);  
        printfflush();  
    }  
}  
    

  

实验源代码

//Makefile
COMPONENT=TestPrintfAppC
CFLAGS += -I$(TOSDIR)/lib/printf

include $(MAKERULES)

 

//TestPrintfAppC.nc
#include "printf.h"

configuration TestPrintfAppC{
}
implementation {
  components MainC, TestPrintfC;
  components new TimerMilliC() as Timer0;
  components PrintfC;
  components SerialStartC;
  TestPrintfC.Boot -> MainC;
  TestPrintfC.Timer0 -> Timer0;
}
//TestPrintfC.nc
#include "printf.h"
module TestPrintfC {
  uses {
    interface Boot;
    interface Timer<TMilli> as Timer0;
  }
}
implementation {
	
  uint8_t dummyVar1 = 123;
  uint16_t dummyVar2 = 12345;
  uint32_t dummyVar3 = 1234567890;

  event void Boot.booted() {

          call Timer0.startPeriodic( 1000 );  
  }

 event void Timer0.fired()
  {
   	printf("Hi I am writing to you from my TinyOS application!!\n");
  	printf("Here is a uint8: %u\n", dummyVar1);
  	printf("Here is a uint16: %u\n", dummyVar2);
  	printf("Here is a uint32: %ld\n\n", dummyVar3);
  	printfflush();
  }
}

 

五、课后习题

习题:

在示例代码中使用counter计数,定时器每触发一次,counter就自加1,并用printf打印出来。

 

 

posted @   枫让  阅读(95)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示