AnsweredAssumed Answered

FindAttributesByPath in C# Problem

Question asked by PFC5478 on Nov 8, 2016
Latest reply on Nov 14, 2016 by PFC5478

Dear all,

 

I have used PI AF SDK for around two years but only used on PI Data Archive (Namespace: Osisoft.AF.PI) but not AF Server.

 

To make myself get familiar for using PI AF SDK in AF Server, I am learning from below examples:

GitHub - osisoft/PI-AF-SDK-Basic-Samples: Self-contained and reproducible samples of basic operations using PI AF SDK.

 

I am successful to use "AFAttributeExamples\FindAttributeWalkDownExample.cs" to query the result. However,

I fail to use "AFAttributeExamples\FindAttributesByPathExample.cs" as below (<AFServer> has been replaced to the AF Server that I currently test):

 

           string processFeedRate = @"\\<AFSERVER>\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Process Feedrate";
            string waterFlow = @"\\<AFSERVER>\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Water Flow";

            AFKeyedResults<string,AFAttribute> results = AFAttribute.FindAttributesByPath(new[] { processFeedRate, waterFlow }, null);

            AFAttribute processFeedRateAttribute = results[processFeedRate];
            AFAttribute waterFlowAttribute = results[waterFlow];
            AFAttributeList attrList = new AFAttributeList(new[] { processFeedRateAttribute, waterFlowAttribute });

            // Make a bulk call to get values.
            AFValues values = attrList.GetValue();
            foreach (AFValue val in values)
            {
                Console.WriteLine("Attribute: {0}", val.Attribute);
                Console.WriteLine("Timestamp: {0}, Value: {1}", val.Timestamp, val.Value.ToString());
                Console.WriteLine();
            }     

 

Previously I doubt this is due to escape character '\' in C#. I have tried to minor modify the above source code such as replacing the backslash '\' to Unicode '\u005c'

but also fail. The error message is "Object for path....was not found".

 

My development environment is:

Visual Studio 2013 Professional Update 4

.Net Framework 4.6.2

PI AF SDK 2.8.5

PI AF Server 2015

 

All comments are welcomed!

 

Thanks and Regards,

Paul Fung

Outcomes