问题
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
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.
Exception
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) ....
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;
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
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
What am I missing? Do I have to use virtual connection or something so I can get HC-06
messages?
回答1:
If this is a "normal" Windows application (and not a Windows Store application), it's probably easier to use the SerialPort class.
来源:https://stackoverflow.com/questions/33507665/port-error-exception-when-connecting-hc-06-device-via-bluetooth-32feet