10-06-2009 01:44 PM
Hello,
I have a device that I am trying to communicate with from my BlackBerry using Bluetooth.
I am able to connect to it using the method Connector.open(info, Connector.READ_WRITE );
I can also read and write using the input and output streams.
However I need to be able to detect when the port is disconnected from the remote device. I was thinking of using BluetoothSerialPortListener. To use this I try to connect to the device using this method:
listener = new MyBluetoothListener(); _serialPort = new BluetoothSerialPort(info[i].toString(), BluetoothSerialPort.BAUD_9600, BluetoothSerialPort.DATA_FORMAT_DATA_BITS_8 | BluetoothSerialPort.DATA_FORMAT_PARITY_NONE | BluetoothSerialPort.DATA_FORMAT_STOP_BITS_1, BluetoothSerialPort.FLOW_CONTROL_NONE, 2048, 2048, listener);
This does not appear to be working. The above call works fine and I don't get any exceptions. However, I also don't get the deviceConnected() callback in my listener.
In the console output I see the following and nothing else after this:
BT: allocSerialPort 81159234
BT: sdpAddRecord
BT: allocSdpAttributeData
Is there something I'm missing here?
To summarize, I have two questions:
1. Why isn't the connection using BluetoothSerialPort working?
2. Assuming I can't get that to work is there a way I can detect a disconnect when using the Connector.open() method?
Thanks in advance for your help.
Solved! Go to Solution.
10-06-2009 03:12 PM
I am connecting to a Bluetooth device using very similar code to yours, with two exceptions:
1) You use info[i].toString(), as the first parameter, I just use the equivalent of info[i]
2) I'm using BluetoothSerialPort.BAUD_115200,
The listener receives disconnections as I would expect.
The messages I see when debugging this re as follows:
BT: allocSerialPort 814ee52c
BT: BTEVENT_LINK_CONNECT_CNF
net.rim.bluetooth: DC00
BT: BTEVENT_LINK_POLICY_CHNG received
net.rim.bluetooth: EC00
This test was run on an 8900 running 4.6.1.199.
Hope this helps.
10-06-2009 09:27 PM
Thank you for the response. That fixed my problem.
I removed the .toString() and used just info[i] and everything works fine now.
I can connect and my listener is getting the callbacks.
Thanks.
11-05-2009 07:02 AM
11-05-2009 03:17 PM - last edited on 11-05-2009 03:21 PM
Just once please! Response posted here: