Answered by:
Serial connection via Bluetooth

Question
-
Hello,
I would like to know if it is possible to use the bluetooth of the phone as a serial port, in order to establish a serial communication with a bluetooth device.
Thanks.
Monday, November 26, 2012 4:41 PM
Answers
-
It is possible to connect to BT devices that use SPP. These are connected to and the serial data stream is passed over effectively RFCOM via a Socket Stream. The Serial stream will just be continues data on the socket
Connect as you would normally to a paired device
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var pairedDevices = await PeerFinder.FindAllPeersAsync();Create a socket stream
StreamSocket readSocket = new StreamSocket();
readSocket.ConnectAsync((PeerInformation)pairedDevices[0], "1"); //Note "1" this is the port number to use for the socket
DataReader = new DataReader(this._readSocket.InputStream);Then read the data on a DataReader with
LoadAsync
ReadBytes- Marked as answer by aZubi Tuesday, February 5, 2013 2:59 PM
Friday, February 1, 2013 5:53 PM
All replies
-
I've looked at the supported profiles for the OS and it doesn't list SPP. However, the Nokia 920 and 820 indicate support. This may be a situation where Nokia is just documenting what is possible with the hardware when it may not be possible (yet) with software. I'm having the same question with BLE. Hopefully, the documentation is wrong and SPP is available in some way today.Monday, November 26, 2012 5:41 PM
-
All bluetooth communication is handled via a TCP StreamSocket.
No other protocol is supported in the Windows Phone SDK.
- Edited by Dave Hunt (ProfEclipse)Banned Monday, November 26, 2012 6:32 PM
Monday, November 26, 2012 6:32 PM -
Hello ProfEclipse,
Thank you for your answer. I was just wathcing this session from Build 2012, and I was wondering if it would be possible to talk to a OBD bluetooth device like that: http://blog.uobd2.com/obd2-scanners-communication-ways-usb-rs232-bluetooth-and-wifi/
Is this possible?
Thanks
Monday, November 26, 2012 6:46 PM -
Bluetooth might not be possible. However, there are some inexpensive Wifi OBDII devices that use the same chip found in most of the Bluetooth based units. Wifi might work.Tuesday, November 27, 2012 9:29 PM
-
After reading this:
Should I consider that it is actually possible?
- Edited by aZubi Tuesday, December 4, 2012 9:21 PM
Tuesday, December 4, 2012 9:21 PM -
After reading this:
Should I consider that it is actually possible?
Nice update, but it doesn't say you can support an existing bluetooth product that expects SPP. Still sort of vague. Hopefully they can get the code and commentary published.
Are you building it for yourself or as a generic application to support unknown vendor hardware?
The Wifi devices look pretty easy to implement.
Tuesday, December 4, 2012 10:03 PM -
It is possible to connect to BT devices that use SPP. These are connected to and the serial data stream is passed over effectively RFCOM via a Socket Stream. The Serial stream will just be continues data on the socket
Connect as you would normally to a paired device
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var pairedDevices = await PeerFinder.FindAllPeersAsync();Create a socket stream
StreamSocket readSocket = new StreamSocket();
readSocket.ConnectAsync((PeerInformation)pairedDevices[0], "1"); //Note "1" this is the port number to use for the socket
DataReader = new DataReader(this._readSocket.InputStream);Then read the data on a DataReader with
LoadAsync
ReadBytes- Marked as answer by aZubi Tuesday, February 5, 2013 2:59 PM
Friday, February 1, 2013 5:53 PM -
Thank you Craig!
I have found the sample from Build:
http://code.msdn.microsoft.com/wpapps/Windows-Phone-8-Networking-835239c1#content
Tuesday, February 5, 2013 4:08 PM