通过蓝牙32脚连接HC-06设备时出现端口错误异常 [英] Port Error exception when connecting HC-06 Device via Bluetooth 32Feet
问题描述
我想从 HC- 06 设备更改为PC
,我正在使用 32feet库来管理蓝牙,但是无论何时尝试连接出现异常.
I want to receive messages from HC-06 device to PC
, I am using 32feet library to manage Bluetooth, however whenever I tried to connect I get an exception.
HC-06
使用SPP (Serial Port Profile)
,因此其想法是在设备管理器中使用虚拟COM端口.然后使用SerialPort
类进行通信.
HC-06
uses the SPP (Serial Port Profile)
so the idea is to use a virtual COM port in the device manager. And then use the SerialPort
class to communicate.
System.Net.Sockets.SocketException(0x80004005):尝试连接 失败,因为关联方在 一段时间,或由于建立连接而建立的连接失败 主机未能响应我的蓝牙 地址:位于 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, 套接字地址(套接字地址)在 System.Net.Sockets.Socket.Connect(EndPoint remoteEP)位于 InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.Connect(BluetoothEndPoint remoteEP) InTheHand.Net.Sockets.BluetoothClient.Connect(BluetoothEndPoint remoteEP)....
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#
代码:
Current C#
code:
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);
但没有成功
Also I have tried using RFCommProtocol
(service class) instead of SerialPort
on the line
BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort);
but had no success
要进行一些测试,以证明HC-06设备实际上是sendind消息(我使用Realterm软件进行了检查),我在终端COM8 PORT 8=\BthModem0
中分配了波特率9600
,消息出现在终端中.
BthModem通过TDI接口将所有I/O和控制操作定向到RfComm
To do some tests that HC-06 device is in fact sendind messages I used Realterm software to check it out, I assign in terminal COM8 PORT 8=\BthModem0
with baud rate 9600
and messages appear in terminal.
BthModem directs all I/O and control operations to RfComm through a TDI interface
我想念什么?我是否必须使用虚拟连接或其他某种方式才能获得HC-06
消息?
What am I missing? Do I have to use virtual connection or something so I can get HC-06
messages?
推荐答案
如果这是一个普通" Windows应用程序(而不是Windows Store应用程序),则使用
If this is a "normal" Windows application (and not a Windows Store application), it's probably easier to use the SerialPort class.
这篇关于通过蓝牙32脚连接HC-06设备时出现端口错误异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!