【发布时间】:2015-11-05 18:14:32
【问题描述】:
我想从HC-06 设备接收消息到PC,我正在使用32feet library 管理蓝牙,但是每当我尝试连接时都会出现异常。
HC-06 使用SPP (Serial Port Profile),所以想法是在设备管理器中使用虚拟 COM 端口。然后使用SerialPort类进行通信。
异常
System.Net.Sockets.SocketException(0x80004005):连接尝试 失败,因为连接方没有正确响应后 一段时间,或建立连接失败,因为已连接 主机未能响应我的蓝牙 地址:在 System.Net.Sockets.Socket.DoConnect(端点 endPointSnapshot, SocketAddress 套接字地址)在 System.Net.Sockets.Socket.Connect(EndPoint remoteEP) 在 InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint 远程EP)在 InTheHand.Net.Sockets.BluetoothClient.Connect(BluetoothEndPoint 远程EP) ....
当前C# 代码:
string my_pin ="1234"; //default pin for HC-06 device
BluetoothAddress address = BluetoothAddress.Parse("201311111662"); //address of HC-06
BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort);
bool t = false;
BluetoothSecurity.PairRequest(address, my_pin);
BluetoothClient cli = new BluetoothClient();
cli.Connect(ep);
t = cli.Connected;
我也试过用RFCommProtocol(服务类)代替SerialPort就行了
BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort); 但没有成功
为了测试 HC-06 设备实际上是在发送消息,我使用 Realterm 软件进行了检查,我在终端 COM8 PORT 8=\BthModem0 中分配了波特率 9600,消息出现在终端中。
BthModem 通过 TDI 接口将所有 I/O 和控制操作定向到 RfComm
我错过了什么?我是否必须使用虚拟连接或其他方式才能收到HC-06 消息?
【问题讨论】:
标签: c# sockets bluetooth 32feet