private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { logger.TextAddedEvent -= loggerTextAddedEventHandler; logger.FinishLog(); timer.Tick -= timerTickHandler; if (timer.IsRunning) { timer.Stop(); } timer.Dispose(); if (gnssEmulatorPort != null) { if (gnssEmulatorPort.IsOpen) { gnssEmulatorPort.Close(); } gnssEmulatorPort.Dispose(); } if (gtrPort.IsOpen) { gtrPort.NewNMEAMessage -= gtrPortNewNMEAMessageEventHandler; gtrPort.PortError -= gtrPortErrorEventHandler; gtrPort.Close(); } }
private void RestartPort() { try { if (port.IsOpen) { port.Close(); } UnsubscribePort(); port.Dispose(); } catch (Exception ex) { } StartEnumerate(); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (timer.IsRunning) { timer.Stop(); } timer.Dispose(); if (inPort.IsOpen) { try { inPort.Close(); } catch { } } inPort.Dispose(); if (AUXGNSSUsed) { try { auxGNSSPort.Close(); } catch { } auxGNSSPort.Dispose(); } if (OutPortUsed) { if (outPort.IsOpen) { try { outPort.Close(); } catch { } } outPort.Dispose(); } } disposed = true; } }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (IsOpen) { Close(); } port.Dispose(); timer.Dispose(); } disposed = true; } }
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); }