I have a bespoke bluetooth device that I can pair with and connect to using windows 10 and it creates 2 com ports - one is listed as incoming and one is listed at outgoing.
When I connect using the 32Feet C# bluetooth libraries I am able to discover and pair the device and the enable the SPP profile but, alas, I only get one COM port and it is listed as "outgoing".
I am required to interface to the device using someone else's code and it needs to be supplied a com port number. Unfortunately it wants to connect to the "incoming" port.
Hence my question is what magic do I need to create this incoming com port? I have looked at the 32Feet code and the underlying API call of BluetoothSetServiceState(...) and it doesn't seem to have any parameters to control how the ports are created. Is there another profile for this feature??
private const UInt16 BLUETOOTH_MAX_SERVICE_NAME_SIZE = 256;
private const UInt16 BLUETOOTH_DEVICE_NAME_SIZE = 256;
private static Guid SerialPortServiceClass_UUID = new Guid("{00001101-0000-1000-8000-00805F9B34FB}");
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct BLUETOOTH_LOCAL_SERVICE_INFO
{
public Boolean Enabled;
public Int64 btAddr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = BLUETOOTH_MAX_SERVICE_NAME_SIZE)]
public String szName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = BLUETOOTH_DEVICE_NAME_SIZE)]
public String szDeviceString;
};
[DllImport("BluetoothAPIs.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
private static extern UInt32 BluetoothSetLocalServiceInfo(IntPtr hRadioIn, ref Guid pClassGuid, UInt32 ulInstance, ref BLUETOOTH_LOCAL_SERVICE_INFO pServiceInfoIn);
private void CreateComPort(Boolean Create)
{
BLUETOOTH_LOCAL_SERVICE_INFO s = new BLUETOOTH_LOCAL_SERVICE_INFO();
s.btAddr = 0;
s.Enabled = Create;
s.szName = "MyComPort";
s.szDeviceString = "COM10";
UInt32 Res = BluetoothSetLocalServiceInfo(IntPtr.Zero,
ref SerialPortServiceClass_UUID, 1, ref s);
MessageBox.Show(Res.ToString());
}