Ejemplo n.º 1
0
        public bool Connect(string strServer, string port)
        {
            try
            {
                if (string.IsNullOrEmpty(strServer) || port == "0")
                {
                    return(false);
                }
                PlcTcpClient plink = new PlcTcpClient(strServer, int.Parse(port));
                int          n     = plink.ConnectPLC();

                if (n == 0)
                {
                    NotifyEvent?.Invoke("Connect", "连接成功!");
                    g_brun  = true;
                    ComTask = Task.Run(Rcv, CancelTS.Token);
                    return(true);
                }
                else
                {
                    NotifyEvent?.Invoke("Break", "连接失败!");
                    return(false);
                }
            }
            catch (SocketException ex)
            {
                NotifyEvent?.Invoke("Break", $"连接失败,异常:{ex.Message}");
                return(false);
            }
        }
Ejemplo n.º 2
0
 public RWLOPCServerl(string ip, int port = 102)
 {
     mPlc = new PlcTcpClient(ip, port);
 }
Ejemplo n.º 3
0
 public RWLOPCServerl(string ip)
 {
     mPLC = new PlcTcpClient(ip, 102);
 }