As promised here are the resources from yesterday’s session on Bluetooth and NFC. I’ve begun uploading the slides and code to this SkyDrive folder:-
I have a few finishing touches to put on the sharing library for NFC – it will be up on NuGet and CodePlex shortly.
Version 8.1 of 32feet.NET for Windows Phone is now available via NuGet. This package adds some helper functionality for Bluetooth development. In particular this version includes the RfCommServiceId (designed to match the Windows 8.1 API) to provide information about various standard RfComm profiles. You can use this when connecting a StreamSocket or to filter devices in the BluetoothDevicePicker.
Speaking of which the BluetoothDevicePicker has been updated to more closely follow the appearance of the dialog displayed when you use the built in Bluetooth photo sharing feature. Currently the library is built with localized resources in mind but has only English text. If you are interested in providing localized text in your own language please contact me.
The CodePlex project contains the source and the Serial sample app. I’m working on some additional sample apps which will be added soon.
Unless you’ve been stuck under a rock (in which case what are you doing reading this?) you’ll know that Microsoft announced a preview release of Windows 8.1 at Build yesterday. While I haven’t got a development machine up and running yet (No easy upgrade if your device is UK English) I’ve been looking at the updated documentation at MSDN. Of the many new APIs described there are a couple of new namespaces which will be interesting to those working with Bluetooth devices:-
Windows.Devices.Bluetooth.GenericAttributeProfile – Contains functionality to work with Bluetooth LE devices. This will make it possible to interact with devices such as FitBit and other low energy sensors and devices from within apps – which means support on ARM devices.
Windows.Devices.Bluetooth.Rfcomm – Support for normal serial sockets Bluetooth. While completely different from the Windows Phone 8 API it provides the same functionality and more. Ability to enumerate and get notified of device arrival and departure and access to SDP attributes. There are identifiers for a number of standard profiles – Generic File Transfer, ObexFileTransfer, ObexObjectPush, PhoneBookAccess (client and server), SerialPort (SPP).
A new Chat sample is available for 8.1 here – http://code.msdn.microsoft.com/windowsapps/Bluetooth-Rfcomm-Chat-afcee559
With the recent announcement of Windows Embedded Handheld 8 it seems fitting to discuss something related to industrial and line-of-business applications which you can develop now on the Windows Phone platform.
I’ve released the first drop of 32feet.NET for Windows Phone 8 to our CodePlex site and NuGet. Because the programming model on Windows Phone (based on Windows Runtime StreamSockets) this is a separate package and doesn’t follow the programming model of the main 32feet.NET release. Windows Phone 8 supports Bluetooth programming out-of-the-box it is not straight-forward as it is build around the Windows Runtime Peer networking APIs but is different to the Windows 8 implementation. The aim of the 32feet library for Windows Phone is to simplify common tasks. This initial release adds the following features:-
- Strongly typed extension methods for ConnectAsync which accept service Guids or numerical port numbers
- BluetoothDevicePicker which offers an easy way for a user to select a device. Equivalent to the SelectBluetoothDeviceDialog in the core 32feet library.
- Common Bluetooth service Guids
- Bluetooth Barcode scanner sample. This sample app connects to a Motorola CS3070 scanner and allows input of Barcodes to the device screen. It should also work with other Bluetooth serial based scanners.
This is just a first release and we will be continuing to develop the library as well as add further localisation and samples. For example to demonstrate connecting to applications running on the desktop (Sorry not Windows Store apps currently). Your feedback is valuable so please visit the CodePlex project site to provide feedback.
There is a NuGet package available for the Windows Phone flavour of 32feet.NET to allow you to easily add it to your projects:-
The Bluetooth API on Windows Phone 8 is based around some customisations to the Proximity APIs which are part of the Windows API introduced with Windows 8. When you “discover” devices you can retrieve a collection of device identifiers for paired devices. The first time you perform a task you will want to use this mechanism to select the appropriate device. However you may want your app to remember a specific device and try to connect again on subsequent attempts. In the old .NET world with 32feet.NET we have a constructor for BluetoothAddress which allows you to supply the address in a variety of string or numeric forms. In the Windows API the Windows.Networking.HostName type is used to represent a host name whether it is for a Bluetooth device or an IP address. Normally the read-only Type property will indicate the type of the host.
In order to store a Bluetooth address for later use you should save the RawName property which for Bluetooth devices is in the form “(11:22:33:44:55:66)”. The dotted hex notation is fairly common but notice the address is wrapped in brackets. Now to restore this address in a HostName instance you can later use to open a socket you can use:-
HostName storedHostName = new HostName(storedRawName);
You’ll notice that this sets the host name and correctly sets the Type property to Bluetooth.
Today has been spent catching up on my To-Do list, though it still doesn’t look that way! I have however been able to make some progress with 32feet.
Alongside the class library documentation for the project there is a User Guide which provides an overview of the functionality and some example code snippets. Alan McFarlane created the documentation and it is an excellent starting point and Alan has continued to keep it up to date throughout each version of the library (currently up to 3.0 Beta). Up until now this has been distributed as a Word document with the install package but I have for some time been trying to integrate it into the Help file for the library. The help file is created with Sandcastle Help File Builder which supports adding in static content, but you have to provide the pages in Microsoft’s proprietary MAML format and I was never able to get the layout and appearance to look right and manually copying and pasting bits of documents was tedious. As a compromise I instead investigated the Documentation support on CodePlex. Each project hub is a Wiki and the mark-up required makes it very simple to put together the right structure and hyperlink between topics. Because all of the content is now part of the project Wiki it is also searchable – Type “Broadcom” into the search box and you can get straight to the relevant topics.
You can browse the User Guide at http://32feet.codeplex.com/documentation
I also recommend you follow Alan’s 32feet.NET blog where he has posted some of the excellent work he has been doing to add support for further Bluetooth stacks to the project.