[英]Port Error exception when connecting HC-06 Device via Bluetooth 32Feet
我想接收從HC-06設備到PC
消息,我正在使用32feet庫來管理藍牙,但是無論何時嘗試連接,都會出現異常。
HC-06
使用SPP (Serial Port Profile)
因此其想法是在設備管理器中使用虛擬COM端口。 然后使用SerialPort
類進行通信。
System.Net.Sockets.SocketException(0x80004005):連接嘗試失敗,因為一段時間后連接方未正確響應,或者由於連接的主機未能響應我的藍牙地址 ,建立的連接失敗:System.Net.Sockets InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.System.Net.Sockets.Socket.Connect(EndPoint remoteEP)的InTheHand.Net.Sockets.BluetoothClient的.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)。連接(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
(服務類)代替BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort);
上的SerialPort
BluetoothEndPoint ep = new BluetoothEndPoint(address, BluetoothService.SerialPort);
但沒有成功
為了測試HC-06設備實際上是sendind消息,我使用Realterm軟件對其進行了檢驗,我在終端8=\\BthModem0
PORT 8=\\BthModem0
了波特率為9600
並且消息出現在終端中。 BthModem通過TDI接口將所有I / O和控制操作定向到RfComm
我想念什么? 我是否必須使用虛擬連接或其他某種方式才能獲得HC-06
消息?
如果這是“常規” Windows應用程序(而不是Windows Store應用程序),則使用SerialPort類可能更容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.