我想从HC-06设备接收消息PC
,我正在使用32feet 库来管理蓝牙,但是每当我尝试连接时都会出现异常。
HC-06
使用SPP (Serial Port Profile)
so的想法是在设备管理器中使用虚拟COM端口。然后使用SerialPort
类进行交流。
例外
System.Net.Sockets.SocketException(0x80004005):连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应 我的蓝牙地址:在 System.Net.Sockets .Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 在 InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint remoteEP) 在 InTheHand.Net.Sockets.BluetoothClient 的 System.Net.Sockets.Socket.Connect(EndPoint remoteEP)。连接(蓝牙端点远程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
消息?