Author Topic: Which device disconnected  (Read 9888 times)

mcmalburg

  • Guest
Which device disconnected
« on: August 05, 2016, 08:11:00 PM »
My .NET (PC-based) application has an array of Bluetooth devices attached.  I'm trying to handle the situation where one of the devices walks away or is powered down.

The Discovery.OnDeviceLost handler is very slow and unresponsive.  It often misses the fact that I've disconnected:

wclBluetoothDiscovery.OnDeviceLost += new wcl.wclBluetoothDiscoveryDeviceEventHandler(OnBluetoothDeviceLost);

private void OnBluetoothDeviceLost(object sender, wcl.wclBluetoothDiscoveryDeviceEventArgs e)
{
    // use "e.Device.Address" to determine which device was lost
}



The wclsyncClient.OnConnect handler which conveniently provides the device address in the argument.
However, the wclSyncClient.OnDisconnect handler doesn't provide the address of the device that was lost.

syncClients = new wclSyncClient[gageArray.Length];
comboBoxGageName.Items.Clear();

for (int i = 0; i < gageArray.Length; i++)
{
  syncClients = new wclSyncClient();
  syncClients.OnDisconnect += new System.EventHandler(OnBluetoothDisconnect);
  syncClients.OnConnect += new wcl.wclConnectEventHandler(OnBluetoothConnect);

  comboBoxGageName.Items.Add(gageArray.strUserName);
}

private void OnBluetoothDisconnect(object sender, EventArgs e)
{
  // how do I know which device was lost?
  // the EventArgs don't tell me which device was lost !!!
}


Questions:
How should I immediately detect and handle the situation when one of my devices walks away or is powered down?  The "OnDeviceLost" is very slow as is the "InRange".  The OnDisconnect seems to be a bit better (although pretty slow) - however, I cannot determine which of the devices in my array was lost.

Thanks,

   - Mark








Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Which device disconnected
« Reply #1 on: August 05, 2016, 11:56:21 PM »
OnDeviceLost does absolutely nothing with connection/disconnection. It simple checks that device in range. Even it is disconnected. And you must not execute discovering during connection (does not matter server or client). That is by Bluetooth Core specification.

As you may see any event has sender parameter (as any event in .NET). The sender as you may guess if the object that fired the event. So once you know sender you know any other information. In your case the sender is wclSyncClient. It has wclClientBluetoothParams property that has Address property. Very easy.

 

Sitemap 1 2 3 4 5 6 7