Monitoring Bluetooth Connections

Topics: Bluetooth - Microsoft
Jun 7, 2013 at 4:25 PM
Please can somebody help me to understand if and how I can monitor Bluetooth connections within my application.

I have stopped using BluetoothClient, as although this appeared to initiate a Bluetooth connection, I couldn't get the Software Development Kits of either of my Bluetooth devices to work in conjunction with BluetoothClient. So, instead, I am now using:
  1. InTheHand.Net.Bluetooth.BluetoothSecurity.PairRequest(peer.DeviceAddress, pin) to "bond" with the Bluetooth device
  2. peer.SetServiceState(BTGuid, True, True) to update the registry
  3. On one dvice, which requires a serial port, I then use InTheHand.Net.Ports.BluetoothSerialPort.CreateClient(BTEP)
I then use the SDKs of the 2 devices to perform the next steps (these devices are a scanner, and a printer)

All of the above is working fine, but using this method I cannot figure out how to tell whether a Bluetooth connection is still up and running, or whether it has dropped out for some reason (device out of range, device turned off, etc). I think I can achieve this monitoring if I use a BluetoothClient or a BluetoothDeviceInfo, but if I use these methods then the SDKs of my two devices cannot connect

Thanks in advance
Jun 11, 2013 at 4:38 PM
Hi All,
I'm guessing that no replies probably means I'm asking for something unusual!! Because of this, I've gone back to look at the code and am thinking that at least for the printer I might be better off dropping the printer's simplistic SDK and simply streaming data directly to the printer. This should allow me to use the 32feet tools to implement, manage and monitor the BluetoothClient connection. So, I have implemented new code to make a BluetoothClient connection, but have discovered through testing that if I simply turn the printer off (which should force the connection to drop out) the BluetoothClient.Connected property is still set to TRUE.

Can anybody tell me how to check/monitor a BluetoothClient to see whether the Bluetooth connection still exists or not?

Jun 14, 2013 at 12:46 PM
I have been able to workaround this by attempting to write data to the stream, and trapping the exception that occurs if the device is no longer connected. It's not quite as easy or elegant as I had expected (I thought I would be able to use the BluetoothClient.Connected property) but it works. Hope this is useful to somebody!