32脚蓝牙连接HC-06设备时Port Error异常
Port Error exception when connecting HC-06 Device via Bluetooth 32Feet
我想接收来自 HC-06 device to PC
, I am using 32feet library 的消息以管理蓝牙,但是每当我尝试连接时都会出现异常。
HC-06
使用 SPP (Serial Port Profile)
所以想法是在设备管理器中使用虚拟 COM 端口。然后使用SerialPort
class进行通信。
异常
System.Net.Sockets.SocketException(0x80004005): A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond my bluetooth
address: at
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress) at
System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at
InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint
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
(服务class)代替SerialPort
就行了
BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort);
但没有成功
为了测试 HC-06 设备实际上是在发送消息,我使用 Realterm 软件进行检查,我在终端 COM8 PORT 8=\BthModem0
中分配了波特率 9600
并且消息出现在终端。
BthModem 通过 TDI 接口将所有 I/O 和控制操作指向 RfComm
我错过了什么?我是否必须使用虚拟连接或其他方式才能收到 HC-06
消息?
如果这是 "normal" Windows 应用程序(而不是 Windows 商店应用程序),使用 SerialPort class 可能更容易。
我想接收来自 HC-06 device to PC
, I am using 32feet library 的消息以管理蓝牙,但是每当我尝试连接时都会出现异常。
HC-06
使用 SPP (Serial Port Profile)
所以想法是在设备管理器中使用虚拟 COM 端口。然后使用SerialPort
class进行通信。
异常
System.Net.Sockets.SocketException(0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond my bluetooth address: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint 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
(服务class)代替SerialPort
就行了
BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort);
但没有成功
为了测试 HC-06 设备实际上是在发送消息,我使用 Realterm 软件进行检查,我在终端 COM8 PORT 8=\BthModem0
中分配了波特率 9600
并且消息出现在终端。
BthModem 通过 TDI 接口将所有 I/O 和控制操作指向 RfComm
我错过了什么?我是否必须使用虚拟连接或其他方式才能收到 HC-06
消息?
如果这是 "normal" Windows 应用程序(而不是 Windows 商店应用程序),使用 SerialPort class 可能更容易。