• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Talking to a Bluetooth Device, Getting BRSF

KertDawg

Lurker
Hello,

I am working on a simple program to talk to an ELM 327 Bluetooth device over a Serial Port Protocol. I have verified that my debug device (Samsung Galaxy Note II VZW) can talk to the device using other programs that seem to work. I have no experience with Bluetooth and Android, so please forgive any obvious mistakes.

I hesitate to post code here, mainly because I have things spread out into various classes. If needed, I can try to reproduce my problem with a simpler, single class. However, if anyone knows any tips that can save me that trouble, I'd appreciate it.

The problem at hand is that ANYTHING I send to the device results in a response of "AT+BRSF=24\r". On a second attempt to communicate, my InputStream.read(Buffer) times out. For instance, I send the command "010C\r" (which requests a specific response from the device), and I get the BRSF response above. A second attempt results in a timeout of the subsequent read(), as though the device has nothing further to say.

The code I use to communicate is this:
[HIGH]
String Command = "010C\r";
m_OutputStream.write(Command.getBytes());
Thread.sleep(1000);
byte[] Buffer = new byte[m_InputStream.available()];
m_InputStream.read(Buffer);
[/HIGH]Google has not helped. If source code would help, I'll gladly reduce my code to the bare essentials and post it. However, I hope that this is an easy issue to resolve with the above information.

Thank you in advance for any replies.

- Kert
 
Hi,

I have exactly the same problem - did you manage to resolve it? I found that such behaviour is the same as for Bluetooth hands-free (HF) devices, but all tips and specification doesn't work for me. You can see those documents here:
Cannot input links so you have to add htt...

kaa.org.ua/qtopia-docs/modememulator-controlandstatus.html

google.pl/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&sqi=2&ved=0CDUQFjAB&url=https%3A%2F%2Fwww.bluetooth.org%2Fdocman%2Fhandlers%2Fdownloaddoc.ashx%3Fdoc_id%3D238193&ei=_6prUsezBciF4ASrxIHYAQ&usg=AFQjCNF-Hf7fAnmQaItg6WPs7crwoLdVFA&sig2=dY2MlvihV445k00PtpePdw&bvm=bv.55123115,d.bGE

Here some output examples:
androidpit.de/de/android/forum/thread/272537/Buetooth-startet-nicht-mehr

code.google.com/p/android/issues/attachmentText?id=16717&aid=167170012000&name=DUN.txt&token=02057a503d45316624cf990fd42b851d

And following above examples I tried sth like:

>AT Z (sending, I get AT+BRSF.. only after sendind AT Z)
AT+BRSF=24 (received)
>+BRSF: 24 (sending)

or

>+BRSF: 99 (sending)

or
>+BRSF: 24 (sending)
OK (sending)

but nothing works, after sending anything I get error "Connection reset by peer" in my application.
But I know that interface works because I'm able to correctly connect via Scan-Master ELM (but only in automatic mode - in manual/command line mode I cannot even connect to the device).

Hope together we will resolve the problem.
 
Ok, I think I resolve the problem. I used recommended in new API way to resolving BT socket:

[HIGH]BluetoothSocket tmp = null;
Method m;
try {
m = dev.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(dev, 1);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}

this.sock = tmp;
[/HIGH]
When I changed for traditional one (like in old APIs):

[HIGH]try {
this.sock = dev.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
e.printStackTrace();
}[/HIGH]

with UUID = 00001101-0000-1000-8000-00805F9B34FB

the socket connects normally and I can get OBD answers.
 
Back
Top Bottom