使用C#更改Smartphone(WM5)的蓝牙状态
来源:互联网 发布:模拟城市5 mac 破解版 编辑:程序博客网 时间:2024/04/29 19:18
最近在学.net CF,写一个GPS的应用程序,手机是多普达585,系统为WM5 Smartphone,.NET CF 2,手机与GPS通过蓝牙连接,连接后以虚拟串口的形进行通讯。
手机平时的蓝牙都是关着的,要不然太耗电了。每次使用GPS前,都得手动开启蓝牙,用完GPS之后,还得手机关闭蓝牙,有些麻烦。通过搜索,终于找到开启和关闭蓝牙的API。写成一个简单的类,要用时引用一下就可以。
using System;
using System.Runtime.InteropServices;
namespace GPS
{
public class Bluetooth
{
//TODO THIS IS NOT TESTED!!!
public enum RadioMode {
BTH_POWER_OFF = 0,
BTH_CONNECTABLE = 1,
BTH_DISCOVERABLE = 2
}
[DllImport("BthUtil.dll", SetLastError = true)]
public static extern int BthGetMode(out RadioMode dwMode);
[DllImport("BthUtil.dll", SetLastError = true)]
public static extern int BthSetMode(RadioMode dwMode); }
}
using System.Runtime.InteropServices;
namespace GPS
{
public class Bluetooth
{
//TODO THIS IS NOT TESTED!!!
public enum RadioMode {
BTH_POWER_OFF = 0,
BTH_CONNECTABLE = 1,
BTH_DISCOVERABLE = 2
}
[DllImport("BthUtil.dll", SetLastError = true)]
public static extern int BthGetMode(out RadioMode dwMode);
[DllImport("BthUtil.dll", SetLastError = true)]
public static extern int BthSetMode(RadioMode dwMode); }
}
使用:
using GPS;
打开串口前调用:
Bluetooth.RadioMode mode = Bluetooth.RadioMode.BTH_POWER_OFF;
int ret = 0;
//检查蓝牙状态,如果不是"连接"状态,则设为"连接"状态
ret = Bluetooth.BthGetMode(out mode);
if(mode!=Bluetooth.RadioMode.BTH_CONNECTABLE) Bluetooth.BthSetMode(Bluetooth.RadioMode.BTH_CONNECTABLE);
int ret = 0;
//检查蓝牙状态,如果不是"连接"状态,则设为"连接"状态
ret = Bluetooth.BthGetMode(out mode);
if(mode!=Bluetooth.RadioMode.BTH_CONNECTABLE) Bluetooth.BthSetMode(Bluetooth.RadioMode.BTH_CONNECTABLE);
退出程序时调用:
//关闭蓝牙
Bluetooth.BthSetMode(Bluetooth.RadioMode.BTH_POWER_OFF);
Bluetooth.BthSetMode(Bluetooth.RadioMode.BTH_POWER_OFF);
- 使用C#更改Smartphone(WM5)的蓝牙状态
- 使用C#开发SmartPhone程序入门
- 使用C#开发SmartPhone程序入门1
- 蓝牙状态的监听
- 蓝牙的状态详解
- 蓝牙的设置状态
- wm5获得电池状态信息
- C# DataRowState - 状态更改细节
- 在WM5以上系统使用Notification Broker机制实现获取全部电话状态
- C# WM5/6 界面美观
- Windows Mobile的蓝牙状态
- 蓝牙的四种状态
- 用C#修改WM5.0和WM6.0 系统平台的时间
- c#开发的运行在wm5.0环境中的sqlce数据库操作。
- C#使用任务栏的状态区
- 在C#的Form中动态更改菜单、工具栏的状态
- 蓝牙状态
- WM5 中起用OBEX实现蓝牙收发文件
- linux内核编译详解
- 献给ARM爱好者
- “我只买黄金现货不买黄金股票,那是纸上黄金”
- 货币贬值与剪羊毛 读《货币战争》有感
- java 时间提醒
- 使用C#更改Smartphone(WM5)的蓝牙状态
- 标准时间
- JSF入门
- FC7安装后的配置
- 苹果总裁史蒂夫乔布斯在斯坦福大学的演讲
- 香辣虾的做法
- 密码监听器注册算法分析
- .net中窗体之间的数据交换总结
- 用VS.NET2003开发驱动程序