private void connectToToolStripMenuItem_Click(object sender, EventArgs e) { if (m_terminalClient != null) { return; } ConnectTo ct = new ConnectTo(); if (ct.ShowDialog() == DialogResult.OK) { if (ct.IsSerial) { SerialParams sp = Helper.GetDefaultSerialParams(); sp.PortName = ct.SerialPort.ToUpper(); if (!TryConnectTerminalClient(sp)) { m_terminalClient = null; } } else { ConnectWithNkParams(ct.Address, ct.Port); } } }
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { if (m_terminalClient != null) { m_terminalClient.Disconnect(); m_terminalClient = null; SetTitle(null); } SetDisconnectState(); }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (m_terminalClient != null) { m_terminalClient.Disconnect(); m_terminalClient = null; } if (m_shareServer != null) { m_shareServer.Stop(); } }
private bool TryConnectTerminalClient(SerialParams sp) { m_terminalClient = new SerialClient(sp); m_terminalClient.DataReceivedEvent += MTerminalClientDataReceivedEvent; if (m_terminalClient.Connect()) { SetTitle(m_terminalClient.Title); SetConnectState(); return(true); } MessageBox.Show(String.Format("Connecting to {0} failed.", sp.PortName)); return(false); }
private void ConnectWithNkParams(string address, int port) { var np = new NkParams { Address = address, Port = port }; m_terminalClient = new NetworkClient(np); m_terminalClient.DataReceivedEvent += new DataReceivedHandler(MTerminalClientDataReceivedEvent); if (m_terminalClient.Connect()) { SetTitle(m_terminalClient.Title); SetConnectState(); } else { MessageBox.Show(String.Format("Connection to {0}:{1} failed.", np.Address, np.Port)); m_terminalClient = null; } }
public void CheckAutoConnect() { if (Config.GetInstance().GetConfig().AutoConnect) { if (Config.GetInstance().GetConfig().ConType == ConnectionType.Serial) { SerialParams sp = Config.GetInstance().GetConfig().SerialParams; if (!TryConnectTerminalClient(sp)) { m_terminalClient = null; sp.PortName = "COM2"; if (!TryConnectTerminalClient(sp)) { m_terminalClient = null; } } } else { ConnectWithNkParams(Config.GetInstance().GetConfig().NtAddress, Config.GetInstance().GetConfig().NtPort); } } }
public TerminalApplicationService(ITerminalClient terminalClient = null) { this.terminalClient = terminalClient ?? Locator.Current.GetService <ITerminalClient>(); }