4 Replies Latest reply on Sep 17, 2013 7:37 PM by Marcos Vainer Loeff

    Data transfer to/from PI SDK and Matlab

    rehanna

      Hello, I have limited experience with the PI SDK and am new to vCampus so I apologize if I've posted in an inappropriate location or if my question has been answered in a different thread.  

       

      I am trying to obtain data from the PI SDK using Matlab and have written the following code: 

       
      sdk = NET.addAssembly('OSIsoft.PISDK');
      sdkcommon = NET.addAssembly('OSIsoft.PISDKCommon');
      sdktimeserver = NET.addAssembly('OSIsoft.PITimeServer');
      pi_sdk =  PISDK.PISDKClass();
      time_start = System.String('15-Sep-2013 11:00:00');
      time_end = System.String('15-Sep-2013 11:01:00');
      PI_DATA.PV = PI_POINT.PV.Data.RecordedValues(time_start,time_end);
      

      The PI tag from which I am grabbing records 1 sec data, but for a given minute generally 30-37 data are returned, not 60.  Similarly, with a separate PI tag that records 1 min data, 2-6 data are returned, not 1.  Any insight into the nature of these data grabs or into better use of the start/end times would be helpful as I'm unfamiliar with the way the data is stored in PI.

       

      Thank you,

       

      Ryan

       

       

       

       

       

       

        • Re: Data transfer to/from PI SDK and Matlab
          Marcos Vainer Loeff

          Hello Ryan,

           

          Could you please check how many recorded values you can see for the same tag and choosing the same period of time using PI SMT? Do the values received in Matlab are different from the ones shown in PI SMT?

           

          Besides that, please check the exception and compression settings of this tag. When a tag is configured for 1 second scan, it doesn’t mean that is has to record 60 values per minute due to compression and exception tests.

           

          Hope this helps!!

            • Re: Data transfer to/from PI SDK and Matlab
              hanyong

              Hi Ryan,

               

              As Marcos mentioned, part of the process of collecting data from data sources into the PI Server, we apply exception and compression testing to the data. The objective of doing this is to remove noise in the data collected and also to minimize the storage required without losing the accurancy of the data. As a result of that, even if the interface is collecting or polling data from the data sources every second, the number of data archived may not be at every second interval. If getting data with other clients give you the same data set, then we can be sure that this is caused by exception and compression, hence Marcos' suggestion to look at the data from PI SMT. If you would like to know more about these, you can take a look at the PI System Basic training videos on YouTube. This is a playlist with information about the basics of PI System, including the exception and compression testing explanation.

               

              Another thing to consider is the nature of data collection. Some data sources supports getting data by exception or get updates only. One example is PI OPC interface supports advise mode and polling mode. So in this case, it is also possible that data is not provided by the data source to our interface at regular intervals.

               

              If you do not have control over the data collection process but still would like to have data at 1 second interval into Matlab. One way to go about this is to use the PIData.InterpolatedValues or IPIData2.InterpolatedValues2 methods. These method can sample for data based on the archived data in the PI Server for a number of intervals or a specified interval duration respectively. We probably do not have code snippets for using these methods in Matlab, but you can find code snippets in other languages like: http://vcampus.osisoft.com/discussion_hall/development_with_osisoft_sdks/f/8/p/2203/11737.aspx#11737

              • Re: Data transfer to/from PI SDK and Matlab
                rehanna

                Hi Marcos,

                 

                Thanks for the response.  Using the PI SMT, I see the same number of recorded values minus two (I don't see in the SMT the endpoints of the data retrieved using Matlab).  As you mentioned, it appears <60 values per min are recorded due to compression/exception.  Ultimately I am interested in a single datum, the 1 min avg over the minute interval.  Though I was expecting 60 1 sec data, ultimately I was going to average those 60 points.  I would be equally happy If there was a function call in Matlab to calculate the mean of the data stored for a PI tag (no matter the number of data) in that 1 min interval.

                 

                Ryan

                  • Re: Data transfer to/from PI SDK and Matlab
                    Marcos Vainer Loeff

                    Hello Ryan,

                     

                    There are two options to solve your problem:

                     

                    1)Instead of using the RecordedValues method, you should switch it to  PIData.InterpolatedValues or IPIData2.InterpolatedValues2 as Han Yong has suggested. Below you can find the syntax of both methods:

                     

                    PIData.InterpolatedValues

                     

                    object.InterpolatedValues StartTime, EndTime, nValues, [FilterExp], [ShowFiltered], [AsynchStatus]

                     

                    IPIData2.InterpolatedValues2

                     

                    object.InterpolatedValues2 StartTime, EndTime, SampleInterval, [FilterExp], [ShowFiltered], [AsynchStatus]

                     

                    Although InterpolatedValues2 seems to be more appropriate due to the fact in order to achieve what you want to do you only need to set up SampleInterval=”1s”, this method is available from the IPIData2 interface and not from the PI Data object.

                     

                    I am not sure how to manipulate C# objects on Matlab. That is why, I suggest using the InterpolatedValues and then you need to choose nValues that will result a sample interval of 1 second.

                     

                    Please try something like this:

                     

                     

                     
                    time_start = System.String('15-Sep-2013 11:00:00');
                    time_end = System.String('15-Sep-2013 11:01:00');
                    nValues=61;
                    PI_DATA.PV = PI_POINT.PV.Data.InterpolatedValues(time_start,time_end,nValues);
                    

                     

                     

                    2)The second option is to continue using the RecordedValues method and develop a Matlab function that will calculate interpolated values given a start time, end time and a sample interval. However, I suggest trying the first option first because it might work with only 3/4 lines of code.

                     

                     

                     

                    Hope this helps!