[英]Exception when connecting to device
我與藍牙設備(HC-05)的連接有問題。 調用BluetoothClient.Connect()
,有時會發生異常-“提供了無效的參數。”或其他。 但是有時設備會連接(通常是第一次連接)! 離開應用程式時是否必須關閉連線?
是的,您應該關閉連接並處置BluetoothClient。
private InTheHand.Net.Sockets.BluetoothClient BTClient =
new InTheHand.Net.Sockets.BluetoothClient();
private System.Net.Sockets.NetworkStream stream;
//代碼中的某處:
stream = BTClient.GetStream();
public void Disconnect()
{
if (BTClient == null )
return;
try
{
if (BTClient != null)
{
if (stream != null)
{
stream.ReadTimeout = 500;
stream.WriteTimeout = 500;
stream.Close();
}
if(BTClient.Connected)
BTClient.Close();
BTClient.Dispose();
}
}
catch (Exception ex)
{
throw ex;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.