You Are Here:

Community: Developer Discussion Boards

#1 Old Connect as master with N82? - 2008-11-28, 16:10

Join Date: Nov 2008
Posts: 3
mikrodidakt1
Offline
Registered User
Hi!

I am trying to connect my N82 as master to a smale device running as slave but I cannot get it to work.

I am using the following code:

con = (StreamConnection) Connector.open("btspp://00011E016848:1;master=true;encrypt=true");
os = con.openOutputStream();
is = con.openInputStream();
os.write(new String("w\n").getBytes());
nbrBytes = is.read(buffer);

while(buffer[nbrBytes - 1] != CR) {
tmp = is.read(data);
for(int i = 0; i < tmp; ++i) {
buffer[nbrBytes + i] = data[i];
}
nbrBytes += tmp;
}

When I am using this url to connect I get a BluetoothConnectionException thrown, if i remove the master=true in the url "btspp://00011E016848:1encrypt=true" I managed to connect but I don't manage to write to the slave device. The strange thing is that the phone thinks everything went ok, no exception, but the slave device don't receive anything. I have managed to run the program on my computer and that works so the there is no problem with the slave device.

Any thoughts would be appreciated.
Reply With Quote

#2 Old Re: Connect as master with N82? - 2008-12-01, 09:12

Join Date: Nov 2008
Posts: 3
mikrodidakt1
Offline
Registered User
I tried using flush but that did not work?

os.write(new String("w\n").getBytes());
os.flush();
Reply With Quote

#3 Old Re: Connect as master with N82? - 2008-12-08, 10:46

Join Date: Nov 2008
Posts: 3
mikrodidakt1
Offline
Registered User
I have tried everything but nothing works, I have managed to run this code on a Sony Ericsson W810 and that works great but for some reasone I can't run this on the N82, I can't use the master=true since then I cannot connect and I if i don't use it i can't write to the device. If you think that this seems correct pleas let me know so that I dont spend any more time on this code It could be that I have to do some modification on the client device to make it run, I just think it seems strange that it works on the SE phone but not on the Nokia, I thought Java was platform independet? Apparently not.

public class HelloMIDlet extends MIDlet implements CommandListener {

private boolean midletPaused = false;
private String alertStr;
private StreamConnection connection;
private InputStream is;
private OutputStream os;
private Command getWCommand;
private Command exitCommand;
private Command conCommand;
private Command closeCommand;
private SimpleCancellableTask task;
private Alert alert;
private WaitScreen waitScreen;
private Form form;
private StringItem stringItem;
...
..
..
public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
if (displayable == form) {
if (command == closeCommand) {
// write pre-action user code here
try {
connection.close();
getForm().removeCommand(getCloseCommand());
getForm().removeCommand(getGetWCommand());
getForm().addCommand(getConCommand());
} catch(IOException e) {
System.out.println(e.toString());
}

// write post-action user code here
} else if (command == conCommand) {
// write pre-action user code here
try {
connection = (StreamConnection) Connector.open("btspp://000BCEA16848:1;encrypt=true");
System.out.println("Connected");
is = connection.openInputStream();
os = connection.openOutputStream();
System.out.println("created IN/OUT");
getForm().addCommand(getCloseCommand());
getForm().addCommand(getGetWCommand());
getForm().removeCommand(getConCommand());
} catch(IOException e) {
System.out.println(e.toString());
}


// write post-action user code here
} else if (command == exitCommand) {
// write pre-action user code here
try {
connection.close();
getForm().removeCommand(getCloseCommand());
getForm().removeCommand(getGetWCommand());
getForm().addCommand(getConCommand());
} catch(IOException e) {
System.out.println(e.toString());
}
exitMIDlet();
// write post-action user code here
} else if (command == getWCommand) {
// write pre-action user code here
switchDisplayable(null, getWaitScreen());
// write post-action user code here
}
} else if (displayable == waitScreen) {
if (command == WaitScreen.FAILURE_COMMAND) {
// write pre-action user code here
alertStr += " Failure";
switchDisplayable(getAlert(), getForm());
// write post-action user code here
} else if (command == WaitScreen.SUCCESS_COMMAND) {
// write pre-action user code here
alertStr += " Success";
switchDisplayable(getAlert(), getForm());
// write post-action user code here
}
}
// write post-action user code here
}
..
....
..
public SimpleCancellableTask getTask() {
if (task == null) {
// write pre-init user code here
task = new SimpleCancellableTask();
task.setExecutable(new org.netbeans.microedition.util.Executable() {
public void execute() throws Exception {
// write task-execution user code here


// create a server connection
int nbrBytes = 0;
int tmp = 0;
byte CR = (byte) 0x0D;
byte[] data = new byte[80];
// prepare to send/receive data
byte buffer[] = new byte[100];
String msg = "s\n";

// send data to the client
System.out.println("write to client");
os.write(msg.getBytes());
// read data from client
System.out.println("read from client");
nbrBytes = is.read(buffer);
while(buffer[nbrBytes - 1] != CR) {
System.out.println("No CR:" + new Byte(buffer[nbrBytes - 1]).toString());
tmp = is.read(data);
for(int i = 0; i < tmp; ++i) {
buffer[nbrBytes + i] = data[i];
}
nbrBytes += tmp;
}
String received = new String(buffer, 0, nbrBytes);
System.out.println(nbrBytes + "nbr of bytes recived.");
System.out.println("received: " + received);

}
});
// write post-init user code here
}
return task;
}

public WaitScreen getWaitScreen() {
if (waitScreen == null) {
// write pre-init user code here
waitScreen = new WaitScreen(getDisplay());
waitScreen.setTitle("waitScreen");
waitScreen.setCommandListener(this);
waitScreen.setTask(getTask());
// write post-init user code here
}
return waitScreen;
}
...
...
..
}
Last edited by mikrodidakt1 : 2008-12-08 at 11:35.
Reply With Quote

#4 Old Re: Connect as master with N82? - 2009-04-25, 13:11

Join Date: Apr 2009
Posts: 2
Rombosia
Offline
Registered User
I'm also desperately in need of a solution to this problem. I can't communicate to my Bt device without explicitly specifying master=true!!! Any Nokia Development support guys to the rescue?
Reply With Quote

#5 Old Re: Connect as master with N82? - 2009-04-28, 10:02

Join Date: Mar 2008
Posts: 577
mahbub_s60's Avatar
mahbub_s60
Offline
Forum Nokia Expert
Hi,
I am not Java expert but still I can suggest you that you take a working example from Forum Nokia wiki and try that.


-Mahbub
Reply With Quote

#6 Old 2009-05-01, 12:09

Join Date: Mar 2003
Posts: 2,617
traud
Offline
Super Contributor
Rombosia, I recommend to let us continue with your original post …
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
N82 Problem of synchronization with PC Suite Telemann General Discussion 1 2008-08-06 14:48
N82 can not connect windows hyperterminal wdynasty General Discussion 0 2008-06-06 06:19
E70-1 BB connect BES with Lotus Notes christophay PC Suite API and PC Connectivity SDK 0 2007-06-12 11:12
Connect Nokia 7650 Emulator to Internet via modem/RAS on Win2000/WinXP Pro Youth_Jack Symbian Networking & Messaging 5 2006-02-05 18:48
Master Slave application anshulkothari General Symbian C++ 2 2004-08-17 04:54

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia