📄 bluetoothdevice.cs
字号:
// Copyright (c) David Vescovi. All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/?linkid=2933443.
//
#region Using directives
using System;
using System.Net.Sockets;
#endregion
namespace Gumstix.Bluetooth
{
/// <summary>
/// Represents a unique Bluetooth device and provides the ability to connect with it on a
/// specified service.
/// </summary>
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -