GPSモジュールは確かにデータを受信していて、エラーも出ていません。しかし、肝心のそのデータを出力することができません。
今実行しようとしているファイルには3つのプロジェクトが入っています。
①SunSpotAplicationAdapter.java
- コード: 全て選択
package org.sunspotworld;
import com.sun.spot.peripheral.*;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.io.*;
import com.sun.spot.sensorboard.peripheral.*;
import com.sun.spot.util.*;
import javax.microedition.midlet.*;
public abstract class SunSpotApplicationAdapter extends MIDlet {
protected ISpot spot = Spot.getInstance();
protected ISleepManager sleepManager = spot.getSleepManager();
protected EDemoBoard eDemo = EDemoBoard.getInstance();
protected ITriColorLED[] leds = eDemo.getLEDs();
protected IScalarInput[] scalarInputs = eDemo.getScalarInputs();
protected IIOPin[] ioPins = eDemo.getIOPins();
protected IOutputPin[] outputPins = eDemo.getOutputPins();
protected ISwitch[] switches = eDemo.getSwitches();
protected ITriColorLED led1 = leds[EDemoBoard.LED1];
protected ITriColorLED led2 = leds[EDemoBoard.LED2];
protected ITriColorLED led3 = leds[EDemoBoard.LED3];
protected ITriColorLED led4 = leds[EDemoBoard.LED4];
protected ITriColorLED led5 = leds[EDemoBoard.LED5];
protected ITriColorLED led6 = leds[EDemoBoard.LED6];
protected ITriColorLED led7 = leds[EDemoBoard.LED7];
protected ITriColorLED led8 = leds[EDemoBoard.LED8];
protected IScalarInput a0 = scalarInputs[EDemoBoard.A0];
protected IScalarInput a1 = scalarInputs[EDemoBoard.A1];
protected IScalarInput a2 = scalarInputs[EDemoBoard.A2];
protected IScalarInput a3 = scalarInputs[EDemoBoard.A3];
protected IScalarInput a4 = scalarInputs[EDemoBoard.A4];
protected IScalarInput a5 = scalarInputs[EDemoBoard.A5];
protected IIOPin d0 = ioPins[EDemoBoard.D0];
protected IIOPin d1 = ioPins[EDemoBoard.D1];
protected IIOPin d2 = ioPins[EDemoBoard.D2];
protected IIOPin d3 = ioPins[EDemoBoard.D3];
protected IIOPin d4 = ioPins[EDemoBoard.D4];
protected IOutputPin h0 = outputPins[EDemoBoard.H0];
protected IOutputPin h1 = outputPins[EDemoBoard.H1];
protected IOutputPin h2 = outputPins[EDemoBoard.H2];
protected IOutputPin h3 = outputPins[EDemoBoard.H3];
protected ISwitch sw1 = switches[EDemoBoard.SW1];
protected ISwitch sw2 = switches[EDemoBoard.SW2];
protected void startApp() throws MIDletStateChangeException {
new BootloaderListener().start(); // monitor the USB (if connected) and recognize commands from host
try {
setup();
while (true) {
loop();
}
} catch (InterruptedException ignore) {
} catch (Exception e) {
e.printStackTrace();
}
try {
cleanup();
} catch (Exception e) {
e.printStackTrace();
}
notifyDestroyed(); // cause the MIDlet to exit
}
protected void setup() throws Exception {
}
protected void loop() throws Exception {
exitLoop();
}
protected void exitLoop() throws InterruptedException {
throw new InterruptedException();
}
protected void cleanup() throws Exception {
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
if (unconditional) {
try {
cleanup();
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new MIDletStateChangeException();
}
}
protected static void sleep(long milliseconds) {
Utils.sleep(milliseconds);
}
}
②SunSpotGPS.java
- コード: 全て選択
package org.sunspotworld;
import com.sun.squawk.io.BufferedReader;
import java.io.InputStreamReader;
public class SunSpotGPS extends SunSpotApplicationAdapter {
BufferedReader in;
protected void setup() throws Exception {
System.out.println("setup");
in = new BufferedReader(new InputStreamReader(new UARTInputStream(9600)));
}
protected void loop() throws Exception {
String sentence = in.readLine();
System.out.println(sentence);
if (sw1.isClosed()) {
exitLoop();
}
}
protected void cleanup() throws Exception {
System.out.println("cleanup");
in.close();
}
}
③UARTInputStream.java
- コード: 全て選択
package org.sunspotworld;
import com.sun.spot.sensorboard.EDemoBoard;
import java.io.IOException;
import java.io.InputStream;
public class UARTInputStream extends InputStream {
private EDemoBoard eDemo;
private long timeout;
public UARTInputStream(int baud) {
this(baud, false, 0);
}
public UARTInputStream(int baud, boolean twoStopBit) {
this(baud, twoStopBit, 0);
}
public UARTInputStream(int baud, boolean twoStopBit, long timeout) {
this.timeout = timeout;
eDemo = EDemoBoard.getInstance();
eDemo.initUART(baud, twoStopBit);
}
public int available() throws IOException {
return timeout > 0 ? (int) eDemo.readUART(timeout) : (int) eDemo.readUART();
}
public int read() throws IOException {
return timeout > 0 ? (int) eDemo.readUART(timeout) : (int) eDemo.readUART();
}
public int read(byte[] b, int off, int len) throws IOException {
return timeout > 0 ? super.read(b, off, len) : eDemo.readUART(b, off, len);
}
}
配線は資料の通りです。
どうして出力できないのでしょうか?
僕たちは恐らく足りない部分があるのだと思っています。
どこが足りないのでしょうか?
よろしくお願いします。