public void Dispose() { if (_serialPort != null) { CloseConnection(); _serialPort.Dispose(); } }
new public void Dispose() { if (autoSession != null) { autoSession.Dispose(); } if (resetTimer != null) { resetTimer.Stop(); } }
public void Close() { if (ApiAnalyzer != null) { ApiAnalyzer.Dispose(); } if (MachineAnalyzer != null) { MachineAnalyzer.Dispose(); } if (hub != null) { hub.Close(); } }
/// <summary> /// Terminate the programm gracefully. /// </summary> private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (serialportForm != null) { serialportForm.Dispose(); } if (serialSession != null) { serialSession.Dispose(); } if (anaForm != null) { anaForm.Close(); } }
void attemptAutoConnect() { btnAutomatic.Text = "searching..."; btnAutomatic.Update(); foreach (string s in comboBoxPorts.Items) { try { if (autoSession != null) { autoSession.Pause(); while (autoSession.PortIsOpen) { ; } } autoSession = new SerialComm(s, Convert.ToInt32(textBoxBaudRate.Text), (byte)ModuleId_t.Api_e); autoSession.RegisterAckTimeoutHandler(ackTimeoutCallback); autoSession.RegisterPacketSentHandler(packetSentCallback); autoSession.MaxSendRepetition = 1; autoSession.AckTimeout = TimeSpan.FromMilliseconds(100); autoSession.ResponseTimeout = TimeSpan.FromMilliseconds(100); autoSession.Start(); autoConnectTimeoutTmr.Interval = 1000; autoConnectTimeoutTmr.Tick += new EventHandler(autoConnectTimeoutTmr_Tick); autoConnectTimeoutTmr.Start(); // send GetStatus request autoSession.EnqueuePacket((byte)ModuleId_t.Touch_e, new SerialComm.Message_t((byte)API_Command_t.GetStatus_e, 0), new byte[0], 0, true, SerialComm.Encrypt_t.No, 0, SerialComm.ApplicationPort_t.Api_e, 0xFF); while (status == MachineStatus_t.TryConnection && autoConnectTimeout == false) { } autoConnectTimeoutTmr.Stop(); autoConnectTimeout = false; if (status == MachineStatus_t.MachineFound) { autoSession.Dispose(); serialPort.PortName = autoSession.PortName; serialPort.BaudRate = autoSession.BaudRate; this.Close(); } else { status = MachineStatus_t.TryConnection; } } catch { } } if (autoSession != null) { autoSession.Dispose(); } btnAutomatic.Text = "nothing found"; resetTimer.Interval = 2000; resetTimer.Tick += new EventHandler(resetTimer_Tick); resetTimer.Start(); }