Exemplo n.º 1
0
        /// <summary>
        /// 打开串口
        /// </summary>
        /// <param name="comName">192.168.1.125</param>
        /// <param name="setting">10001</param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool Open(string comName, out string er, string setting = "10001", bool recvThreshold = false)
        {
            er = string.Empty;

            try
            {
                if (_com != null)
                {
                    _com.close();
                    _com = null;
                }

                _com = new CTelnet(idNo, name, EDataType.ASCII格式);

                if (!_com.open(comName, out er, setting))
                {
                    _com = null;
                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                er = e.ToString();
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 关闭串口
 /// </summary>
 /// <returns></returns>
 public void Close()
 {
     if (_com != null)
     {
         _com.close();
         _com = null;
     }
 }
Exemplo n.º 3
0
        private void btnCon_Click(object sender, EventArgs e)
        {
            try
            {
                btnCon.Enabled = false;

                SaveIniFile();

                string er = string.Empty;

                if (_client == null)
                {
                    _client = new CTelnet();
                    if (!_client.Connect(_ip, _port, out er))
                    {
                        ShowStatus(er, true);
                        _client = null;
                        return;
                    }
                    ShowStatus("连接[" + _ip + ":" + _port.ToString() + "]正常", false);
                    btnCon.Text        = "断开";
                    btnSendCmd.Enabled = true;
                    btnCheck.Enabled   = true;
                    btnPower.Enabled   = true;
                }
                else
                {
                    _client.Close();
                    _client = null;
                    ShowStatus("断开[" + _ip + ":" + _port.ToString() + "]连接", false);
                    btnCon.Text        = "连接";
                    btnSendCmd.Enabled = false;
                    btnCheck.Enabled   = false;
                    btnPower.Enabled   = false;
                }
            }
            catch (Exception ex)
            {
                ShowStatus(ex.ToString(), true);
                _client = null;
            }
            finally
            {
                btnCon.Enabled = true;
            }
        }