예제 #1
0
        public void ConnectToServer()
        {
            try
            {
                //LOCAL OPC CONNECTION kepware
                //url = new Opc.URL("opcda://PCNAME/Kepware.KEPServerEX.V6");
                //LOCAL OPC CONNECTION RSLinx
                //url = new Opc.URL("opcda://PCNAME/RSLinx OPC Server");

                //REMOTE OPC CONNECTION WHEN USING opcexpert tunneling
                url = new Opc.URL("opcda://PCNAME/RSLinx Remote OPC Server.REMOTEPCNAME");

                //REMOTE RSLinx OPC
                //this requires DCOM setup
                //url = new Opc.URL("opcda://PCNAME/RSLinx Remote OPC Server");

                server = new Opc.Da.Server(fact, url);
                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential();
                Opc.ConnectData connecteddata = new Opc.ConnectData(networkCredential);
                server.Connect(url, connecteddata);
                groupState             = new Opc.Da.SubscriptionState();
                groupState.Name        = "Group";
                groupState.UpdateRate  = 1;                                                 // this isthe time between every reads from OPC server
                groupState.Active      = true;                                              //this must be true if you the group has to read value
                groupRead              = (Opc.Da.Subscription)server.CreateSubscription(groupState);
                groupRead.DataChanged += new Opc.Da.DataChangedEventHandler(UpdateTagData); //callback when the data are readed

                Opc.Da.Item[] items_read = groupRead.AddItems(createSomeTags());
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }
예제 #2
0
파일: Server.cs 프로젝트: ZSYMAX/OpcNetApi
 // Token: 0x06000022 RID: 34 RVA: 0x00002BA4 File Offset: 0x00001BA4
 public virtual void Connect(URL url, ConnectData connectData)
 {
     if (url == null)
     {
         throw new ArgumentNullException("url");
     }
     if (this.m_server != null)
     {
         throw new AlreadyConnectedException();
     }
     this.SetUrl(url);
     try
     {
         this.m_server      = this.m_factory.CreateInstance(url, connectData);
         this.m_connectData = connectData;
         this.GetSupportedLocales();
         this.SetLocale(this.m_locale);
     }
     catch (Exception ex)
     {
         if (this.m_server != null)
         {
             try
             {
                 this.Disconnect();
             }
             catch
             {
             }
         }
         throw ex;
     }
 }
예제 #3
0
        public void ConnectToServer()
        {
            try
            {
                url = new Opc.URL("opcda://IAPENG1/RSLinx OPC Server");
                //server = new Opc.Da.Server(fact, null);
                server = new Opc.Da.Server(fact, url);
                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential();
                Opc.ConnectData connecteddata = new Opc.ConnectData(networkCredential);
                server.Connect(url, connecteddata);
                groupState             = new Opc.Da.SubscriptionState();
                groupState.Name        = "Group";
                groupState.UpdateRate  = 1000;                                              // this isthe time between every reads from OPC server
                groupState.Active      = true;                                              //this must be true if you the group has to read value
                groupRead              = (Opc.Da.Subscription)server.CreateSubscription(groupState);
                groupRead.DataChanged += new Opc.Da.DataChangedEventHandler(UpdateTagData); //callback when the data are readed

                if (items[0] == null)
                {
                    items[0] = new Opc.Da.Item();
                    items[1] = new Opc.Da.Item();
                    items[2] = new Opc.Da.Item();
                    items[3] = new Opc.Da.Item();
                    items[4] = new Opc.Da.Item();
                    items[5] = new Opc.Da.Item();
                    items[6] = new Opc.Da.Item();
                    items[7] = new Opc.Da.Item();
                }

                items[0].ItemName = "[PLC2]LocalDateTime[0]";
                items[1].ItemName = "[PLC2]LocalDateTime[1]";
                items[2].ItemName = "[PLC2]LocalDateTime[2]";
                items[3].ItemName = "[PLC2]LocalDateTime[3]";
                items[4].ItemName = "[PLC2]LocalDateTime[4]";
                items[5].ItemName = "[PLC2]LocalDateTime[5]";
                items[6].ItemName = "[PLC2]LocalDateTime[6]";
                items[7].ItemName = "[PLC2]LocalDateTime";

                items = groupRead.AddItems(items);

                // Create a write group
                groupStateWrite        = new Opc.Da.SubscriptionState();
                groupStateWrite.Name   = "Group Write";
                groupStateWrite.Active = false;//not needed to read if you want to write only
                groupWrite             = (Opc.Da.Subscription)server.CreateSubscription(groupStateWrite);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// Connect/Disconnect to the server.
        /// </summary>
        /// <returns></returns>
        private bool Connect()
        {
            // Connect server
            var url = new Opc.URL(OpcConnectionString);

            // Create an unconnected server object.
            OpcServer = GetServerForUrl(url);
            if (OpcServer == null)
            {
                return(false);
            }

            // Invoke the connect server callback.
            try
            {
                var connectData = new Opc.ConnectData(Credential, null);
                OpcServer.Connect(connectData);

                var opcDaSrerver = OpcServer as Opc.Da.Server;

                if (opcDaSrerver == null)
                {
                    return(false);
                }

                VendorInfo  = opcDaSrerver.GetStatus().VendorInfo;
                VersionInfo = opcDaSrerver.GetStatus().ProductVersion;
                StatusInfo  = opcDaSrerver.GetStatus().StatusInfo;

                var state = new Opc.Da.SubscriptionState
                {
                    ClientHandle = Guid.NewGuid().ToString(),
                    ServerHandle = null,
                    //Name = "DEFAULT",
                    Active     = false,
                    UpdateRate = 1000,
                    KeepAlive  = 0,
                    //Deadband = 0,
                    //Locale = null
                };
                Subscription = (Subscription)opcDaSrerver.CreateSubscription(state);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(true);
        }
예제 #5
0
        //======================================================================
        // IFactory

        /// <summary>
        /// Creates a new instance of the server.
        /// </summary>
        public virtual IServer CreateInstance(URL url, ConnectData connectData)
        {
            IServer server = null;

            // instantiate the object locally.
            if (!m_useRemoting)
            {
                server = (IServer)Activator.CreateInstance(m_systemType, new object[] { url, connectData });
            }

            // instantiate the object remotely using .NET remoting.
            else
            {
                server = (IServer)Activator.GetObject(m_systemType, url.ToString());
            }

            return(server);
        }
예제 #6
0
파일: Form1.cs 프로젝트: simple555a/OPC-2
        public Form1()
        {
            InitializeComponent();
            OpcCom.ServerEnumerator se = new ServerEnumerator();
            Opc.Server[]            Servers;
            String sErrFunc = "";

            Opc.ConnectData cd = new Opc.ConnectData(new System.Net.NetworkCredential());
            sErrFunc = "GetAvailableServers";
            Servers  = se.GetAvailableServers(Opc.Specification.COM_DA_20, "localhost", cd);
            Console.WriteLine(Servers[1].Name.ToString());


            Opc.URL url = new Opc.URL("opcda://localhost/" + Servers[0].Name);

            OpcCom.Factory fact = new OpcCom.Factory();
            server = new Opc.Da.Server(fact, null);
            server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
        }
예제 #7
0
파일: Factory.cs 프로젝트: ZSYMAX/OpcNetApi
        // Token: 0x06000713 RID: 1811 RVA: 0x00011858 File Offset: 0x00010858
        public virtual IServer CreateInstance(URL url, ConnectData connectData)
        {
            IServer result;

            if (!this.m_useRemoting)
            {
                result = (IServer)Activator.CreateInstance(this.m_systemType, new object[]
                {
                    url,
                    connectData
                });
            }
            else
            {
                //result = (IServer)Activator.GetObject(this.m_systemType, url.ToString());
                result = null;
            }
            return(result);
        }
예제 #8
0
        /// <summary>
        /// Establishes a physical connection to the remote server identified by a URL.
        /// </summary>
        /// <param name="url">The network address of the remote server.</param>
        /// <param name="connectData">Any protocol configuration or user authenication information.</param>
        public virtual void Connect(URL url, ConnectData connectData)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (m_server != null)
            {
                throw new AlreadyConnectedException();
            }

            // save url.
            SetUrl(url);

            try
            {
                // instantiate the server object.
                m_server = m_factory.CreateInstance(url, connectData);

                // save the connect data.
                m_connectData = connectData;

                // cache the supported locales.
                GetSupportedLocales();

                // update the default locale.
                SetLocale(m_locale);
            }
            catch (Exception e)
            {
                if (m_server != null)
                {
                    try   { Disconnect(); }
                    catch {}
                }

                throw e;
            }
        }
예제 #9
0
        public void ConnectToServer()
        {
            try
            {
                //url = new Opc.URL("opcda://MUHUMTHA/Kepware.KEPServerEX.V6");
                //url = new Opc.URL("opcda://IAPENG1/RSLinx OPC Server");
                //REMOTE OPC CONNECTION
                url    = new Opc.URL("opcda://MUHUMTHA/RSLinx OPC Server.MUHUNTHANPC");
                server = new Opc.Da.Server(fact, url);
                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential();
                Opc.ConnectData connecteddata = new Opc.ConnectData(networkCredential);
                server.Connect(url, connecteddata);
                groupState             = new Opc.Da.SubscriptionState();
                groupState.Name        = "Group";
                groupState.UpdateRate  = 1;                                                 // this isthe time between every reads from OPC server
                groupState.Active      = true;                                              //this must be true if you the group has to read value
                groupRead              = (Opc.Da.Subscription)server.CreateSubscription(groupState);
                groupRead.DataChanged += new Opc.Da.DataChangedEventHandler(UpdateTagData); //callback when the data are readed
                //Opc.Da.Item[] items_read = groupRead.AddItems(createSomeTags());
                Opc.Da.Item[] items_read = groupRead.AddItems(createSomeTags());

                // Create a write group
                //groupStateWrite = new Opc.Da.SubscriptionState();
                //groupStateWrite.Name = "Group_Write";
                //groupStateWrite.UpdateRate = 1000;
                //groupStateWrite.Active = false;//not needed to read if you want to write only
                //groupWrite = (Opc.Da.Subscription)server.CreateSubscription(groupStateWrite);
                //groupWrite.DataChanged += new Opc.Da.DataChangedEventHandler(ReadCompleted);

                Global.flag1 = true;
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }
예제 #10
0
파일: Server.cs 프로젝트: ZSYMAX/OpcNetApi
 // Token: 0x06000021 RID: 33 RVA: 0x00002B93 File Offset: 0x00001B93
 public virtual void Connect(ConnectData connectData)
 {
     this.Connect(this.m_url, connectData);
 }
예제 #11
0
 /// <summary>
 /// Establishes a physical connection to the remote server.
 /// </summary>
 /// <param name="connectData">Any protocol configuration or user authenication information.</param>
 public virtual void Connect(ConnectData connectData)
 {
     Connect(m_url, connectData);
 }