Ejemplo n.º 1
0
        /// <summary>
        /// Ищет OPC сервер, берет первый найденный сервер.
        /// На сервере берет первый узел. (в дереве)
        /// </summary>
        /// <returns></returns>
        public void ConfigureProcessor()
        {
            List <OpcServerDescription> servers = _opcServerManager.SelectServer();

            if (servers == null)
            {
                throw new Exception("opc servers is null");
            }

            if (!servers.Any())
            {
                throw new Exception("Не найден OPC сервер");
            }

            _opcServerDescription = servers[0];// TODO: find by name

            _opcServerManager.DoInit(_opcServerDescription);

            if (!_opcServerManager.OpcNamespacesTree.Children.Any())
            {
                throw new Exception("Не найден ни один узел OPC сервера");
            }

            _opcNode = _opcServerManager.OpcNamespacesTree.Children.First();// select firt child

            Parameters = _opcServerManager.BrowseToNodeInOpc(_opcNode.FullPath).Cast <string>().ToList();

            if (Parameters == null || Parameters.Count == 0)
            {
                throw new Exception("Не найден ни один параметр");
            }

            for (int i = 0; i < Parameters.Count; i++)
            {
                Parameters[i] = string.Format("PLC.PLC.{0}", Parameters[i]);
            }
        }
Ejemplo n.º 2
0
        public bool DoInit(OpcServerDescription opcServerDescription)
        {
            _theSrv = new OpcServer();

            OpcNamespacesTree = new TreeNode <string>(_rootname);

            // ---------------
            OpcServerConnectResult connectResult = DoConnect(opcServerDescription.ProgId);

            if (!connectResult.IsSuccess)
            {
                return(false);
            }

            OpcConnected = true;

            // add event handler for server shutdown
            _theSrv.ShutdownRequested += (e, args) =>
            {
                CallOnServerShutdown(args.shutdownReason);
            };

            // precreate the only OPC group in this example
            if (!CreateGroup())
            {
                return(false);
            }

            // browse the namespace of the OPC-server
            if (!DoBrowse())
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Ищет OPC сервер, берет первый найденный сервер.
        /// На сервере берет первый узел. (в дереве)
        /// </summary>
        /// <returns></returns>
        public void ConfigureProcessor()
        {
            List <OpcServerDescription> servers = _opcServerManager.SelectServer();

            if (servers == null)
            {
                throw new Exception("opc servers is null");
            }

            if (!servers.Any())
            {
                throw new Exception("Не найден OPC сервер");
            }

            _opcServerDescription = servers[0];// TODO: find by name

            _opcServerManager.DoInit(_opcServerDescription);

            if (!_opcServerManager.OpcNamespacesTree.Children.Any())
            {
                throw new Exception("Не найден ни один узел OPC сервера");
            }

            _opcNode1   = _opcServerManager.OpcNamespacesTree.Children.First();// select firt child
            _opcNode2   = _opcServerManager.OpcNamespacesTree.Children[1];
            Parameters1 = new List <string>();
            Parameters1 = _opcServerManager.BrowseToNodeInOpc(_opcNode1.FullPath, "Press2\tApplication\tSCADA").Cast <string>().ToList();

            Parameters2 = _opcServerManager.BrowseToNodeInOpc(_opcNode2.FullPath, "Press1\tApplication\tGVL_TO_SCADA").Cast <string>().ToList();

            Parameters3 = _opcServerManager.BrowseToNodeInOpc(_opcNode2.FullPath, "Press1\tApplication\tPVL").Cast <string>().ToList();
            Parameters4 = _opcServerManager.BrowseToNodeInOpc(_opcNode2.FullPath, "Press1\tApplication\tGVL\tPress").Cast <string>().ToList();

            //if (Parameters1 == null || Parameters1.Count == 0)
            //{
            //    throw new Exception("Не найден ни один параметр");
            //}
            if (Parameters1 != null)
            {
                for (int i = 0; i < Parameters1.Count; i++)
                {
                    Parameters1[i] = string.Format("Press2.Application.SCADA.{0}", Parameters1[i]);
                }
            }

            if (Parameters2 != null)
            {
                for (int i = 0; i < Parameters2.Count; i++)
                {
                    Parameters2[i] = string.Format("Press1.Application.GVL_TO_SCADA.{0}", Parameters2[i]);
                }

                foreach (string p in Parameters2)
                {
                    Parameters1.Add(p);
                }
            }

            if (Parameters3 != null)
            {
                foreach (string p in Parameters3.Where(p => OpcConsts.PositionSP1.Contains(p) || OpcConsts.PowerSP1.Contains(p) || OpcConsts.SpeedSP1.Contains(p)))
                {
                    Parameters1.Add(string.Format("Press1.Application.PVL.{0}", p));
                }
            }

            if (Parameters4 != null)
            {
                foreach (string p in Parameters4.Where(p => OpcConsts.Run1.Contains(p)))
                {
                    Parameters1.Add(string.Format("Press1.Application.GVL.Press.{0}", p));
                }
            }
        }