Author Topic: Bluetooth adapter not found scenario  (Read 19728 times)

TheodorosGR

  • Guest
Bluetooth adapter not found scenario
« on: August 04, 2008, 12:38:46 PM »
I have the following scenario on my application.
Application is starting.The bluetooth adapter is not pluged(i think this is common from a lot users).Show an exception from Enum_Radios() (wcl demo).The exception says what to do(check your adapter....etc).Then if the user plugs the adaptor he will probably hit the refresh button (GetSelectedRadio()).But there i am getting an exception which i cant handle.
My question is if there is any way after the user plugs the adapter and calling GetSelectedRadio() to display the BT adapter without requiring restarting the application.
A little bit confusing question but i think you got the point.
Regards
Thiodor

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Bluetooth adapter not found scenario
« Reply #1 on: August 04, 2008, 10:24:54 PM »
Good day!

WCL Has no GetSelectedRadio function. What does that function do?

Of course, WCL can detect changes in hardware without restarting application.

TheodorosGR

  • Guest
Re: Bluetooth adapter not found scenario
« Reply #2 on: August 04, 2008, 10:55:28 PM »
Here is the code.
Code: [Select]
private wclBluetoothRadio GetSelectedRadio()
        {
            wclBluetoothRadio Result = null;

            if (lvRadios.SelectedItems.Count == 0)
            {
                Result = new wclBluetoothRadio();

                try
                {
                    Result.API = wclBluetoothDiscovery.StringToBluetoothAPI(lvRadios.Items[0].SubItems[1].Text);
                }
                catch (Exception )
                {
                    MessageBoxEx.Show(Resources.PlugAdaptorGR + ".Error code:201", headerMSG);

                }
             

                //MessageBox.Show("Select radio", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                Result = new wclBluetoothRadio();

                try
                {
                    Result.API = wclBluetoothDiscovery.StringToBluetoothAPI(lvRadios.SelectedItems[0].SubItems[1].Text);
                }
                catch
                {
                    Result = null;
                    throw;
                }
            }

            return Result;
        }

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Bluetooth adapter not found scenario
« Reply #3 on: August 04, 2008, 11:41:53 PM »
When and how lvRadios items created and inserted in the liist view

TheodorosGR

  • Guest
Re: Bluetooth adapter not found scenario
« Reply #4 on: August 05, 2008, 12:56:00 AM »
I think you need this:
Code: [Select]
private void ShowRadio(wclBluetoothRadio Radio)
        {
           
            String Address = "";

            try
            {
                Address = Radio.Address;
            }
            catch (Exception e)
            {
                Address = e.Message;
            }

            ListViewItem Item = lvRadios.Items.Add(Address);
            Item.SubItems.Add(wclBluetoothDiscovery.BluetoothAPIToString(Radio.API));

            try
            {
               
                Item.SubItems.Add(Radio.Connectable.ToString());
            }
            catch (Exception e)
            {
                Item.SubItems.Add(e.Message);
            }

            try
            {
                Item.SubItems.Add(Radio.Discoverable.ToString());
            }
            catch (Exception e)
            {
                Item.SubItems.Add(e.Message);
            }

            try
            {
                Item.SubItems.Add(Radio.Name);
            }
            catch (Exception e)
            {
                Item.SubItems.Add(e.Message);
            }
        }

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Bluetooth adapter not found scenario
« Reply #5 on: August 05, 2008, 10:06:44 AM »
Aha. OK.
I think the better and fast way to do what you need is:

1. Write procedure
wclBluetoothRadio GetRadio()
{
  if (wclAPI.Transports.Contains(trBluetooth)
  {
     wclBluetoothRadios Radios = wclBluetoothDiscovery.EnumRadio();
     wclBluetoothRadio Radio = Radio[0];
     Radios = null;
     return Radio;
   }
   return null;
}

2. Write OnChanged event for wcvlAPI and when it called (and when your app start) call the procedure.
3. If the procdure returns null show message about No Radio.

 

Sitemap 1 2 3 4 5 6 7