?? mote-pc serial communication and serialforwarder - tinyos documentation wiki.htm
字號:
?<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0081)http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder -->
<HTML lang=en dir=ltr xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META
content="Mote-PC serial communication and SerialForwarder,Mote-PC serial communication and SerialForwarder,Getting Started with TinyOS,Mote-mote radio communication,Sensing"
name=keywords><LINK href="/favicon.ico" rel="shortcut icon"><LINK
title="TinyOS Documentation Wiki (English)" href="/opensearch_desc.php"
type=application/opensearchdescription+xml rel=search>
<STYLE type=text/css media="screen, projection">@import url( /skins/common/shared.css?97 );
@import url( /skins/monobook/main.css?97 );
</STYLE>
<LINK media=print
href="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/commonPrint.css"
type=text/css rel=stylesheet><!--[if lt IE 5.5000]><style type="text/css">@import "/skins/monobook/IE50Fixes.css?97";</style><![endif]--><!--[if IE 5.5000]><style type="text/css">@import "/skins/monobook/IE55Fixes.css?97";</style><![endif]--><!--[if IE 6]>
<STYLE type=text/css>@import url( /skins/monobook/IE60Fixes.css?97 );
</STYLE>
<![endif]--><!--[if IE 7]><style type="text/css">@import "/skins/monobook/IE70Fixes.css?97";</style><![endif]--><!--[if lt IE 7]>
<SCRIPT
src="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/IEFixes.js"
type=text/javascript></SCRIPT>
<META http-equiv=imagetoolbar content=no><![endif]-->
<SCRIPT type=text/javascript>/*<![CDATA[*/var skin = "monobook";var stylepath = "/skins";var wgArticlePath = "/index.php/$1";var wgScriptPath = "";var wgScript = "/index.php";var wgServer = "http://docs.tinyos.net";var wgCanonicalNamespace = "";var wgCanonicalSpecialPageName = false;var wgNamespaceNumber = 0;var wgPageName = "Mote-PC_serial_communication_and_SerialForwarder";var wgTitle = "Mote-PC serial communication and SerialForwarder";var wgAction = "view";var wgRestrictionEdit = [];var wgRestrictionMove = [];var wgArticleId = "10";var wgIsArticle = true;var wgUserName = null;var wgUserGroups = null;var wgUserLanguage = "en";var wgContentLanguage = "en";var wgBreakFrames = false;var wgCurRevisionId = "273";/*]]>*/</SCRIPT>
<SCRIPT
src="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/wikibits.js"
type=text/javascript><!-- wikibits js --></SCRIPT>
<SCRIPT
src="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/index.php"
type=text/javascript><!-- site js --></SCRIPT>
<STYLE type=text/css>@import url( /index.php?title=MediaWiki:Common.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000 );
@import url( /index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000 );
@import url( /index.php?title=-&action=raw&gen=css&maxage=18000 );
</STYLE>
<!-- Head Scripts -->
<SCRIPT
src="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/ajax.js"
type=text/javascript></SCRIPT>
<META content="MSHTML 6.00.2900.3268" name=GENERATOR></HEAD>
<BODY
class="mediawiki ns-0 ltr page-Mote-PC_serial_communication_and_SerialForwarder">
<DIV id=globalWrapper>
<DIV id=column-content>
<DIV id=content><A id=top name=top></A>
<H1 class=firstHeading>Mote-PC serial communication and SerialForwarder</H1>
<DIV id=bodyContent>
<H3 id=siteSub>From TinyOS Documentation Wiki</H3>
<DIV id=contentSub></DIV>
<DIV id=jump-to-nav>Jump to: <A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#column-one">navigation</A>,
<A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#searchInput">search</A></DIV><!-- start content -->
<P>To goal of this lesson is to show you how to communicate with a mote from a
PC. This will allow you to collect data from the network, send commands to
motes, and monitor network traffic. </P>
<P>This tutorial presents the Java-based infrastructure for communicating with
motes. There is also a C-based infrastructure, found in support/sdk/c. Please
see the documentation found there, and the <CODE>mig</CODE> and <CODE>ncg</CODE>
man pages for more details. </P>
<TABLE class=toc id=toc summary=Contents>
<TBODY>
<TR>
<TD>
<DIV id=toctitle>
<H2>Contents</H2></DIV>
<UL>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Packet_sources_and_TestSerial"><SPAN
class=tocnumber>1</SPAN> <SPAN class=toctext>Packet sources and
TestSerial</SPAN></A>
<UL>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Cannot_find_JNI_error"><SPAN
class=tocnumber>1.1</SPAN> <SPAN class=toctext>Cannot find JNI
error</SPAN></A>
<UL>
<LI class=toclevel-3><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Installing_tos-install-jre_from_CVS_sources"><SPAN
class=tocnumber>1.1.1</SPAN> <SPAN class=toctext>Installing
tos-install-jre from CVS sources</SPAN></A> </LI></UL>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#MOTECOM"><SPAN
class=tocnumber>1.2</SPAN> <SPAN class=toctext>MOTECOM</SPAN></A>
</LI></UL>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#BaseStation_and_net.tinyos.tools.Listen"><SPAN
class=tocnumber>2</SPAN> <SPAN class=toctext>BaseStation and
net.tinyos.tools.Listen</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#MIG:_generating_packet_objects"><SPAN
class=tocnumber>3</SPAN> <SPAN class=toctext>MIG: generating packet
objects</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#SerialForwarder_and_other_packet_sources"><SPAN
class=tocnumber>4</SPAN> <SPAN class=toctext>SerialForwarder and other
packet sources</SPAN></A>
<UL>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Packet_Sources"><SPAN
class=tocnumber>4.1</SPAN> <SPAN class=toctext>Packet
Sources</SPAN></A>
<LI class=toclevel-2><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#The_tool_side"><SPAN
class=tocnumber>4.2</SPAN> <SPAN class=toctext>The tool
side</SPAN></A> </LI></UL>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Sending_a_packet_to_the_serial_port_in_TinyOS"><SPAN
class=tocnumber>5</SPAN> <SPAN class=toctext>Sending a packet to the
serial port in TinyOS</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Related_Documentation"><SPAN
class=tocnumber>6</SPAN> <SPAN class=toctext>Related
Documentation</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#CLASSPATH_and_Java_classes"><SPAN
class=tocnumber>7</SPAN> <SPAN class=toctext>CLASSPATH and Java
classes</SPAN></A> </LI></UL></TD></TR></TBODY></TABLE>
<SCRIPT type=text/javascript> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </SCRIPT>
<A name=Packet_sources_and_TestSerial></A>
<H1><SPAN class=mw-headline>Packet sources and TestSerial</SPAN></H1>
<P>The first step is to check that you are able to get your PC to communicate
with a mote. Most motes have a serial port or similar interface. For example,
the mica family can directly control a serial port: programming boards basically
connect the mote's serial port pins to the actual serial port on the board.
Telos motes also have a serial interface, but it talks to their USB hardware,
which is similar in functionality but very different in terms of cables and
connectors. </P>
<P>The basic abstraction for mote-PC communication is a <B>packet source</B>. A
packet source is exactly that: a communication medium over which an application
can receive packets from and send packets to a mote. Examples of packet sources
include serial ports, TCP sockets, and the SerialForwarder tool. Most TinyOS
communication tools take an optional <CODE>-comm</CODE> parameter, which allows
you to specify the packet source as a string. For example: </P><PRE>$ java net.tinyos.tools.Listen -comm serial@COM1:telos
</PRE>
<P>tells the Listen tool to use the COM1 serial port (on a Windows machine) at
the correct speed for a telos mote, while </P><PRE>$ java net.tinyos.tools.Listen -comm serial@/dev/ttyS0:micaz
</PRE>
<P>tells Listen to use the serial port <CODE>/dev/ttyS0</CODE> (on a UNIX
machine) at the correct speed for a micaz mote. </P>
<P>The first step to testing your serial port is to install the
<CODE>apps/tests/TestSerial</CODE> application on a mote. This application sends
a packet to the serial port every second, and when it receives a packet over the
serial port it displays the packet's sequence number on the LEDs. </P>
<P>Once you have installed <CODE>TestSerial</CODE>, you need to run the
corresponding Java application that communicates with it over the serial port.
This is built when you build the TinyOS application. From in the application
directory, type: </P><PRE>$ java TestSerial
</PRE>
<P>If you get a message like </P><PRE>The java class is not found: TestSerial
</PRE>
<P>it means that you either haven't compiled the Java code (try running
<CODE>make <I>platform</I></CODE> again) or you don't have <CODE>.</CODE> (the
current directory) in your Java <CODE>CLASSPATH</CODE>. </P>
<P>Because you haven't specified a packet source, TestSerial will fall back to a
default, which is a SerialForwarder. Since you don't have a SerialForwarder
running, TestSerial will exit, complaining that it can't connect to one. So
let's specify the serial port as the source. The syntax for a serial port source
is as follows: </P><PRE> serial@<PORT>:<SPEED>
</PRE>
<P>PORT depends on your platform and where you have plugged the mote in. For
Windows/Cygwin platforms, it is COM<I>N</I>, where <I>N</I> is the port number.
For Linux/UNIX machines, it is <CODE>/dev/ttyS</CODE><I>N</I> for a built-in
serial port, or one of <CODE>/dev/ttyUSB<I>N</I></CODE> or
<CODE>/dev/usb/tts/<I>N</I></CODE> for a serial-over-USB port. Additionally as
we saw in <A title="Getting Started with TinyOS"
href="http://docs.tinyos.net/index.php/Getting_Started_with_TinyOS">lesson
1</A>, on Linux you will typically need to make this serial port world
writeable. As superuser, execute the following command: </P><PRE>chmod 666 <I>serialport</I>
</PRE>
<P>The SPEED can either be a numeric value, or the name of a platform.
Specifying a platform name tells the serial packet source to use the default
speed for the platform. Valid platforms are: </P>
<CENTER>
<TABLE>
<TBODY>
<TR>
<TD>Platform </TD>
<TD>Speed (baud) </TD></TR>
<TR>
<TD colSpan=2>
<HR>
</TD></TR>
<TR>
<TD>telos </TD>
<TD>115200 </TD></TR>
<TR>
<TD>telosb </TD>
<TD>115200 </TD></TR>
<TR>
<TD>tmote </TD>
<TD>115200 </TD></TR>
<TR>
<TD>micaz </TD>
<TD>57600 </TD></TR>
<TR>
<TD>mica2 </TD>
<TD>57600 </TD></TR>
<TR>
<TD>mica2dot </TD>
<TD>19200 </TD></TR>
<TR>
<TD>eyes </TD>
<TD>115200 </TD></TR>
<TR>
<TD>intelmote2 </TD>
<TD>115200 </TD></TR></TBODY></TABLE></CENTER>
<P>The Java file <TT>support/sdk/java/net/tinyos/packet/BaudRate.java</TT>
determines these mappings. Unlike in TinyOS 1.x, all platforms have a common
serial packet format. Following the table, these two serial specfications are
identical: </P><PRE>serial@COM1:micaz
serial@COM1:57600
</PRE>
<P>If you run <CODE>TestSerial</CODE> with the proper PORT and SPEED settings,
you should see output like this: </P><PRE>Sending packet 1
Received packet sequence number 4
Sending packet 2
Received packet sequence number 5
Sending packet 3
Received packet sequence number 6
Sending packet 4
Received packet sequence number 7
Received packet sequence number 8
Sending packet 5
Received packet sequence number 9
Sending packet 6
</PRE>
<P>and the mote LEDs will blink. </P><A name=Cannot_find_JNI_error></A>
<H2><SPAN class=mw-headline>Cannot find JNI error</SPAN></H2>
<P>If you try to run TestSerial and receive an error that Java cannot find
TOSComm JNI support, this means the Java Native Interface (JNI) files that
control the serial port haven't been correctly installed. Run the command
<CODE>tos-install-jni</CODE> (on Linux, do this as the superuser). If this
command does not exist, then you have either not installed the tinyos-tools RPM
or it was installed incorrectly. The <TT>tos-</TT> commands are typically
installed in /usr/bin. If you still cannot find the script, email
<TT>tinyos-help</TT>. </P><A
name=Installing_tos-install-jre_from_CVS_sources></A>
<H3><SPAN class=mw-headline>Installing <TT>tos-install-jre</TT> from CVS
sources</SPAN></H3>
<P>If you have not installed the tools RPM and are working directly from the
TinyOS CVS repository, you can manually install the tos-locate-jre script. Go to
<CODE>tinyos-2.x/tools/tinyos/java</CODE>. If the directory has a
<CODE>Makefile</CODE> in it, type <CODE>make</CODE> and (again, on Linux, as
superuser) <CODE>make install</CODE>. If the directory does not have a
<CODE>Makefile</CODE>, go to <CODE>tinyos-2.x/tools</CODE> and type: </P><PRE>$ ./Bootstrap
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -