Exemple #1
0
        public static List <OpcDaGroup> BuildSubcribtion(OpcDaServer server, OPCAgentConfig cfg)
        {
            List <OpcDaGroup> groups = new List <OpcDaGroup>();

            try
            {
                string objectFilePath = cfg.AssetFolder + "\\objects.txt";
                string tagFilePath = cfg.AssetFolder + "\\tags.txt";
                string objLine, tagLine;

                List <String> objs = new List <string>();

                System.IO.StreamReader fileObj = new System.IO.StreamReader(objectFilePath);
                while ((objLine = fileObj.ReadLine()) != null)
                {
                    objLine = objLine.Trim();
                    if (!objLine.StartsWith("//"))
                    {
                        objs.Add(objLine);
                    }
                }
                fileObj.Close();

                List <String>          tags    = new List <string>();
                System.IO.StreamReader fileTag = new System.IO.StreamReader(tagFilePath);
                while ((tagLine = fileTag.ReadLine()) != null)
                {
                    tagLine = tagLine.Trim();
                    if (!tagLine.StartsWith("//"))
                    {
                        tags.Add(tagLine);
                    }
                }
                fileTag.Close();

                foreach (String obj in objs)
                {
                    List <string> objtags = new List <string>();
                    foreach (string tag in tags)
                    {
                        String objTag = String.Concat(obj, ".", tag);
                        objtags.Add(objTag);
                    }
                    OpcDaGroup g = Subscribe(obj, server, objtags.ToArray());
                    Console.WriteLine("Subscribe for " + obj);
                }
            }catch (Exception exc)
            {
                Console.WriteLine("Error: " + exc.Message);
            }

            return(groups);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            cfg             = new OPCAgentConfig();
            cfg.Host        = ConfigurationManager.AppSettings["host"];
            cfg.OPCName     = ConfigurationManager.AppSettings["opcname"];
            cfg.Period      = Convert.ToInt32(ConfigurationManager.AppSettings["period"]);
            cfg.AssetFolder = ConfigurationManager.AppSettings["assetfolder"];

            var server = new OpcDaServer(UrlBuilder.Build(cfg.OPCName, cfg.Host));

            server.Connect();
            BuildSubcribtion(server, cfg);
            System.Threading.Thread.Sleep(cfg.Period * 10);
            server.Disconnect();
            Console.WriteLine("Press any key ....");
            Console.ReadLine();
        }