5 public class NXTCommFantom implements NXTComm {
6 private NXTInfo nxtInfo;
8 public native String[] jfantom_find();
9 public native int jfantom_open(String nxt);
10 public native void jfantom_close(int nxt);
11 public native void jfantom_send_data(int nxt, byte [] message, int len, int replyLen);
12 public native byte[] jfantom_read_data(int nxt, int len);
14 public NXTInfo[] search(String name, int protocol) {
15 String[] nxtNames = jfantom_find();
16 NXTInfo[] nxtInfo = new NXTInfo[nxtNames.length];
17 for(int i=0;i<nxtNames.length;i++) {
18 nxtInfo[i] = new NXTInfo();
19 String nxtName = nxtNames[i];
20 nxtInfo[i].btResourceString = nxtName;
21 nxtInfo[i].name = "Unknown";
22 nxtInfo[i].protocol = NXTCommFactory.USB;
23 nxtInfo[i].btDeviceAddress = "";
24 if (nxtName != null) {
25 if (nxtName.length() >= 3 && nxtName.substring(0,3).equals("BTH"))
26 nxtInfo[i].protocol = NXTCommFactory.BLUETOOTH;
27 int startName = nxtName.indexOf("::");
28 if (startName >= 0) startName +=2;
30 if (startName != -1) endName = nxtName.indexOf("::", startName);
31 if (startName >= 0 && endName >= 0) {
32 nxtInfo[i].name = nxtName.substring(startName, endName);
33 nxtInfo[i].btDeviceAddress = nxtName.substring(endName+2);
40 public boolean open(NXTInfo nxtInfo) {
41 this.nxtInfo = nxtInfo;
42 nxtInfo.nxtPtr = jfantom_open(nxtInfo.btResourceString);
47 jfantom_close(nxtInfo.nxtPtr);
50 public byte [] sendRequest(byte [] data, int replyLen) {
51 jfantom_send_data(nxtInfo.nxtPtr, data, data.length, replyLen-1);
52 return jfantom_read_data(nxtInfo.nxtPtr, replyLen);
55 public byte [] read() throws IOException {
56 throw new IOException("Not implemented");
59 public void write(byte [] data) throws IOException {
60 throw new IOException("Not implemented");
63 public OutputStream getOutputStream() {
67 public InputStream getInputStream() {
72 System.loadLibrary("jfantom");