locked
how to use bluetooth class RRS feed

  • Question

  • hi. i downloaded the windows embbeded source tools for bluetooth and i found that there are classes in there which i could use. i was just wondering if someone could give me a sample on how to use it.

    Code Snippet

    public class BluetoothDevice

    {

    /// <summary>

    /// Constructs an object to represent the Bluetooth device described with a name and address

    /// </summary>

    /// <param name="name">Describes the Bluetooth device</param>

    /// <param name="address">8 byte bluetooth address</param>

    public BluetoothDevice(string name, byte[] address)

    {

    if (name == null)

    {

    throw new ArgumentNullException("name");

    }

    if (address == null)

    {

    throw new ArgumentNullException("address");

    }

    this.name = name;

    this.address = address;

    }

    /// <summary>

    /// Describes a Bluetooth device

    /// </summary>

    public string Name

    {

    get

    {

    return name;

    }

    }

    /// <summary>

    /// 8 byte Bluetooth address

    /// </summary>

    public byte[] Address

    {

    get

    {

    return address;

    }

    }

    /// <summary>

    /// Provides the ability to connect to this device and transfer data

    /// </summary>

    /// <param name="serviceGuid">Specifies the Guid of the service to connect with on the remote device</param>

    /// <returns>A NetworkStream object used to communicate between the two devices</returns>

    public NetworkStream Connect(Guid serviceGuid)

    {

    Socket clientSocket = new Socket((AddressFamily)32, SocketType.Stream, (ProtocolType)3);

    BluetoothEndPoint endPoint = new BluetoothEndPoint(this, serviceGuid);

    clientSocket.Connect(endPoint);

    // the network stream will own the socket so that it will clean up nicely

    return new NetworkStream(clientSocket, true);

    }

    private string name;

    private byte[] address;

    }

     

     

    how do i make an instance of it in another class and how do i use it to connect to another device?

    Monday, May 28, 2007 8:32 PM

Answers

All replies