Input- Outputstream via Bluetooth

Post your NXJ projects, project ideas, etc here!

Moderators: roger, 99jonathan, imaqine

Input- Outputstream via Bluetooth

Postby pitti » Thu Jan 13, 2011 8:09 am

Hello
I would connect via bluetooth to send Arrays....
There is my code:
Code: Select all
import java.io.InputStream;
import javax.microedition.io.*;
import java.io.OutputStream;
import lejos.pc.comm.NXTInfo;
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommUSB;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTCommBluez;
public class ConnectBlueNXT{
    public static void main(String[] args) throws Exception{
   System.out.println("Test");
   //NXTComm comm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
   NXTCommBluez comm = new NXTCommBluez();
   NXTInfo info = new NXTInfo(NXTComm.RAW, "Robin", "00:16:53:06:3e:af");
   comm.open(info);
   System.out.println("Connected!");
   comm.close();
    }
}

If I execute, I get this error:
/usr/lib/jvm/java-6-openjdk/bin/java ConnectBlueNXT

Test
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jbluez in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at lejos.pc.comm.NXTCommBluez.<clinit>(NXTCommBluez.java:23)
at ConnectBlueNXT.main(ConnectBlueNXT.java:13)

Process ConnectBlueNXT exited abnormally with code 1



What can I do?[/code]
Last edited by pitti on Thu Jan 13, 2011 8:28 pm, edited 1 time in total.
pitti
New User
 
Posts: 7
Joined: Wed Jan 12, 2011 10:24 pm

Re: Bluetoothconnect

Postby Shawn » Thu Jan 13, 2011 8:43 am

pitti wrote:
Code: Select all
   //NXTComm comm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
   NXTCommBluez comm = new NXTCommBluez();
 



I would try using:
Code: Select all
lejos.pc.comm.NXTConnector


I think it will end up using bluecove which there is a jar for. I'm not sure NXTCommBluez is used anymore.

Code: Select all
NXTConnector conn = new NXTConnector();

   conn.setDebug(true);
   conn.addLogListener(new NXTCommLogListener() {

       public void logEvent(String arg0) {
       //add logging
       }

       public void logEvent(Throwable arg0) {
       //add logging
       }
   });

       conn.connectTo("btspp://");
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

Postby pitti » Thu Jan 13, 2011 4:43 pm

Mhhh.... now.... my code:

import java.io.InputStream;
import javax.microedition.io.*;
import java.io.OutputStream;
import lejos.pc.comm.NXTInfo;
import lejos.pc.comm.NXTConnector;
import lejos.pc.comm.NXTCommLogListener;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTCommBluez;
public class ConnectBlueNXT{
public static void main(String[] args) throws Exception{
System.out.println("Test");
//NXTComm comm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
//NXTCommBluez comm = new NXTCommBluez();
//NXTInfo info = new NXTInfo(NXTComm.RAW, "Robin", "00:16:53:06:3e:af");
//comm.open(info);
//System.out.println("Connected!");
//comm.close();

NXTConnector conn = new NXTConnector();

conn.setDebug(true);
conn.addLogListener(new NXTCommLogListener() {

public void logEvent(String arg0) {
//add logging
}

public void logEvent(Throwable arg0) {
//add logging
}
});

conn.connectTo("btspp://00:16:53:06:3e:af");
}
}


and the error:

/usr/lib/jvm/java-6-openjdk/bin/java ConnectBlueNXT

Test
Exception in thread "main" java.lang.ClassCastException: javax.microedition.io.Connector$1 cannot be cast to javax.microedition.io.StreamConnection
at lejos.pc.comm.NXTCommBluecove.open(NXTCommBluecove.java:120)
at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:229)
at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:328)
at lejos.pc.comm.NXTConnector.connectTo(NXTConnector.java:337)
at ConnectBlueNXT.main(ConnectBlueNXT.java:33)

Process ConnectBlueNXT exited abnormally with code 1



I think, that bluez use the unix libary and bluecove use the windows libary...
pitti
New User
 
Posts: 7
Joined: Wed Jan 12, 2011 10:24 pm

Postby pitti » Thu Jan 13, 2011 8:36 pm

Okay.... now I've connect... I must compile with nxjpcc and start with nxjpcc.
But now I can't send a array of bytes...

there my pc-program:

Code: Select all
import java.io.InputStream;
import java.io.OutputStream;
import lejos.pc.comm.NXTInfo;
import lejos.pc.comm.NXTCommBluecove;
import lejos.pc.comm.NXTCommException;
public class ConnectBlueNXT{
    public static void main(String[] args) throws Exception{
   NXTInfo nxtInfo = new NXTInfo();
   nxtInfo.deviceAddress = "001653063EAF";   
   NXTCommBluecove com = new NXTCommBluecove();
   InputStream is = com.getInputStream();
   OutputStream os = com.getOutputStream();
   byte[] b;
   String test = "Testpups";
   //b = test.getBytes();
   //String test2 = new String(b);
   System.out.println(test2);
   try {
       com.open(nxtInfo);

   } catch (NXTCommException e) {
       e.printStackTrace();
   }
   os.write(b);
   os.close();
   com.close();
   System.out.println("AUS");
    }
}


And there my nxt-program:

Code: Select all
import lejos.nxt.*;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import java.io.InputStream;
import java.io.OutputStream;
public class Printer{

    private static ExitNXT exit;

    public static void main(String[] args)throws Exception{

   String a ="Testpups";
   byte[] b = new byte[a.length()];
   exit = new ExitNXT();
   exit.start();

   // Wartet solange, bis eine Bluetoothverbindung eingegangen wird.
   // Diese Funktion ist blockierend!
   System.out.println("warte auf Bluethooth");
   BTConnection btc = Bluetooth.waitForConnection();
   System.out.println("Bluethoothverbindung... JUHU");
   // Input- und OutputStream abfragen.
   InputStream is = btc.openInputStream();
   OutputStream os = btc.openOutputStream();
   is.read(b);
   is.close();
   String inhalt = new String(b);
   System.out.println(inhalt);
   for (int i=0;i<b.length;i++) System.out.print(b[i]);
      
    }
}



The output of "System.out.println(inhalt);" are 8 little squares and the output of for (int i=0;i<b.length;i++) System.out.print(b[i]); are "00000000";

What can I do?
pitti
New User
 
Posts: 7
Joined: Wed Jan 12, 2011 10:24 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff