WPF使用32feet.net进行蓝牙连接

LH806732 2016-09-30 05:44:53
环境:
开发:WPF + PC(windows 7)
客户端:PC(windows 7)
远程蓝牙设备:华为荣耀4C
蓝牙库:32feet.net


BluetoothClient localClient;

1. 查找设备完成
2. 配对完成
3. 连接远程设备:
BluetoothEndPoint ep;

// 第二个参数只有选择BluetoothService.Handsfree才能连上远程蓝牙设备
ep = new BluetoothEndPoint(mSelectDevice.DeviceAddress, BluetoothService.Handsfree);
//ep = new BluetoothEndPoint(mSelectDevice.DeviceAddress, BluetoothService.SerialPort);
localClient.BeginConnect(ep, new AsyncCallback(RemoteDeviceConnect), localClient);// 使用异步方式连接

private void RemoteDeviceConnect(IAsyncResult result)// 异步连接完成
{
BluetoothClient client = (BluetoothClient)result.AsyncState;

if (client.Client.Connected)// 刚进来时Connected为true,调试过程停在这(断点)过了5秒左右变成false
{
mNetworkStream = client.GetStream();
mRevThread = new Thread(BT_DataReceive);
mRevThread.Start();
}
}

代码还未实现断开连接,为什么刚进入RemoteDeviceConnect方法时client.Client.Connected为true,debug停在这5秒左右就变成false?
...全文
1272 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,140

社区成员

发帖
与我相关
我的任务
社区描述
Windows客户端使用相关问题交流社区
社区管理员
  • Windows客户端使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