} // ExecuteConnectCommand() #endif /// <summary> /// Connects to the specified peer. /// </summary> /// <param name="peerInformation">The peer information.</param> /// <returns>An async Task.</returns> private async Task Connect(PeerInformation peerInformation) { var socket = await this.bluetoothManager.ConnectToDevice(peerInformation); if (socket == null) { // stop any running operation this.Stop(); this.ShowToast("Connection to OBD Interface failed"); return; } // if this.OutputText("Connected."); this.ConnectedHint = "Connected"; this.socketConnection = new ObdStreamSocketDeviceConnection(socket); this.socketConnection.ConnectionClosed += this.OnConnectionClosed; this.socketConnection.ErrorEncountered += this.OnErrorEncountered; this.obdManager = new ObdManager(this.socketConnection); this.obdManager.ErrorEncountered += this.OnErrorEncountered; if (this.wasRunning) { this.Start(); } // if } // Connect()
} // OnErrorEncountered() /// <summary> /// Disconnects this instance. /// </summary> private void Disconnect() { // stop any running operation this.Stop(); this.socketConnection.ConnectionClosed -= this.OnConnectionClosed; this.socketConnection = null; this.OutputText("Disconnected."); this.ConnectedHint = "Not Connected!"; } // Disconnect()