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); } } }
public static SerialParams GetDefaultSerialParams(string comPort) { SerialParams sp = new SerialParams(); sp.PortName = comPort; sp.BaudRate = 115200; sp.DataBits = 8; sp.Parity = Parity.None; sp.StopBits = StopBits.One; sp.Handshake = Handshake.None; return(sp); }
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); }
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 SerialClient(SerialParams sp) { _mSerialParams = sp; }