0
我的藍牙設備(HC-05)連接出現問題。 當致電BluetoothClient.Connect()
時,有時發生異常 - 「提供的參數無效」或其他。但有時設備連接(通常在第一次連接)! 當我離開應用程序時,是否必須關閉連接?連接到設備時出現異常
我的藍牙設備(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;
}
}