示例#1
0
        public void Disconnect()
        {
            if (!IsConnected)
            {
                return;
            }

            try
            {
                phx42.DataPolled             -= Phx42OnDataPolled;
                phx42.Error                  -= Phx42OnError;
                phx42.CommandError           -= Phx42OnCommandError;
                phx42.WriteFlashProgress     -= Phx42OnWriteFlashProgress;
                phx42.ReadFlashProgress      -= Phx42OnReadFlashProgress;
                phx42.UpdateFirmwareProgress -= Phx42OnUpdateFirmwareProgress;
                phx42.StopPollingData();

                Task.Delay(500).Wait(500);

                phx42.ShutdownNow = true;

                Task.Delay(500).Wait(500);
            }
            catch (Exception ex)
            {
                phx42?.WriteToPhxLog("Problem stopping polling");
                phx42?.WriteExceptionToPhxLog(ex);
            }

            try
            {
                phx42.ShutdownNow = true;

                _bluetoothService.Disconnect(_device);
            }
            catch (Exception ex)
            {
                phx42?.WriteToPhxLog("Problem disconnecting");
                phx42?.WriteExceptionToPhxLog(ex);
            }

            IsConnected = false;
            Status      = "Disconnected";

            OnDisconnected(new DeviceEventArgs(this));
        }