private bool ReopenPort() { bool result = false; InvokeWriteStateLbl("Reopening port"); InvokeSwitchProgressBarMode(ProgressBarStyle.Marquee); InvokeWriteLogString("Reopening port...\r\n"); try { nmeaPort.Close(); nmeaPort.PortBaudRate = BaudRate.baudRate115200; nmeaPort.IsRawModeOnly = true; Thread.Sleep(1000); nmeaPort.Open(); Thread.Sleep(2000); action = UCNL_FW_ACTION.FW_UPDATE_INIT; result = RequestTransferSize(); } catch (Exception ex) { ProcessException(ex, false); } return(result); }
private void connectionBtn_Click(object sender, EventArgs e) { if (gtrPort.IsOpen) { gtrPort.PortError -= gtrPortErrorEventHandler; gtrPort.NewNMEAMessage -= gtrPortNewNMEAMessageEventHandler; try { gtrPort.Close(); } catch (Exception ex) { ProcessException(ex, true); } if (settingsProvider.Data.IsGNSSEmulator) { try { gnssEmulatorPort.Close(); } catch (Exception ex) { ProcessException(ex, false); } } OnConnectionClosed(); } else { try { gtrPort.Open(); gtrPort.PortError += gtrPortErrorEventHandler; gtrPort.NewNMEAMessage += gtrPortNewNMEAMessageEventHandler; OnConnectionOpened(); } catch (Exception ex) { ProcessException(ex, true); OnConnectionClosed(); } if ((gtrPort.IsOpen) && (settingsProvider.Data.IsGNSSEmulator)) { try { gnssEmulatorPort.Open(); } catch (Exception ex) { ProcessException(ex, false); } } } }
private void connectionBtn_Click(object sender, System.EventArgs e) { if (inPort.IsOpen) { try { inPort.Close(); } catch (Exception ex) { ProcessException(ex, true); } if (settingsProvider.Data.IsUseOutPort) { try { outPort.Close(); } catch (Exception ex) { ProcessException(ex, true); } } connectionBtn.Checked = false; connectionBtn.Text = "CONNECT"; settingsBtn.Enabled = true; } else { try { inPort.Open(); connectionBtn.Text = "DISCONNECT"; connectionBtn.Checked = true; settingsBtn.Enabled = false; } catch (Exception ex) { ProcessException(ex, true); } if (settingsProvider.Data.IsUseOutPort) { try { outPort.Open(); } catch (Exception ex) { ProcessException(ex, true); } } } }
private void openClosePortBtn_Click(object sender, EventArgs e) { if (port.IsOpen) { try { port.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } State = AppState.PORT_CLOSED; } else { try { port.PortName = portNameCbx.SelectedItem.ToString(); port.Open(); State = AppState.PORT_OPENED; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void RestartPort() { try { if (port.IsOpen) { port.Close(); } UnsubscribePort(); port.Dispose(); } catch (Exception ex) { } StartEnumerate(); }
public void Stop() { if (inPort.IsOpen) { try { inPort.Close(); } catch (Exception ex) { LogEvent.Rise(inPort, new LogEventArgs(LogLineType.CRITICAL, ex)); } if (AUXGNSSUsed) { try { auxGNSSPort.Close(); } catch (Exception ex) { LogEvent.Rise(auxGNSSPort, new LogEventArgs(LogLineType.ERROR, ex)); } } if (OutPortUsed) { try { outPort.Close(); } catch (Exception ex) { LogEvent.Rise(outPort, new LogEventArgs(LogLineType.ERROR, ex)); } } } else { throw new InvalidOperationException("Cannot be stopped because has not been started"); } }
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { logger.Write("Closing..."); logger.FinishLog(); if (timer.IsRunning) { timer.Stop(); } if (port.IsOpen) { try { port.Close(); } catch { } } }
private bool CheckNextPort() { portSettings.PortName = portNames[curPortIdx]; bool result = false; try { port = new NMEASerialPort(portSettings); port.NewNMEAMessage = new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessage); port.PortError = new EventHandler <SerialErrorReceivedEventArgs>(port_PortError); port.Open(); var queryStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)LocalDataIDs.LOC_DATA_DEVICE_INFO, 0 }); port.SendData(queryStr); if (ConnectionEstablished != null) { ConnectionEstablished(this, new EventArgs()); } timer.Start(); result = true; } catch (Exception ex) { if (port.IsOpen) { port.Close(); } UnsubscribePort(); port.Dispose(); } return(result); }
public void Close() { port.Close(); }
public void Close() { timer.Stop(); port.Close(); }