Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a virtual COM port for Bluetooth in C# .NET

I have an app. that receives some transmissions from a device via Bluetooth. This app is meant to be hosted on Win. Server 2008 or Win. 7, developed on C#.NET 4.5. The integration is made by using the device SDK, so I just need to know which is the COM port to receive data from. That's not a problem when I create the virtual COM port manually from the Bluetooth settings.

Virtual COM port .

This integration should be deployed in lots of devices, and asking users to create a virtual COM port manually is not an option... Is there a way of creating it from .NET code? I would need to create the virtual COM port (listening for Bluetooth transmissions) and know its port name.

EDIT: I'm open to new ways of doing that (C++, power shell scripts, CMD, bat file... always inside Windows technologies

I have tried already some COM integration (like this one), but it seems to be limited to .NetCF (I don't have coredll.dll since it is running on Windows Server or Windows 7, among other missing stuff... already tried to 'force' that DLL to load with no luck). Something similar, but working, would be the ideal solution

like image 783
nnimis Avatar asked Jun 15 '17 14:06

nnimis


People also ask

How do I create a Bluetooth COM port?

Note If using Windows 8/10, navigate: Right-click Start > Control Panel > In the search box, enter "Bluetooth" then select Change Bluetooth settings. From the COM Ports tab, click Add. Ensure that "Incoming (device initiates the connection)" is selected then click OK. Click OK.

How do I create a virtual serial port?

Download Virtual Serial Port Driver on your Windows machine. Install the application on your system and launch it. Choose “Pair” in the application's main window. Click the “Add a new pair” button to create a pair of virtual serial ports.

How do I install a virtual COM port?

Download and install VSPD on your Windows 10 computer. Launch the application and navigate to the “Manage Ports” tab. Here you can select ports from the drop-down menu or manually enter custom port names. After selecting the port names, simply click the “Add Pair” button and you are done!

What is a COM port for Bluetooth?

It is basically a telecommunication port that allows wireless connection and exchange of data over a short-range wireless connection. Moreover, it is possible in mobiles, computers and other digital devices too. Besides, it uses short-range radio waves for sharing the data.


1 Answers

I found this interesting tidbit that relates to your problem

On Win32, to create a Bluetooth virtual serial port one can use BluetoothDeviceInfo.SetServiceState, passing in service class SerialPort. Unfortunately the name of the COM port created is not returned — that’s because the native API does not tell! One way to find the name of the port created is to call the System.IO.Ports.SerialPort.GetPortNames method before and after the SetServiceState call and see which name is new.

Source: https://github.com/inthehand/32feet/wiki/Bluetooth-Serial-Ports

In any case... In the registry, All bluetooth devices are listed under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\BTHENUM.

You can enumerate the entries under that key to locate your device PNP ID. A key name from my registry, as an example: {00001103-0000-1000-8000-00805f9b34fb}_VID&0001001d_PID&1200

The serial port for your device is stored below that, in: .\{unique subkey name}\Device Parameters\SerialPort

Where {unique subkey name} is an internal MS ID. It's the only subkey at that level.

One way to get the PnPID is to right-click->Property on the device in Device Manager. Go to the "Details" tab, then select "Compatible IDs" in the combo box.

like image 124
Michaël Roy Avatar answered Oct 24 '22 17:10

Michaël Roy