Getting invalid serial port names from bluetoothdevice (C #)

To get all available Serialports from the system, I use the following command.

SerialPort.GetPortNames 

It works fine for the serial port of the motherboard, but with the Bluetooth device I get the wrong port names.

For example: instead of COM7, I sometimes get COM70 or COM7ΓΆ. Its always 1 letter.

any assumptions?

PS: I use the latest Visual Studio Express in Windows 7 PPS: dirty hacking the last letter did not work, because I don’t know which one is a bluetooth serial port (with various bluetooth plugs or devices that change the number of commots), and after of how I tried various sticks, I reached COM10, ergo COM100 or COM10f

EDIT: The code I'm using right now. reading registers, but still the same problem.

 RegistryKey myRegistry = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm"); foreach (string valuename in myRegistry.GetValueNames()) { if (myRegistry.GetValue(valuename) is String) { if (valuename.Contains("BthModem")) { richTextBox1.AppendText(">" + myRegistry.GetValue(valuename) + "<" + Environment.NewLine); } } } 

Usually the second or third query works with a result like

COM11α―‹ <COM10S <COM11 <COM10 <COM11 <COM10 <

how can it be?

+6
c # bluetooth serial-port
source share
3 answers

This is reported as an error with null terminated strings:

Can you manually start the registry?

 HKLM\Hardware\DeviceMap\SerialComm 
+2
source share

You can use WMI to query the system for serial ports, including those added by Bluetooth devices and USB-To-Serial devices. Perhaps this way you will not run into this problem. See CodeProject .

0
source share

I have the same problem. SerialPort.GetPortNames mainly uses the registry anyway - both of these methods do not seem to work with Bluetooth.

The workaround I'm currently using is to loop through the first X com ports and see if they exist, which is hardly elegant. MS: FAIL.

0
source share

All Articles