/** * Operation to execute when the user clicks on the Disconnect button * Stops the threads that are interacting with the server */ private void disconnect() { _updateTimer.Enabled = false; if (_orientation_fetcher.IsAlive()) _orientation_fetcher.Stop(); if (_frame_fetcher.IsAlive()) _frame_fetcher.Stop(); _orientation_fetcher = new OrientationFetcher(_satService); _frame_fetcher = new FrameFetcher(_satService, pictureBox); /*if (_scf != null && (_scf.State == CommunicationState.Faulted || serviceIsFaulted(_satService))) serviceDisconnect();*/ serviceDisconnect(); clearUI(); }
private void connectBn_Click(object sender, EventArgs e) { Invoke(new Action(() => { // try to ping the server try { serviceConnect(); _satService.NamedPing("Hello world !"); } catch (Exception) { disconnect(); MessageBox.Show("Error: impossible to ping the server"); Console.Error.WriteLine("Error: impossible to ping the server"); return; } connectBn.Enabled = false; disconnectBn.Enabled = true; IPAdress.Enabled = false; stabilizeCb.Enabled = true; // to enable/disable the controller server side _orientation_fetcher = new OrientationFetcher(_satService); _orientation_fetcher.Start(); _frame_fetcher = new FrameFetcher(_satService, pictureBox); _frame_fetcher.Start(); _updateTimer.Enabled = true; // update position of the cursors on the track bar pitchTrackBar.Value = _orientation_fetcher.GetServoPitch(); yawTrackBar.Value = _orientation_fetcher.GetServoYaw(); // if the save path is valid checkSavePath(false); kiTextBox.Text = "" + Math.Round(_orientation_fetcher.GetKi(), 3); kpTextBox.Text = "" + Math.Round(_orientation_fetcher.GetKp(), 3); expTimeTextBox.Text = "" + _orientation_fetcher.GetExpTime(); fpsTextBox.Text = "" + _orientation_fetcher.GetFps(); })); }