我想接收从HC-06设备到PC的消息,我使用32英尺图书馆来管理蓝牙,但是每当我试图连接时,我都会得到一个异常。
HC-06使用SPP (Serial Port Profile),所以想法是在设备管理器中使用虚拟COM端口。然后使用SerialPort类进行通信。
异常
System.Net.Sockets.SocketException(0x80004005):连接尝试失败是因为连接方在一段时间后没有正确响应,或建立连接失败是因为连接主机未能响应我的蓝牙地址: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP at InTheHand.Net.Sockets.BluetoothClient.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;此外,我也尝试过在行RFCommProtocol (服务类)上使用SerialPort而不是SerialPort,但没有成功。
为了测试HC-06设备实际上是发送消息,我使用Realterm软件来检查它,我在终端COM8端口8=\BthModem0中分配波特率9600,并在终端中显示消息。BthModem通过TDI接口将所有I/O和控制操作定向到RfComm。
我遗漏了什么?我是否必须使用虚拟连接或其他什么方式才能获得HC-06消息?
发布于 2015-11-05 10:14:32
如果这是一个“正常”的Windows应用程序(而不是Windows应用程序),那么使用SerialPort类可能更容易。
https://stackoverflow.com/questions/33507665
复制相似问题