首页 文章

通过蓝牙32Feet连接HC-06设备时出现端口错误异常

提问于
浏览
0

我想从HC-06设备接收消息到 PC ,我正在使用32feet library管理蓝牙,但每当我尝试连接时,我都会遇到异常 .

HC-06 使用 SPP (Serial Port Profile) 所以想法是在设备管理器中使用虚拟COM端口 . 然后使用 SerialPort 类进行通信 .

例外

System.Net.Sockets.SocketException(0x80004005):连接尝试失败,因为连接方在一段时间后没有正确响应,或者 Build 的连接失败,因为连接的主机无法响应我的蓝牙地址:在System.Net . 位于InTheHand.Net.Sockets.BluetoothClient的InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint remoteEP)的System.Net.Sockets.Socket.Connect(EndPoint remoteEP)上的Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress) .Connect(BluetoothEndPoint remoteEP)....

当前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;

我也尝试在 BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort); 上使用 RFCommProtocol (服务类)而不是 SerialPort ,但没有成功

为了做一些测试HC-06设备实际上是sendind消息,我使用Realterm软件检查出来,我在终端COM8 PORT 8=\BthModem0 中分配波特率 9600 并且消息出现在终端中 . BthModem directs all I/O and control operations to RfComm through a TDI interface

我错过了什么?我是否必须使用虚拟连接或其他东西才能获得 HC-06 消息?

1 回答

  • 1

    如果这是一个"normal" Windows应用程序(而不是Windows应用商店应用程序),则可能更容易使用SerialPort class .

相关问题