示例#1
0
文件: OPCReader.cs 项目: eaciit/wfopc
        public void Init()
        {
            cfg             = new OPCAgentConfig();
            cfg.Host        = Common.GetConfig("host");
            cfg.OPCName     = Common.GetConfig("opcname");
            cfg.Period      = Convert.ToInt32(Common.GetConfig("period"));
            cfg.AssetFolder = Common.GetConfig("assetfolder");

            ErrorTags = new List <string>();

            if (!String.IsNullOrEmpty(cfg.Host))
            {
                server = new OpcDaServer(UrlBuilder.Build(cfg.OPCName, cfg.Host));
                server.Connect();
                BuildSubcribtion(server, cfg);
            }
            else
            {
                Log.Write("Cannot find host address.", LogType.ERROR);
            }
        }
示例#2
0
文件: OPCReader.cs 项目: eaciit/wfopc
        protected 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 tagErrorFilePath = cfg.AssetFolder + "\\tags-error.txt";
                string objLine, tagLine, tagErrorLine;

                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();

                System.IO.StreamReader fileTagError = new System.IO.StreamReader(tagErrorFilePath);
                while ((tagErrorLine = fileTagError.ReadLine()) != null)
                {
                    tagErrorLine = tagErrorLine.Trim();
                    if (!tagErrorLine.StartsWith("//"))
                    {
                        tags.Add(tagErrorLine);
                        ErrorTags.Add(tagErrorLine);
                    }
                }
                fileTagError.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());
                    string     msg = "Subscribe for " + obj;
                    //Log.Write(msg, LogType.SUBSCRIBE);
                }
            }
            catch (Exception exc)
            {
                string err = "Error: " + exc.Message;
                Log.Write(err, LogType.ERROR);
            }

            return(groups);
        }