Bluetooth - MS Stack Windows 7

Topics: Bluetooth - Microsoft
Aug 2, 2012 at 9:04 PM
Edited Aug 6, 2012 at 3:25 PM

I am attempting to connect to a device that requires a serial connection (SPP) from a Windows 7 64-bit laptop using MS Bluetooth stack (2.1). I can find the device using BluetoothDeviceInfo and the serial port gets created. Then, I implemented a thread sleep for 10 seconds. However, the port cannot be opened. An exception is thrown - The semaphore timeout period has expired. Am I missing something or do I need to create the port then reboot the laptop to access it? This same code works fine in Windows XP. Any advice or help would be greatly appreciated.

Code snippet:

BluetoothClient btC = new BluetoothClient();
BluetoothDeviceInfo[] btInfoArr = btC.DiscoverDevices();
BluetoothDeviceInfo btDevInfo = null;
string devName = string.Empty;
string portName = string.Empty;
int btbaud = 115200;

foreach (BluetoothDeviceInfo btItem in btInfoArr)
{
      devName = btItem.DeviceName.ToLower().Trim();
      //search for the device by its name
       if (devName.Contains("blah"))
      {    
          btDevInfo = btItem;
          break;
      }
}

btc.Dispose();

btDevInfo.SetServiceState(BluetoothService.SerialPort, true, true);

Thread.Sleep(10000);

//get port name

//code to access-open serial port here - this throws the semaphore exception
SerialPort sp = new SerialPort(portName, btbaud);           

sp.Open();

sp.Close();
Developer
Aug 7, 2012 at 11:44 AM

Sorry I try to avoid virtual serial ports myself, and haven't seen that problem.  I use BluetoothClient and NetworkStream for all my data transfer.

http://32feet.codeplex.com/documentation

http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections&referringTitle=Documentation

May 28, 2014 at 6:14 PM
How you get the port name? Quering Win32_SerialPort in Get-WmiObject is problematic in windows 7 for some reason.