DCSIMG
Working With Bluetooth Devices Using C# – Part 1 - Shai Raiten

Shai Raiten

 Subscribe

Working With Bluetooth Devices Using C# – Part 1

Working With Bluetooth Devices Using C# – Part 1

32feet.NET is a shared-source project to make personal area networking technologies such as Bluetooth, Infrared (IrDA) and more, easily accessible from .NET code.

Supports desktop, mobile or embedded systems. The project currently consists of the following libraries:-

  • Bluetooth
  • IrDA
  • Object Exchange

In this post I’ll show how to find Bluetooth devices using C# code.

MyPhone

Download Demo Project

First download 32Feet.net assemblies, the create new project and add those assemblies.

Add using for using InTheHand.Net.Sockets;

BluetoothClient bc = new BluetoothClient();

Use BluetoothClient to discover bluetooth devices:

public BluetoothDeviceInfo[] DiscoverDevices();

public BluetoothDeviceInfo[] DiscoverDevices(int maxDevices);

public BluetoothDeviceInfo[] DiscoverDevices(int maxDevices, bool authenticated, bool remembered, bool unknown);


*** DiscoverDevices takes about 20-30 seconds to complete.

List<Device> devices = new List<Device>();

BluetoothClient bc = new BluetoothClient();

BluetoothDeviceInfo[] array = bc.DiscoverDevices();

int count = array.Length;

for (int i = 0; i < count; i++)

{

    Device device = new Device(array[i]);

    devices.Add(device);

}

public class Device

{

    public string DeviceName { get; set; }

    public bool Authenticated { get; set; }

    public bool Connected { get; set; }

    public ushort Nap { get; set; }

    public uint Sap { get; set; }

    public DateTime LastSeen { get; set; }

    public DateTime LastUsed { get; set; }

    public bool Remembered { get; set; }

 

    public Device(BluetoothDeviceInfo device_info)

    {

        this.Authenticated = device_info.Authenticated;

        this.Connected = device_info.Connected;

        this.DeviceName = device_info.DeviceName;

        this.LastSeen = device_info.LastSeen;

        this.LastUsed = device_info.LastUsed;

        this.Nap = device_info.DeviceAddress.Nap;

        this.Sap = device_info.DeviceAddress.Sap;

        this.Remembered = device_info.Remembered;

    }

 

    public override string ToString()

    {

        return this.DeviceName;

    }

}

Download Demo Project

Comments

Shai Raiten said:

Working With Bluetooth Devices Using C# – Part 2 ( OBEX) In my last post I talked about Working With

# June 23, 2009 9:19 AM

online said:

ler todo o blog, muito bom

# March 13, 2010 5:08 AM

Gili said:

Hi Shai,

Ahla code, but it doesnt seem to work with devices made by BroadCom Corporation.

any other solution for us?

# March 25, 2010 10:47 PM

shair said:

Hi Gili,

Please contact me through "Blog Contact" and I'll help solve this issue with BroadCom products.

Thanks

# March 25, 2010 11:57 PM

Shai Raiten said:

Blue Radar Application On CodePlex Couple of week ago I wrote couple of posts about working with Bluetooth

# April 11, 2010 11:03 AM

Murali said:

Hi,

Thanks for the useful post and code.

I am a kind of new bee in bluetooth technologies. I am experimenting with my Health related application, I am actually preparing some demo.

My problem is I cant download 32Feet.net assemblies from their website. Could you kindly help me by guiding to find the direct link to download them.

Help is highly apreciated.

Thanks

Murali

# May 10, 2010 3:18 PM

shair said:

Hi,

Try this link:

32feet.codeplex.com/.../27693

Let me know if this works.

# May 10, 2010 4:22 PM

Nuno Moreira said:

How can we detect if a service is present in a device ? I mean, when i connect to a device i want to know if a specified Service is already installed...

Thanks in advance

NM

# May 15, 2010 12:13 PM

shair said:

Hi,

I have this example on the Bluetooth Radar project in codeplex, you an download the source and how it is done.

bluetoothradar.codeplex.com

Enjoy

# May 15, 2010 1:20 PM

Carlos dos Santos » Blog Archive » Desenvolvimento para Bluetooth com C# said:

Pingback from  Carlos dos Santos  &raquo; Blog Archive   &raquo; Desenvolvimento para Bluetooth com C#

# June 22, 2010 1:21 AM

lavanya said:

hi it says 33feet does not support bluetooth stack. my laptop is 3000 g530s

there is no bluetooth. but i use a dongle of bluesoleil. even then its shows not suppported. kindly help

# July 7, 2010 12:41 PM

bnvnvbn said:

nbvnvnv

# October 29, 2011 8:51 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: