Java Solaris Communities Partners My Sun Sun Store China Worldwide
»   简介
»  简要了解 Sun SPOT
»   Ectoplasmic Bouncing Ball 演示程序
    加载和运行 Air Text 演示程序(当前页)
»   更改 Air Text 演示程序
» 基站实战
 
Sun SPOT 快速入门教程

加载和运行 Air Text 演示程序

 
 

现在,我们将尝试下载另一个 Sun SPOT 演示程序。您将了解如何下载 Java 程序到 Sun SPOT。

编译、部署和运行演示程序

  1. 在 NetBeans 中,依次导航到 Sun SPOT 目录和 Demos 子目录,在 windows 工作站中,其绝对文件路径通常为: C:/Program Files/Sun/SunSPOT/Demos。打开位于 [SunSPOTdirectory]/Demos/AirText 目录中的项目。确保选择的是 "Open as Main Project",然后单击 "Open Project Folder" 按钮。

A screenshot of the NetBeans 'Open Project' dialog box.  The AirText project is selected from the Demo directory.

NetBeans 项目只包含一个 NBProject 文件夹。您可以通过普通编辑器查看它们。

  1. 清除和编译项目,方法为右键单击项目(Macintosh 机为“Crtl+单击”),然后选择 "Clean and Build Project",如下所示:

A screenshot of NetBeans.  The AirText demo has been selected and right-clicked.  A pop-up menu is displayed and the cursor is over an option that reads 'Clean and Build Project.'

或者从主菜单中选择 "Build" 并选择该菜单中的 "Clean and Build Project":

A NetBeans screenshot. The AirText project has been selected.  The cursor has selected 'Build' from the main menu bar and is over an option in the drop down menu which is labeled 'Clean and Build Main Project.'

在命令系统清除和构建项目后,可以看到位于 NetBeans 窗口底部一个打开的输出面板,它显示来自编译操作中的输出。此文本以 "BUILD SUCCESSFUL" 和其构建对象代码所用时间结束。

  1. 将一个移动 Sun SPOT 连接到 USB 电缆线。按 SPOT 控制按钮复位(或者开启)这个移动 Sun SPOT。 右边的 LED 会同步闪烁绿色。
  1. 选择项目窗口中的项目,右击(Macintosh 机为“Crtl+单击”)并在弹出菜单中选择"deploy", 将会从编译代码创建一个 jar 文件并传输到 Sun SPOT。

A NetBeans screenshot.  The cursor has right-clicked the AirText project and is positioned over an item in the pop-up menu.  The item is labeled 'Deploy to Sun SPOT.'.

下载操作将会以 "SPOT client starting... (please reset SPOT on port COMn) [waiting for reset]" 暂停。 按控制按钮继续下载。右边的 LED 会闪烁绿色,表示 Sun SPOT 正试图与主机工作站同步。

如果部署操作成功,NetBeans 窗口底部的输出以下图中的情形结束:

A Netbeans screenshot.  The AirText project is still the main project, but the focus is now on the a console window occupying much of the bottom half of the NetBeans display.  The console is titled 'Output - AirText (jar-deploy)'.  The console window displays text from a command.  The portion visible says 'Download operation completed successfully.  Writing configuration (1081 bytes) to COM5.  Download operation completed successfully. Exiting.'  The second 'Download operation completed' message is circled.

如果没出现 "Download operation completed successfully" 语句,可能是因为 Sun SPOT 没有和主机工作站取得同步,请再次复位 Sun SPOT。


故障排除:如果输出情形如下:

A NetBeans screenshot.  The console window shows output from a command, ending with the words 'Build failed.'  Above this, the words 'Unhandled exception encountered: COM5 is in use.' are circled.

如果输出显示 "COM5 is in use" 或者"Port COMn unavailable...",说明其他的程序正在使用 Sun SPOT,在程序没有完成之前,部署脚本不能进行编写。要解决这个问题,您需要终止其他 Sun SPOT 相关程序,在 NetBeans 窗口的右上方的面板中,有三个标记:Projects、Files 和 Runtime。单击 Runtime 标记。

A NetBeans screenshot. The upper left panel is shown.  There are three tabs in this panel: Project, Files, and Runtime.  The Runtime tab is circled and the cursor is pointing to it.

展开 "Processes" 节点会显示一列正运行的程序。

A NetBeans screenshot. Of the three tabs in the upper left panel, the Runtime tab has been selected.  The panel shows three items at the top level.  These are Servers, Processes and Databases.  The Processes item has been selected and expanded.  One process is show and it has the label 'AirText(run)'. This process has been selected and the cursor is pointing to it.

右击其中一个程序会出现终止该程序的选项。终止所有程序。再次单击项目标志并对 Sun SPOT 部署演示程序。


当成功完成对 Sun SPOT 的代码部署后,关闭 Sun SPOT 并断开它与 USB 电缆的连接。然后按控制按钮开始演示。

注意复位后,情形没有发生任何变化,在您遵循下面的操作之前,传感器板上的 LED 将保持关闭状态。

效果

This is a drawing of someone holding a Sun SPOT in their right hand, with the eDemo board facing towards the viewer and the radio fin to the viewer's left.  The hand is moving the SPOT very rapidly from left to right and the LEDs are blinking as it moves.  It has the effect of spelling out 'SPOT' in the air as the LEDs blink on and off.

该演示在黑暗的房间里会取得更好的效果,但是前提是必须能够看到八个 LED 主字符串的工作情况。高举 Sun SPOT 并使无线电天线鳍暴露到左边。尽可能快速地摆动 Sun SPOT,从左到右地来回摆动十几次,增加摆动的幅度和速度,幅度可以是一英尺或二英尺甚至三英尺。

Sun SPOT 会感知这种加速并开启 LED 然后再关闭,这时,您可以看到空中由 Sun SPOT 产生的文字:"Hi!...This...is a...Sun...SPOT"(您好,我是 Sun SPOT)。

接下来,修改 Air Text 演示程序,并将其加载到 Sun SPOT 中。


下一页:更改 Air Text 演示程序

返回顶部