Hello,
I have problems with virtual Com Ports on a Windows 10 64 bit System.
When pairing with different Bluetooth modules, Windows 10 assigns virtual Com Ports with a number greater than 9 (Windows 8.1 32 bit assigns Com Ports < 10).
Now on Windows 10 I could not manage to open these virtual Com Ports. I get an exception when I try to open the ports > COM9.
Anybody knows how to solve?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace Serial_Port_Test
{
public partial class Form1 : Form
{
string[] ComPorts = null;
SerialPort mySerialPort;
public Form1()
{
InitializeComponent();
ComPorts = SerialPort.GetPortNames();
mySerialPort = new SerialPort(ComPorts[2]);
try
{
mySerialPort.Open();
MessageBox.Show("ComPort: " + ComPorts[2] + " could be opened");
}
catch (Exception ex)
{
MessageBox.Show("ComPort: " + ComPorts[2] + " could not be opened \r\n"
+ "Error Message: " + ex.Message);
}
}
}
}
The only references I can find to your problem all refer to solving it using P/Invoke to access COM ports 10 and up. I have not found any good examples of that. I did find source code that excludes the \.\COMXX notation in the SerialPort() source as some sort of security issue.
In Modern/Universal apps, you can use the code that andre.m showed. In ‘classic’ desktop apps, you’ll probably have to resort to accessing the serial port via P/Invoke calls to the WIN32 api. That will work no matter what the COM port name is. If all you need is some basic setup (baud, format, handhshake) and blocking read/blocking write, then it shouldn’t be too hard as you’ll only need to map a few methods and structures. I don’t have any examples handy though.
@ mcalsyn -
Thanks for the time you spent on this issue.
I only wanted a short test if the GHI Bluetooth Module and the Seeed BLE dual Bee (HM-13) module work on Windows 10 as well as on 8.1. It was not so short as I thought… I think that I go away from the Forms App and use a Universal or Store App with the Devices.Bluetooth.Rfcomm Class.