AnsweredAssumed Answered

Need to interface with MatLab

Question asked by mdspath on Feb 5, 2015
Latest reply on Feb 6, 2015 by bshang

Hello:

We built a DLL that can

*connect with our PI server

*establish collection of keys (PIPoint) and values (AFValues)

*create a PiPointList

* calls the method InterpolatedValues of the PIPointList class


I need to have a MatLab function read that data that is returned IEnumerable<AFValues>.


An 2D array of doubles for now would be good. Conceptually, the AFValues struct needs to be broken down into this return array.


Any feedback is welcomed.


code example:

//*********************************************************************

        public IEnumerable<AFValues> PIFunction()

        {

             //Connect to a PI Server

            PIServers pIServers = new PIServers();

           

            foreach (var server in pIServers)

            {

                Console.WriteLine("Server: {0}", server.Name);

            }

           

            PIServer piServ = pIServers.DefaultPIServer;

          //  Console.WriteLine("Default Server: {0}", piServ.Name);

           

            piServ.Connect();

         

            PIPointList ptList = new PIPointList();

           

            AFTimeRange timeRange = new AFTimeRange("04-Feb-2015 13:09:40", "05-Feb-2015 13:09:40");

           

            AFTimeSpan timeInterval = new AFTimeSpan(0,0,0,0,0,5,0);

 

             PIPagingConfiguration config = new PIPagingConfiguration(PIPageType.EventCount, 100);


            // establish collection of keys (PIPoint) and values (AFValues)

            Dictionary<PIPoint, AFValues> resultsMap = new Dictionary<PIPoint, AFValues>();

            string[] tagName = { "arDateTime", "vessel1.dSimCO2", "vessel1.AgitatorRPM", "BA:Active.1" };

 

            foreach (string tag in tagName)

            {

                ptList.Add(PIPoint.FindPIPoint(piServ, tag));

            }

 

            IEnumerable<AFValues> results = ptList.InterpolatedValues(timeRange, timeInterval, null, true, config);

            int iNumResult = 0;

            foreach (AFValues result in results)

            {

                resultsMap[result.PIPoint] = result;

                iNumResult = result.Count();

            }

            Console.WriteLine("TimeStamp \t\t{0} \t{1} \t{2} \t{3}", tagName);

            for (int i = 0; i < iNumResult-1; i++)

            {

                Console.WriteLine("{0} \t{1} \t{2} \t{3} \t{4}",

                    resultsMap[ptList[0]][i].Timestamp, resultsMap[ptList[0]][i].Value, resultsMap[ptList[1]][i].Value, resultsMap[ptList[2]][i].Value, resultsMap[ptList[3]][i].Value);

            }

 

            Console.WriteLine("\nFinished. press Enter.");

            //Console.ReadLine(); 

 

           piServ.Disconnect();

           

            return results;

        }

 

thanks.

Outcomes