Пример #1
0
        private void BRMG_Click(object sender, EventArgs e)
        {
            if (RMG == null && Прибор != null)
            {
                Inv_OutMess("Уже подключен не EC605", "");
                return;
            }

            if (RMG == null)
            {
                if (int.TryParse(TBPort.Text, out iPort))
                {
                    Прибор = RMG = new CRMG(this);
                    Прибор.InitIPport(CBIP.Text, iPort);
                }
                else
                {
                    Inv_OutMess("Неправильный номер порта: [" + TBPort.Text + "]", "");
                    return;
                }
            }
            if (ConnDev(BRMG, "RMG on", "RMG off") == false)
            {
                RMG.Close();
                Прибор = RMG = null;
            }
        }
Пример #2
0
        public CInovance_TCP(int idNo = 0, string name = "Inovance_TCP")
        {
            this._idNo = idNo;

            this._name = name;

            com = new CClientTCP(_idNo, _name, EDataType.HEX格式);
        }
Пример #3
0
        public CLECTOR620(int idNo = 0, string name = "LECTOR620")
        {
            this._idNo = idNo;

            this._name = name;

            com = new CClientTCP(idNo, name, EDataType.ASCII格式);
        }
Пример #4
0
        public CDCR202(int idNo = 0, string name = "DCR202")
        {
            this._idNo = idNo;

            this._name = name;

            com = new CClientTCP(idNo, name, EDataType.ASCII格式);
        }
Пример #5
0
        /// <summary>
        /// 连接TCP服务端
        /// </summary>
        /// <returns></returns>
        private bool OpenTCP()
        {
            try
            {
                string er = string.Empty;

                if (_devTCP == null)
                {
                    _devTCP           = new CClientTCP(0, "Client", EDataType.ASCII格式);
                    _devTCP.OnConed  += new CClientTCP.EventOnConHander(OnClientTcpCon);
                    _devTCP.OnRecved += new CClientTCP.EventOnRecvHandler(OnClientTcpRecv);
                    _devTCP.open(txtClientIP.Text, out er, txtClientPort.Text);

                    Stopwatch watcher = new Stopwatch();

                    watcher.Start();

                    while (true)
                    {
                        Application.DoEvents();

                        if (_devTCP.conStatus)
                        {
                            break;
                        }
                        if (watcher.ElapsedMilliseconds > 2000)
                        {
                            break;
                        }
                    }

                    watcher.Stop();

                    if (!_devTCP.conStatus)
                    {
                        _devTCP.OnConed  -= new CClientTCP.EventOnConHander(OnClientTcpCon);
                        _devTCP.OnRecved -= new CClientTCP.EventOnRecvHandler(OnClientTcpRecv);
                        _devTCP.close();
                        _devTCP = null;
                        clientLog.Log("无法连接测试服务端[" + txtClientIP.Text + ":" +
                                      txtClientPort.Text + "]", udcRunLog.ELog.NG);
                        return(false);
                    }

                    clientLog.Log("正常连接测试服务端[" + txtClientIP.Text + ":" +
                                  txtClientPort.Text + "]", udcRunLog.ELog.Action);
                }

                return(true);
            }
            catch (Exception ex)
            {
                clientLog.Log(ex.ToString(), udcRunLog.ELog.Err);
                return(false);
            }
        }
Пример #6
0
        private bool OpenClientTcp(string ip, string port, out string er)
        {
            try
            {
                clientTcp           = new CClientTCP(0, "Socket客户端", EDataType.ASCII格式);
                clientTcp.OnConed  += new CClientTCP.EventOnConHander(OnTcpCon);
                clientTcp.OnRecved += new CClientTCP.EventOnRecvHandler(OnTcpRecv);
                clientTcp.open(ip, out er, port);

                Stopwatch watcher = new Stopwatch();

                watcher.Start();

                while (true)
                {
                    Application.DoEvents();

                    if (clientTcp.conStatus)
                    {
                        break;
                    }
                    if (watcher.ElapsedMilliseconds > 2000)
                    {
                        break;
                    }
                }

                watcher.Stop();

                if (!clientTcp.conStatus)
                {
                    er = "无法连接测试服务端[" + ip.ToString() + ":" + port + "]";
                    clientTcp.OnConed  -= new CClientTCP.EventOnConHander(OnTcpCon);
                    clientTcp.OnRecved -= new CClientTCP.EventOnRecvHandler(OnTcpRecv);
                    clientTcp.close();
                    clientTcp = null;
                    clientLog.Log(er, udcRunLog.ELog.NG);
                    return(false);
                }

                er = "正常连接测试服务端[" + ip.ToString() + ":" + port + "]";

                clientLog.Log(er, udcRunLog.ELog.Action);

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                clientLog.Log(er, udcRunLog.ELog.Err);
                return(false);
            }
        }
