4 Replies - 1599 Views - Last Post: 22 September 2009 - 07:13 AM Rate Topic: -----

#1 irobot  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 02-August 09

can't run bluetooth application

Posted 20 September 2009 - 03:21 AM

hello all, i am developing a bluetooth application where the client can send a command and it will execute a method on the server which is a PC. I am using the bluecove stack for the pc side. My problem is that i can run the application inside netbeans and the server discovers the devices and does what it suppose to do. but when i try to run it on windows command prompt, it doesn't compile, it just says "Bluecove stack shutdown completed". How can i get around this problem. i am using the microsoft bluetooth stack on windows vista and a belkin usb bluetooth dongle.

i need to work around this cos i can't test if my client code is connecting to it on Netbeans IDE. Thanks

here is the server code in case it helps:


import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
//import java.io.InputStreamReader;
import java.io.OutputStream;
import javax.bluetooth.*;
//import javax.microedition.io.Connector;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

public class BTHomeServer implements Runnable, DiscoveryListener {

	private RemoteDevice remote;
	private DiscoveryAgent agent;
   private static Vector DeviceFound = new Vector();
   StreamConnectionNotifier bthserver;
   StreamConnection connect;
   final Object InqCompleted = new Object();

   
   ServiceRecord servicerecord = null;


public void homeserver() throws BluetoothStateException, InterruptedException, IOException {
		synchronized(InqCompleted){

		DeviceFound.clear();
		LocalDevice local = LocalDevice.getLocalDevice();
					local.setDiscoverable(DiscoveryAgent.GIAC);
					local.getBluetoothAddress();
					local.getFriendlyName();

					agent = local.getDiscoveryAgent();
					agent.startInquiry(DiscoveryAgent.GIAC, this);

		System.out.println(" Name " + local.getFriendlyName());
		System.out.println(" Bluetooth Address " + local.getBluetoothAddress());

		InqCompleted.wait();
		}

		  

		  /* String url = "btspp://localhost:881c37af44a5485fac1bdfff78d595bb;name= BtHomeserver";
		   StreamConnectionNotifier bthserver = (StreamConnectionNotifier)Connector.open(url);
		   LocalDevice local = LocalDevice.getLocalDevice();
		   servicerecord = local.getRecord(bthserver);
		   connect = bthserver.acceptAndOpen();*/



		 /*while(connect!=null){
			 byte[] b = new byte[1000];
			 connect.openDataOutputStream();
			 
		 }*/

   }

	public void run() {
		
	}

	//@SuppressWarnings("empty-statement")
	public void deviceDiscovered(RemoteDevice btdevice, DeviceClass cod) {
		//throw new UnsupportedOperationException("Not supported yet.");
		System.out.println(" Device Found = " + btdevice.getBluetoothAddress());

		try {
			System.out.println(" Device Name = " + btdevice.getFriendlyName(false));
		} catch (IOException ex) {
			Logger.getLogger(BTHomeServer.class.getName()).log(Level.SEVERE, null, ex);
		}
			   DeviceFound.addElement(InqCompleted);

		/*RemoteDevice[] agent2 = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
		if(agent2 != null){
			int s = agent2.length;
			for(int i = 0; i<s; i++){
				DeviceFound.elementAt(i);
		 System.out.print((i+1)+ ". Hi " + btdevice.getBluetoothAddress());
			}
		}*/

	}

	public RemoteDevice[] retrieveDevices(int PREKNOWN)throws IllegalArgumentException, IOException {

		RemoteDevice[] trusted = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);

		if(trusted != null){
		for (int i = 0; i<trusted.length; i++){
			 //RemoteDevice remote =
			System.out.println(" only u " +trusted[i]);
			System.out.println(" hey you " +trusted[1]);

		}
	   
		String url = "btspp://localhost:1101;name= BtHomeserver;master=true";
		   StreamConnectionNotifier bthserver = (StreamConnectionNotifier)Connector.open(url);
		   LocalDevice local = LocalDevice.getLocalDevice();
		   servicerecord = local.getRecord(bthserver);
		   System.out.println("now waiting for client to connect");
		   connect = bthserver.acceptAndOpen();
		   System.out.println(" hey you7");
		   //connect = bthserver.acceptAndOpen();


		  //String UUID = "881c37af44a5485fac1bdfff78d595bb";
		   //String url = "btspp://localhost:" + UUID + ";name= BtHomeserver";
			//String url = "btspp://localhost:881c37af44a5485fac1bdfff78d595bb;name= BtHomeserver";
		   //StreamConnectionNotifier bthserver = (StreamConnectionNotifier)Connector.open(url);
		   



		   // RemoteDevice btdevice = RemoteDevice.getRemoteDevice(connect);
					InputStream input = connect.openInputStream();
					  BufferedReader bReader = new BufferedReader(new InputStreamReader(input));
					String lineRead = bReader.readLine();
					System.out.println(lineRead);

					OutputStream output = connect.openOutputStream();
				  
					//byte[] b = new byte[1000];

					
					bthserver.close();




		   
		System.out.println(trusted.length);
		}
		return null;
	   
	}
	public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void serviceSearchCompleted(int arg0, int arg1) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void inquiryCompleted(int arg0) {
		System.out.println(" Inquiry Completed ");
		synchronized(InqCompleted){
			InqCompleted.notifyAll();
		}
	}

	private void sayHi() {
	 
			System.out.println("whats up doc!" );

	}

}


  


i need to work around this cos i can't test if my client code is connecting to it on Netbeans IDE. Is there any other way i can run it.

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: can't run bluetooth application

#2 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: can't run bluetooth application

Posted 20 September 2009 - 08:37 AM

You are keeping everything inside the dist folder of the netbeans project together ?
Was This Post Helpful? 0
  • +
  • -

#3 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: can't run bluetooth application

Posted 20 September 2009 - 12:11 PM

Bluetooth can be a pain in the backside to set up. Did you say it works when you run it straight through your ide? I actually dont like using the microsoft stack, can be annoying. You could try a different stack and completely remove the microsot one. Didnt your dongle come with its own stack driver?
Was This Post Helpful? 0
  • +
  • -

#4 irobot  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 02-August 09

Re: can't run bluetooth application

Posted 21 September 2009 - 10:44 AM

Am sorry for not answering earlier because i have been very busy outside coding. yes it worked when i ran it through my IDE, At least it could detect devices and open a server connetion but for some reason i can't connect to it with the client program on my mobile phone( windows mobile). Thats why i wanted to try it in command prompt cos i was not sure if it was the IDE that was he problem or my code for the client. and yes my bluetooth came with the widcomm stack and it gives me the same message when i try it.

bbq,
yes everything is in the dist folder of the netbeans project. I don't know, but is there a problem with doing that? where should i keep them? Thanks for the response.

This post has been edited by irobot: 21 September 2009 - 10:52 AM

Was This Post Helpful? 0
  • +
  • -

#5 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: can't run bluetooth application

Posted 22 September 2009 - 07:13 AM

Nah that should be fine, once you build a project the dist folder generally holds everything you need :/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1