Wireless Communication Library Support Forum

Frameworks => Bluetooth Framework => Topic started by: TheodorosGR on August 04, 2008, 12:38:46 PM

Title: Bluetooth adapter not found scenario
Post by: TheodorosGR 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
Title: Re: Bluetooth adapter not found scenario
Post by: Mike Petrichenko 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.
Title: Re: Bluetooth adapter not found scenario
Post by: TheodorosGR 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;
        }
Title: Re: Bluetooth adapter not found scenario
Post by: Mike Petrichenko on August 04, 2008, 11:41:53 PM
When and how lvRadios items created and inserted in the liist view
Title: Re: Bluetooth adapter not found scenario
Post by: TheodorosGR 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);
            }
        }
Title: Re: Bluetooth adapter not found scenario
Post by: Mike Petrichenko 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.