예제 #1
0
 public bool Connect(string strServer, int nPort)
 {
     try
     {
         if (System.String.IsNullOrEmpty(strServer) || nPort == 0)
         {
             return(false);
         }
         IPEndPoint iep = new IPEndPoint(IPAddress.Parse(strServer), nPort);
         cliSocket = TimeOutSocket.Connect(iep, TimeOut);
         if (cliSocket != null)
         {
             // RaiseNotifyEvent("Connect", " 连接成功!");
             g_brun    = true;
             ComThread = new Thread(new ThreadStart(Recv));
             ComThread.Start();
             return(true);
         }
         else
         {
             RaiseNotifyEvent("Break", " 连接失败!");
             return(false);
         }
     }
     catch (SocketException ex)
     {
         RaiseNotifyEvent("Break", " 连接失败,异常:" + ex.Message);
         return(false);
     }
 }
예제 #2
0
        public bool Connect(string strServer, int nPort)
        {
            try
            {
                if (System.String.IsNullOrEmpty(strServer) || nPort == 0)
                {
                    return(false);
                }
                IPEndPoint iep = new IPEndPoint(IPAddress.Parse(strServer), nPort);
                cliSocket = TimeOutSocket.Connect(iep, TimeOut);
                if (cliSocket != null)
                {
                    //PlcNotify("Connect", " 连接成功!");
                    g_brun = true;

                    //Send(new byte[] { 0x53, 0x35, 0x10, 0x01, 0x03, 0x03, 0x03, 0x08, 0x01, 0x0B, 0x00, 0x00, 0x00, 0x14, 0xFF, 0x02 });
                    ComThread = new Thread(new ThreadStart(Recv));
                    ComThread.Start();
                    return(true);
                }
                else
                {
                    PlcNotify("Break", " 连接失败!");
                    return(false);
                }
            }
            catch (SocketException ex)
            {
                PlcNotify("Break", " 连接失败,异常:" + ex.Message);
                return(false);
            }
        }
예제 #3
0
 public bool Connect_2001(string strServer, int nPort)
 {
     try
     {
         if (System.String.IsNullOrEmpty(strServer) || nPort == 0)
         {
             return(false);
         }
         IPEndPoint iep = new IPEndPoint(IPAddress.Parse(strServer), nPort);
         cliSocket = TimeOutSocket.Connect(iep, TimeOut);
         if (cliSocket != null)
         {
             return(true);
         }
         else
         {
             PLCNotifyEvent("Break", " 连接失败!");
             return(false);
         }
     }
     catch (SocketException ex)
     {
         PLCNotifyEvent("Break", " 连接失败,异常:" + ex.Message);
         return(false);
     }
 }
예제 #4
0
        public bool CheckConnect(string strServer, int nPort)
        {
            IPEndPoint iep = new IPEndPoint(IPAddress.Parse(strServer), nPort);

            cliSocket = TimeOutSocket.Connect(iep, TimeOut);
            if (cliSocket != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
 public bool Connect_SP(string strServer, int nPort)
 {
     try
     {
         if (System.String.IsNullOrEmpty(strServer) || nPort == 0)
         {
             return(false);
         }
         IPEndPoint iep = new IPEndPoint(IPAddress.Parse(strServer), nPort);
         cliSocket = TimeOutSocket.Connect(iep, TimeOut);
         if (cliSocket != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (SocketException ex)
     {
         return(false);
     }
 }