windows 蓝牙开源工具包分析及C#实例

本文深入分析了Windows平台下的蓝牙开源工具包,结合C#编程语言,探讨了如何在Windows环境下实现蓝牙功能,包括连接、数据传输等实例应用。
摘要由CSDN通过智能技术生成

windows 蓝牙开源工具包分析及C#实例


<buletooh-tool-v2.1.zip>中是使用“Windows Embedded Source Tools for Bluetooth”开发的实例程序。
Bluetooth的应用十分广泛,基于Bluetooth的通信程序开发主要有以下几个步骤:
服务端
* 设置本设备为可发现。
* 公开服务给其他Bluetooth设备访问。
* 接受其他Bluetooth设备的链接。
* 与链接上的Bluetooth设备进行通信。
客户端
* 发现周边Bluetooth设备。
* 主动与被发现的设备发起连接。
* 与链接上的Bluetooth设备进行通信。
在.NET Compact Framework下进行Bluetooth开发有几个可选解决方案
* 可以P/Invoke直接调用Bluetooth的API(btdrt.dll)
* 使用MS的Windows Embedded Source Tools for Bluetooth
* 使用32feet.NET库

这篇文章讲述基于Windows Embedded Source Tools for Bluetooth的开发,点击 链接 下载Windows Embedded Source Tools for Bluetooth,安装后在目录 C:\Program Files\Microsoft\Windows Embedded Source Tools会找到源码以及编译后的DLL。
Windows Embedded Source Tools for Bluetooth提供的API总结如下:
BluetoothRadio.cs
分析:
public enum BluetoothRadioMode : int
    {
        Off,        On,        Discoverable
    };

API:
bool Dispose()     设置蓝牙设备运行被发现或读取当前蓝牙设备是否允许被发现
BluetoothRadioMode BluetoothRadioMode()     设置或去读当前蓝牙状态
BluetoothDeviceCollection PairedDevices()    获取配对设备集
class BluetoothRadio :BluetoothRadio()    初始化蓝牙系统构造类

BluetoothEndPoint.cs
分析:
class BluetoothEndPoint    蓝牙端点构造类。
构造时包含deviceAddress ,serviceGuid,port三个值。

BluetoothService.cs
分析:
class BluetoothService:BluetoothService(Guid serviceGuid)    蓝牙服务端构造类,执行该构造类的应该是蓝牙通信中的主设备。
void Start()    启动服务
void Stop()    停止服务
bool Started    获取服务状态,启动或停止
bool ConnectionPending     指示是否有一个客户端等待连接到本服务上。
NetworkStream AcceptConnection()    接受一个连接,执行该函数后,该函数会挂起直到一个客户端连接上来。
Guid ServiceGuid    返回本服务的GUID

StandardServices.cs
分析:
class StandardServices:StandardServices()    
标准的蓝牙服务列表的GUID
Guid     SerialPortServiceGuid    返回串口服务对应的GUID

Registry.cs
分析:
class Registry    封装的注册表操作类。

SafeNativeMethods.cs
分析:
class SafeNativeMethods    构造类。

导入以下类库的API:
const string BTHUTIL_DLL = "bthutil.dll";
const string BTDRT_DLL = "btdrt.dll";
const string WINSOCK_DLL = "Ws2.dll";
const string CORE_DLL = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值