12 Replies Latest reply on Jan 20, 2017 6:22 PM by jmarriott

    Issues With PI-SDK Snapshot high data sampling


      I have an issue trying to get a high sampling of data, i am getting the sampling trought PI.Data sanpshot with a frecuenci of 20 (1 per 50 ms)  values per second, but its seems that the snapshot only take 4 per second (1 per 250 ms). I tried to modify the "collectin" attribute but its get me an error.


      well, there is any way to know that actually i am getting just 4 values per second, and if it right, how can i do to get the 20 values.





        • Re: Issues With PI-SDK Snapshot high data sampling



          could you please post a code sample? I am not sure what you are observing. If there is data every 20ms in the PI Archive, you should be able to retrieve that. If you are writing data to the PI System, you should be easily able to write data with a frequency of 20 Hertz.

            • Re: Issues With PI-SDK Snapshot high data sampling





              My code is made in LabView so i going to post a pic with my diagram, hope its works.








              Another problem, i tried to used the archive value and its work fine send a value every 20 ms, but the data is wirtting with some time delay.













                • Re: Issues With PI-SDK Snapshot high data sampling

                  I see - you are trying to retrieve data by querying the snapshot. I am not familiar with Labview, so I am not sure what causes the issue. But there are some things to mention:


                  The usual way to make sure to get all events in the snapshot for a particular tag is using an EventPipe, with that you would sign up for events (Snapshots) and the system will send that to a queue where you can pick them up. This ensures that you are not missing an event.


                  The exception and compression algorithms applied to your data might reduce the amount of data that is written to the snapshot /archive compared to the amount of data that is read by the interface.


                  So Labview does require you to poll for new data in the snapshot (as you are doing now) there could be various reasons for only getting 4 values: Labview does not poll often enough, the data is filtered by exception, the data is queued while send to the PI server and you are missing the events as they are sent in bunches.


                  Would it be possible in Labview to use the EventPipe mechanism? Or would it be possible to use archive data (in that case you would need to switch of compression for the tag)?


                  Regarding your write - it looks to me that there is a chance that your timestamp is misinterpreted. The way the PI System works would not allow a delay in writing for a single tag. Could you check if the time delay you think you are experiencing is actually full hours, indicating that there is a timezone issue?

                    • Re: Issues With PI-SDK Snapshot high data sampling

                      here is a little code snippet, even if you could not use it in Labview you might use it to see if you get snapshot events with the rate you are expecting:

                      PISDK.PIPoint myPIPoint;
                      PISDK.EventPipe pdEvents; 

                      myPIPoint = srv.PIPoints["CDT158"];

                      pdEvents = myPIPoint.Data.EventPipe;
                      pdEvents.MaxCount = 1000;

                      for (int i = 0; i < 5; i++)
                          long count;
                          object[] evObj;
                          count = pdEvents.Count;
                          if (count > 0)
                              evObj = newobject[pdEvents.Count];
                              evObj = (object[])pdEvents.TakeAll();
                              foreach (PISDK.PIEventObject PIEvObj in evObj)
                                  PISDK.PointValue pv = (PISDK.PointValue)PIEvObj.EventData;
                          MessageBox.Show(count.ToString() + " events.");

                        • Re: Issues With PI-SDK Snapshot high data sampling

                          As far as the writing problem, you might want to look into Snapshot/Archive/Queue statistics (through Performance Counters or command-line utilities), and see what is going on. If the same code works for 50ms writes but not for 20ms, then it may be that one of these mechanisms is overwhelmed or it could even be a network issue. This brings us back to standard PI System Management so I would recommend you take a look at the appropriate chapter in the "PI System Manager I: Essential Skills" training course (see under vCampus Training Center), read the "PI System Management Guide" (see under vCampus Library), or contact Technical Support.


                          As for the reading problem, are you saying that you can read data that is stored at 50ms intervals with another application (e.g. Archive Editor in PI SMT), but your PI SDK application only reads it at 250ms granularity (5 times the same value)??

                            • Re: Issues With PI-SDK Snapshot high data sampling

                              Sorry for the late answers, i was working with another issues if the work, but now i need to take it back the code in what i was working with PI-SDK.


                              Steve, you are right, i can get data every 50ms with pi-processbook or with data link, but in labview i just get every 250ms.


                              well now i am trying to make the code in Visual Basic, and i am getting the same result, this is te code that i am using:

                              Dim PI_SRV As PISDK.Server
                              Set PI_SRV = PISDK.Servers.Item("")
                              PI_SRV.Open ("USER=pidemo;PWD=pidemo")
                              Do Until ActiveSheet.Datos_PI.Value = True
                                 Range("D5").Value = ((PI_SRV.PIPoints.Item("TPO.U1.Freq").Data.Snapshot.TimeStamp.UTCSeconds / 3600) + 35081) / 24
                                 Range("E5").Value = PI_SRV.PIPoints.Item("TPO.U1.Freq").Data.Snapshot.Value
                              Set PI_SRV = Nothing



                              Thanks for your help

                                • Re: Issues With PI-SDK Snapshot high data sampling
                                  Ahmad Fattahi

                                  How can you be sure that your loop is in fact looping fast enough? Can you make it just write the current system time once per iteration to see how far apart in time two consecutive iterations are?

                                    • Re: Issues With PI-SDK Snapshot high data sampling
                                      Rick Davin

                                      If something is time sensitive in the scale of milliseconds, issuing a DoEvents is a significant time drag, especially if executing it during every iteration of the loop.

                                        • Re: Issues With PI-SDK Snapshot high data sampling

                                          Beware of dots... every time you use a period somewhere, that means it needs to "construct" an object or collection of some sort. For example when you call "PI_SRV.PIPoints.Item("TPO.U1.Freq").Data.Snapshot.TimeStamp.UTCSeconds", you are asking the Server object to seek its PI Points collection, then you instantiate its Data object, and the underlying PIValue object behind Snapshot... and you do this every single iteration of the loop.


                                          I would recommend you refactor your application and write it in such a way that you use a few dots as possible, i.e. use the lowest-level objects possible.


                                          As an example, if you need to perform some operation on  the PI Point labeled "TPO.U1.Freq", then I would recommend you at least declare a PIPoint object (Dim pt As PIPoint), set it to the appropriate point (Set pt = PI_SRV.PIPoints.Item("TPO.U1.Freq")) and then deal with "pt" only within the loop. See the "Beware of dots" article in the PI SDK Programming Reference


                                          Should you have to loop through the snapshot values for a list of tags, use the PointList object (don't hesitate to start a new thread on this very topic, if you need further assistance).


                                          Oh, and the DoEvents is probably not necessary here... as Rick accurately pointed out, it can be a significant time drag.


                                          Hope this helps!

                          • Re: Issues With PI-SDK Snapshot high data sampling

                            We recently created a new PI System Connectivity Toolkit for LabVIEW.  Please see the post on PI Square.

                            PI System Connectivity Toolkit for LabVIEW


                            To obtain installation instructions, LabVIEW Virtual Instruments, and sample code files, see the following posting on the National Instruments Reference Design Portal: