Posts: 7
Joined: Mon Dec 08, 2008 8:21 pm
Location: USA

Help with Service discovery

Sat Dec 27, 2008 4:50 am

I am using the classes provided in the multiple form (compact framework version) to build one form that does the discovery and connection to the serial service that just reads the data from bluethooth device. Thus far only the discovery portion works. When I click on a device I want to list the services for the device, and then click a Connect button to connect to the device and start reading the data being pushed. Can someone help me with this, or at least tell me were I've gone wrong? It is in C#, but this is what I have for discovering the services:

private void ServiceDiscoveryStarted(object sender, Franson.BlueTools.BlueToolsEventArgs eventArgs)
statusLabel.Text = "Discovering services...";

lstServices.Enabled = false;
lstDevices.Enabled = false;
cmdDiscover.Enabled = false;

private void ServiceDiscovered(object sender, Franson.BlueTools.BlueToolsEventArgs eventArgs)
Franson.BlueTools.RemoteService service = (Franson.BlueTools.RemoteService)((Franson.BlueTools.DiscoveryEventArgs)eventArgs).Discovery;


private void ServiceDiscoveryComplete(object sender, Franson.BlueTools.BlueToolsEventArgs eventArgs)
statusLabel.Text = "Service discovery complete.";

lstServices.Enabled = true;
lstDevices.Enabled = true;
cmdDiscover.Enabled = true;

Service[] services = (Service[])((DiscoveryEventArgs)eventArgs).Discovery;

for (int i = 0; i < services.Length; i++)
if (lstServices.Items.IndexOf(services) == -1)

private void lstDevices_SelectedIndexChanged(object sender, EventArgs e)
if (lstDevices.SelectedItem != null)

// cast the device from the selection of the list of devices
Franson.BlueTools.RemoteDevice device = (RemoteDevice)lstDevices.SelectedItem;
//Form2 serviceForm = new Form2(checkBox1.Checked, device);

// show the form with the list of services

m_shared_device = new Franson.Guide.SharedRemoteDevice(device);
m_shared_device.AddEvent(this, Franson.BlueTools.EventType.ServiceDiscoveryStarted, new BlueToolsEventHandler(this.ServiceDiscoveryStarted));
m_shared_device.AddEvent(this, Franson.BlueTools.EventType.ServiceDiscovered, new BlueToolsEventHandler(this.ServiceDiscovered));
m_shared_device.AddEvent(this, Franson.BlueTools.EventType.ServiceDiscoveryCompleted, new BlueToolsEventHandler(this.ServiceDiscoveryComplete));

// deselect the device in the list
lstDevices.SelectedIndex = -1;


Thanks for all help.

Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Help with Service discovery

Sun Dec 28, 2008 10:51 pm

Look at the FindAndConnect sample. It does exactly what you want to achieve.


Return to “BlueTools”