Return to site

Windows 10 Bluetooth Serial Port

broken image


Step-by-step guide to add virtual COM port Windows 10: Following these steps with Virtual Serial Port Driver (VSPD) will enable you to easily create virtual serial ports on a Windows 10 machine: Download and install VSPD on your Windows 10 computer. Launch the application and navigate to the 'Manage Ports' tab. Bluetooth Serial Port For Windows 10 free download - Windows Std Serial Comm Lib for C/C, Bluetooth Serial Terminal for Windows 10, Hyper Serial Port, and many more programs. Checks if a device has a serial port service running and if it is found it passes the channel id to use for the RFCOMM connection. Callback (channel) - called when finished looking for a serial port on the device. ErrorCallback - called the search finished but no serial port channel was found on the device. Connects to a remote bluetooth device.

Windows 10 Bluetooth Serial Port

Universal Windows App that connects to an embedded Bluetooth device over the Bluetooth Serial Profile using a generic Bluetooth USB dongle.

  • 10,809 views
  • 8 comments
  • 34 respects

Components and supplies

Raspberry Pi 2 Model B
×1
Generic Bluetooth USB Dongle
×1
Arduino UNO
×1
SparkFun Bluetooth Modem - BlueSMiRF Silver
×1

Apps and online services

Microsoft Windows 10 IoT Core
Microsoft Visual Studio 2015

About this project

Further

This project is discussed in detail in embedded101.com:

About

This project is a Universal Windows App that connects an IoT-Core device such as a Raspberry PI 2 to an embedded Bluetooth device over the Bluetooth Serial Profile using a genetic Bluetooth USB dongle.

Bluetooth Serial Port Windows 10 Driver

Background

.Bluetooth supports peer to peer networking over a short range. Unlike a Wi-Fi network, Bluetooth connectivity is one to one. Two devices can connect and interact. For example, two devices may connect in a symmetric manner using the serial profile and pas raw data between them. Generally though, Bluetooth connectivity is asymmetric with one end generating a specific data format to be consumed at the other end. For example a mobile phone can implement the A2DP (Advanced Audio Distribution Profile) Profile and stream audio to a head set that implements the HSP (Headset) Profile OBEX (Object Exchange) is a symmetric connection between two devices as they exchange data between them.

The Microsoft IOT-Core Bluetooth Sample project uses the GATT (Generic Attribute Profile Profile). This provides profile discovery and description services for the Bluetooth Low Energy protocol. With this protocol simple low power devices can be connected at one end generating data to be consumed by a complex processor.

This is a far simpler project than the Microsoft sample. It is only concerned with the more generic SPP (Serial Port Profile) which is based upon the RFCOMM profile. It was developed with a very old USB Bluetooth dongle and so should work with any Bluetooth dongle.

The IoT App

This app is a simple Bluetooth Serial Universal Windows (Windows 10) test app. It starts by enumerating (as a list) all devices Bluetooth paired to the device where the app is running. One is selected by double clicking which initiates connection. Text to send is entered in a Textbox and sent when a button is pressed. The app automatically receives any text sent to it ( and displays it). Hence when the endpoint (as above) simply echoes the text its received, the sent text should reappear in the reception box on the UW app.


The Endpoint

For testing an Arduino Uno with a Bluetooth adapter is used. It has a simple shield that just echoes back any characters its receives over the Bluetooth connection:

The Shield Setup:

The Shield Loop:

Pairing

Bluetooth is a peer to peer scenario. Before they can connect over Bluetooth they must be paired. This is not done within the app. Pairing with a passkey can be problematic between embedded devices as they are often headless and may not support popups (as IoT-Core does not). There is a IoT-Core web portal for doing this as well as a command line utility on the device that can be run over an SSH shell. The most recent version of the OS web portal supports passkey pairing which was missing around the time of Windows 10 RTM. 'Win 10 IoT-Core: Bluetooth Universal Windows Serial App' discusses pairing in this context in detail.

Starting the project

The app project is created using in Visual Studio 2015 using the Universal Windows app template:

New Project-->Visual C#->Windows->Blank App (Universal Windows)

Creating the App UI

The UI is implemented in XAML

Create the UI as per the layout as above (or similar):

The UI is quite straight forward and is created as follows:

  • All text elements are TextBlocks except the SendText which is a TextBox
  • SendText accepts CarriageReturn (ie is Multiline)
  • The Recvd text has WrapText enabled (ie is Multiline)
  • UI elements are organised in rows using a StackPanel set to horizontal orientation
  • These StackPanels are then stacked with a StackPanel set to vertical orientation, along with the ListBox.

