Beispiel #1
0
        private void Reconnect()
        {
            bool ping = this.Ping();

            if (ping)
            {
                if (ping)
                {
                    if (omronPlc.Connect())
                    {
                        ConnectionStatus = ConnectionStatusEnum.CONNECTED;
                        AutoReconnectAfterConnectionLostCounter = 0;
                    }
                }
            }
        }
Beispiel #2
0
        //---------------------------------------------------------------------------
        public bool fn_Connect(string strIp, int nPort)
        {
            try
            {
                if (_bConnect)
                {
                    return(false);
                }

                bool rtn = false;

                m_bDrngCon = true;

                // Set Param
                plc.fn_SetParam(strIp, nPort);

                // connection
                rtn = plc.Connect();

                m_bDrngCon = false;

                return(rtn);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                m_bDrngCon = false;
                return(false);
            }
        }
Beispiel #3
0
        private bool tryAndConnect()
        {
            Func <bool> testDataRead = (() =>
            {
                try {
                    if (omronPlc.finsConnectionDataRead(0))
                    {
                        return(true);
                    }
                }
                catch (Exception e) { return(false); }
                return(false);
            });
            Func <bool> testNewConnect = (() =>
            {
                try
                {
                    omronPlc = new OmronPLC(mcOMRON.TransportType.Tcp);
                    tcpCommand = ((mcOMRON.tcpFINSCommand)omronPlc.FinsCommand);
                    tcpCommand.SetTCPParams(ip, port);
                    if (omronPlc.Connect())   //why exception
                    //omronPlc.Close();
                    {
                        return(true);
                    }
                }
                catch (Exception e) { return(false); }
                return(false);
            });

            if (testDataRead())
            {
                return(true);
            }
            else if (testNewConnect())
            {
                return(true);
            }
            return(false);
        }