Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Electronic Equipment > Cellular Bluetooth > Bluetooth Liste...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 2678 of 2797
Post > Topic >>

Bluetooth Listener and Sending Problem

by "mross462@[EMAIL PROTECTED] " <mross462@[EMAIL PROTECTED] > Nov 27, 2007 at 07:57 PM

Hello All,

I'm currently having Trouble Sending and or Receiving a character over
a BT connection from a Blackberry Pearl to a Parani ESD200.

I've included my code below.

Thanks,

M. Ross

/*
 * BluetoothListener.java
 *
 * Created on November 27, 2007, 12:43 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hello;

im****t javax.bluetooth.*;
im****t javax.microedition.io.*;
im****t java.lang.*;
im****t java.util.Vector;
im****t java.io.*;
/**
 *
 * @[EMAIL PROTECTED]
 Mike Ross
 */
public class BluetoothListener implements DiscoveryListener{
   public LocalDevice local;
   public RemoteDevice remote;
   public DiscoveryAgent agent;
   public boolean inquiryStarted;
   public String remoteDeviceName;
   public DiscoveryListener listener;
   public String url;
   public char readCharacter;
   public DataInputStream in;
   public DataOutputStream out;
   public String deviceName;
   public int accecpting;
   public String passcode = "9153094887#";
   public char [] passcodeArray = passcode.toCharArray();
   public Vector devices = new Vector();
   public Vector services = new Vector(); // ServiceRecord
   public RemoteDevice[] device;
   int inquiryResult;
   int inquiryTrials;
   UUID[] uuidSet;
   UUID serviceUUID = new UUID(0x003);


    /** Creates a new instance of BluetoothListener */
    public BluetoothListener() {
    }

    public void beginBluekeys() throws BluetoothStateException{

       try{
              local = LocalDevice.getLocalDevice();
              agent = local.getDiscoveryAgent();
              device = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
       }

       catch(BluetoothStateException e){
       }
        try{


            int n = 0;
            remote = device[n];

            while (remote.getFriendlyName(true) != "Bluekeys"){

                remote = device[n];
                n++;

            }

       }
       catch (IOException e){}
       catch (NullPointerException e){}
       catch (ArrayIndexOutOfBound***ception e){}

       try{
                // Search Services
                agent.searchServices(null,new UUID[] {new
UUID(0x003)},remote,this);

                // Get bluetooth address and set URL
                String BID = remote.getBluetoothAddress();


                String serviceURL = "bttsp://" + BID + ":1";


                //Set Stream Connection Nofitifer and Service Record
                StreamConnectionNotifier notifier =
(StreamConnectionNotifier) Connector.open(serviceURL);

                ServiceRecord serviceRecord =
local.getRecord(notifier);
                StreamConnection connect =(StreamConnection)
Connector.open(serviceURL, Connector.READ_WRITE, true);
                //Open Connection and In and Out Data Streams

                in = connect.openDataInputStream();
                out = connect.openDataOutputStream();

                // Wait For Hardware Handshaking

                while(in.read() != 'A'){
                    out.write('s');
                }

                // Hardware Has Shaken Hands

                int i = 0;

                // Send Passcode to device and wait for "C"

                while(in.read() != 'C'){

                    //Check for last accepctance
                    if (in.read() == 'A'){

                        // Write Current Passcode Character

                        out.write(passcodeArray[i]);
                        i++;

                    }

                    // If A Not Found, decrement to begining of
Passcode array

                    else{

                        while (i >= 0){
                            i--;
                        }
                    }

                }

                // If complete then start At Begining of array for
next exectue.
                while (in.read() == 'C' & i >=0) i--;
       }

       catch(IOException e){
           System.out.println("IO Exception Caught");
           return;
       }
    }

   public void deviceDiscovered(RemoteDevice btDevice, DeviceClass
cod) {
		if (!devices.contains(btDevice)) {
			devices.addElement(btDevice);
		}
   }

   public void inquiryCompleted(int discType) {
		inquiryResult = discType;
		synchronized (this) {
			notify();
   }
   }

   public void servicesDiscovered(int transID, ServiceRecord[]
servRecord) {
		services.addElement(servRecord[0]);
   }

   public void serviceSearchCompleted(int transID, int respCode) {
		synchronized (this) {
			notify();
		}
   }

}
 




 1 Posts in Topic:
Bluetooth Listener and Sending Problem
"mross462@[EMAIL PRO  2007-11-27 19:57:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Aug 30 3:03:49 CDT 2008.