You may prefer to layout the UI using Relative StackPanels or use Grid rows and columns etc.

The ConnectDevices is a ListBox with a Binding Source set to PairedDevices(see later) and an ItemTemplate consisting of a TextBlock bound to the Name property of PairedDevices (see later).

App Configuration

  • The app make no use of IOT-Core features so will not require any Extension References.
  • The app will need some specific capabilities for Bluetooth and Serial added to Package.appxmanifest.
  • Unfortunately, the UI you get for this if you double click on that file in Solution Explorer doesn't support adding these capabilities and so you need to add them manually by right clicking on the file in Solution Explorer and select Open With->XML Editor.

Modify the capabilities section (at the bottom) to:

The internetClient capability will already be there. Its not needed for this app so you may wish to remove it. I leave it in.

PairedDevice Information

At the app start the paired devices are enumerated using:

DeviceInformationCollection DeviceInfoCollection

= await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

This collection is then turned into an ObservableCollection that it can be used in the ListBox:

_pairedDevices = new ObservableCollection();

The DeviceInfoCollection is iterated through creating a PairedDeviceInfo object for each item which is then added to the _pairedDevices collection.

PairedDeviceInfo is a class with properties:

Name

Id

DeviceInfo

The class has an appropriate constructor.

DeviceInformation is Windows.Devices.Enumeration.DeviceInformation Mac audio torrent.

In the listbox of paired devices, the Name field is (bound) displayed.

When a device is selected (double clicked) the endpoint's DeviceInformation is actually part of the selected menu item and so is used for establishing the connection.

Connection

The DeviceInformation is used to get the RFCOMM service. The connection is then established as a StreamSocket using the Endpoint HostName (actually its Bluetooth Mac Address) and the ServiceName string.

If all is well then we have a connection . the socket will be meaningful (not null).

Of course this is error trapped (try-catch)

Bluetooth Serial Port Terminal For Windows 10

Send text and Receive text make use of the socket's InputStream and OutputStream properties.

Receive Text

Receiving text should be started first as it runs as a separate thread. It runs an async wait to get serial input, handles the input then runs another async serial receive . all in a loop. This loops continuous until a cancellation is generated.

Send Text

Whilst the received text is performed asynchronously as the arrival of text is nondeterministic from the app's perspective, sent text is actioned from the app's UI and so is essentially synchronous (although a await is used to free up the UI).

Button States

The command buttons are enabled and disabled depending upon the state of the app. For example Send and Start Recv buttons are disabled when the app isn't connected but become enabled when the app is connected, etc.

Enjoy! :)

Code

iotbluetoothserial on Github
Also on Codeplex (mirror)https://iotgenbluetoothserialuwa.codeplex.com/

Author

David Jones
  • 3 projects
  • 33 followers

Published on

November 6, 2015
Write a comment

Members who respect this project

and 26 others

Virtual
See similar projects
you might like

Table of contents

Write a comment

I was thinking about a comment on a Gist I wrote some time ago and thought I'd written a blog post on the topic, but when I couldn't find any sign of it I decided to start from scratch as I'd have probably needed to update it anyway.
The Bluetooth stack in Windows has supported virtual COM ports since the beginning (Windows XP SP2 if you can remember that far back!). It's important to understand the difference between these and any Serial Port Bluetooth device. The Virtual COM port functionality exists purely for interop with older software – you can make a Bluetooth device appear to the system as a wired Serial device and open a COM port and talk to the device as if it was plugged into your PC.
If you're writing modern software which talks to devices then you would use a Bluetooth API – either 32feet.NET or the platform specific Bluetooth API directly. If not you can create a virtual COM port. Throughout Windows 10's lifetime the Bluetooth options have been slowly moving to the modern Settings experience but the old Control Panel still exists and is used for some additional functionality – Virtual Serial ports are still in there.
The port can be either incoming – you have a listening service which other devices can connect to; or outgoing where you connect to a specific remote device. From Settings > Devices select 'More Bluetooth options' from the righthand menu.

From the resulting 'classic' control panel applet select the 'COM ports' tab to see configured ports or to set one up.

When I reworked the 32feet.NET library I decided not to include the COM port functionality as it's only relevant to Windows and is for legacy code only. However I put together the required code to enumerate all the Bluetooth virtual COM ports on the system in a Gist which you can find here:-

Win 10 Bluetooth Com Port

I've just updated it as I noticed an issue with the null termination of the port names so it is now correctly trimmed. The class is very simple to use – the following will write out all the configured ports to the debug console:-

This will match the contents of the Control Panel shown above.





broken image