CellMoz.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bluetooth Listener and Sending Problem

 
Post new topic   Reply to topic    CellMoz.com Forum Index -> Bluetooth
Author Message
mross462



Joined: 28 Nov 2007
Posts: 1

PostPosted: Wed Nov 28, 2007 12:57 am    Post subject: Bluetooth Listener and Sending Problem Reply with quote

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;

import javax.bluetooth.*;
import javax.microedition.io.*;
import java.lang.*;
import java.util.Vector;
import java.io.*;
/**
*
* @author 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 (ArrayIndexOutOfBoundsException 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();
}
}

}

Archived from group: alt>cellular>bluetooth
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CellMoz.com Forum Index -> Bluetooth All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group