用心做好每一件事情!

C#蓝牙开发之查找设备以及配对

 

           
BluetoothClient Blueclient = new BluetoothClient();
         Dictionary<string, BluetoothAddress> deviceAddresses = new Dictionary<string, BluetoothAddress>();
         BluetoothRadio BuleRadio = BluetoothRadio.PrimaryRadio;
            BuleRadio.Mode = RadioMode.Connectable;
            BluetoothDeviceInfo[] Devices = Blueclient.DiscoverDevices();
            lsbDevices.Items.Clear();
            deviceAddresses.Clear();
            foreach (BluetoothDeviceInfo device in Devices)
            {
                //循环将所有搜索到的设备添加进来。
                lsbDevices.Items.Add(device.DeviceName);
                deviceAddresses[device.DeviceName] = device.DeviceAddress;
            }
 
配对:
      Blueclient.SetPin(DeviceAddress, txtPwd.Text.Trim());
      Blueclient.Connect(DeviceAddress, BluetoothService.Handsfree);

PC上安装Windows Mobile 6.0 SDK和ActiveSync同步软件,ActiveSync目前为4.5版本,通过VS新建的程序便可以部署在相应的设备上面,这里我使用自己的手机来作为测试机,刚好手机也是Windows Mobile的系统.

点击“Find Devices”开始搜索周围的蓝牙设备

 

下图为搜索到的蓝牙设备。图中PC-2012...为我的开发电脑,电脑上面安装了有一个蓝牙的驱动,另一个6690的另一个开了蓝牙的手机.。

 

选中一个设备进行连接。

 

如果这里不输入对方设置的密码或者输入错误的密码,那么会提示“目标主动拒绝。。。”
 

 

 

如果密码正确,则可以正常配对。
 

 

从下图可以看得出已经配对成功了,

 

另外,通过VS的远程放大可以捕捉到设备的屏幕,

BlueTooth

 

posted @ 2012-08-26 14:01  无 影  阅读(14190)  评论(4编辑  收藏  举报
作者: Allen【QQ:96966 1314】 网名:无影 出处: http://www.cnblogs.com/allen0118/ 声明: 本文版权归作者和博客园共有!转载时必须保留此段声明,且在文章页面明显位置给出原文连接。