private void Start_Button_Click(object sender, RoutedEventArgs e) { if (Settings.SelectedDevice.DeviceType != BaseDevice.DeviceTypeOptions.TwiKfdtool) { ErrorEmulation(string.Format("The device type {0} does not support MR emulation", Settings.SelectedDevice.DeviceType.ToString())); return; } if (Settings.SelectedDevice.TwiKfdtoolDevice.ComPort == string.Empty) { ErrorEmulation("No device selected"); return; } StartEmulation(); Task.Run(() => { ap = null; try { ap = new AdapterProtocol(Settings.SelectedDevice.TwiKfdtoolDevice.ComPort); ap.Open(); ap.Clear(); twp = new ThreeWireProtocol(ap); twp.StatusChanged += OnProgressUpdated; twp.MrRunProducer(); } catch (Exception ex) { ErrorEmulation(ex.Message); } finally { try { if (ap != null) { ap.Close(); } } catch (System.IO.IOException ex) { Log.Warn("could not close serial port: {0}", ex.Message); } } }); }
private void Start_Button_Click(object sender, RoutedEventArgs e) { Settings.InProgressScreen = "NavigateP25MrEmulator"; StartEmulation(); Task.Run(() => { if (Settings.Port == string.Empty) { throw new ArgumentException("port empty"); } ap = null; try { ap = new AdapterProtocol(Settings.Port); ap.Open(); ap.Clear(); twp = new ThreeWireProtocol(ap); twp.StatusChanged += OnProgressUpdated; twp.MrRunProducer(); } catch (Exception ex) { ErrorEmulation(ex.Message); } finally { try { if (ap != null) { ap.Close(); } } catch (System.IO.IOException ex) { //Logger.Warn("could not close serial port: {0}", ex.Message); } } }); }