Пример #7
0
 private void CloseClientTcp()
 {
     try
     {
         if (clientTcp != null)
         {
             clientTcp.OnConed  -= new CClientTCP.EventOnConHander(OnTcpCon);
             clientTcp.OnRecved -= new CClientTCP.EventOnRecvHandler(OnTcpRecv);
             clientTcp.close();
             clientTcp = null;
             clientLog.Log("断开连接测试服务端[" + txtSerIP.Text + ":" + txtSerPort.Text + "]", udcRunLog.ELog.NG);
         }
     }
     catch (Exception ex)
     {
         clientLog.Log(ex.ToString(), udcRunLog.ELog.Err);
     }
 }
Пример #8
0
 /// <summary>
 /// 断开TCP连接
 /// </summary>
 private void CloseTCP()
 {
     try
     {
         if (_devTCP != null)
         {
             _devTCP.OnConed  -= new CClientTCP.EventOnConHander(OnClientTcpCon);
             _devTCP.OnRecved -= new CClientTCP.EventOnRecvHandler(OnClientTcpRecv);
             _devTCP.close();
             _devTCP = null;
             clientLog.Log("断开连接测试服务端[" + txtClientIP.Text + ":" +
                           txtClientPort.Text + "]", udcRunLog.ELog.Content);
         }
     }
     catch (Exception ex)
     {
         clientLog.Log(ex.ToString(), udcRunLog.ELog.Err);
     }
 }
Пример #9
0
        //___________________________________________________________________________
        private void BConnect_Click(object sender, EventArgs e)
        {
            if (Прибор == null)
            {
                if (int.TryParse(TBPort.Text, out iPort))
                {
                    Прибор = new CIRGA2(this);
                }
                else
                {
                    Inv_OutMess("Неправильный номер порта: [" + TBPort.Text + "]", "");
                    return;
                }
            }
            Properties.Settings.Default.asPort = TBPort.Text;
            Properties.Settings.Default.asIP   = CBIP.Text;
            if (CBIP.FindString(CBIP.Text) < 0)
            {
                CBIP.Items.Add(CBIP.Text);
                Properties.Settings.Default.asIPs += ";" + CBIP.Text;
            }
            if (Properties.Settings.Default.asCommand.Contains(TBCommand.Text) == false)
            {
                Properties.Settings.Default.asCommand = TBCommand.Text;
            }
            Прибор.InitIPport(CBIP.Text, iPort);

            ThreadPool.QueueUserWorkItem((Object oInfo) =>
            {
                Inv_OutMess($"Подключение к {GetTextCB (CBIP)} ...", "");
                if (ConnDev(oInfo) == false)
                {
                    Прибор = null;
                }
            }
                                         , sender);
        }
Пример #10
0
 public CLsis_TCP(int idNo = 0, string name = "Lsis_TCP")
 {
     this._idNo = idNo;
     this._name = name;
     com        = new CClientTCP(_idNo, _name, EDataType.ASCII格式);
 }
Пример #11
0
 public CFX5U_TCP(int idNo = 0, string name = "Mitsubishi_FX5U")
 {
     this._idNo = idNo;
     this._name = name;
     com        = new CClientTCP(_idNo, _name, EDataType.HEX格式);
 }
Пример #12
0
 public COmron_TCP(int idNo = 0, string name = "OmronFins_TCP")
 {
     this._idNo = idNo;
     this._name = name;
     com        = new CClientTCP(_idNo, _name, EDataType.HEX格式);
 }