15 Replies Latest reply on Sep 22, 2011 12:15 PM by dtakara

    PI OnNewValue events - Time required in milliseconds in ReceivedTime

    sandeep.narang

      Hi Team

       

      We are implementing OnNewValue event handler to get the PI Eventing notifications. We are getting the time from the ReceivedTime.LocalDate property of the  PIEventObject.

       

      LocalDate is returning the time in MM-DD-YYYY HH:M:SS format. Our requirement is to get the milliseonds as well. Please let us know if there is any setting change we need to make or any other property we need to use to achieve the same.,

       

      This is really a CRITICAL issue for us.

       

       

       

      Thanks and Regards

       

      Sachin

       

       

       

       

       

       

        • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
          sandeep.narang

          Hi team

           

          Any updates as this is really critical.

           

          Thanks

           

          Sachin

            • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
              dtakara

              Hi Sachin,

               

              The ReceivedTime property of the PIEventObject is a PITime object. A PITime object has 2 properties that are interesting for you in this case:

              • LocalDate
              • UTCSeconds

              Here is some VBA sample code to get a string containing the date and time with millisecond resolution, using the properties LocalDate and UTCSeconds:

               
              Dim myServer As Server
              Dim myPIPoint As PIPoint
              Dim myPIData As PIData
              Dim myPIValue As PIValue
              Dim myPITime As PITime
              
              Set myServer = PISDK.Servers.DefaultServer
              Set myPIPoint = myServer.PIPoints("cdt158")
              Set myPIData = myPIPoint.Data
              Set myPIValue = myPIData.Snapshot
              Set myPITime = myPIValue.TimeStamp
              
              MsgBox "timestamp of snapshot now is " & myPITime.LocalDate & "," & _
                  Right(Format(myPITime.UTCSeconds, "#0.000"), 3)
              

               

                • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                  dtakara

                  By the way, in this command

                   
                  MsgBox "timestamp of snapshot now is " & myPITime.LocalDate & "," & _     Right(Format(myPITime.UTCSeconds, "#0.000"), 3)
                  

                   I used the comma as separator of seconds and subseconds at

                   
                  "," 
                  

                   to form my date and time string, because this is the standard here in Brazil. You can use whatever separator is appropriate for you.

                   

                  For the Format function parameter though

                   
                  "#0.000" 
                  

                   the point is required to separate seconds from milliseconds.

                    • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                      sandeep.narang

                      Hi

                       

                      I have tried to use the UTCSeconds as defined above but for every event change is is coming as 0. Can you please guide me through.

                       

                      Thanks

                       

                      Sachin

                        • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                          sandeep.narang

                          Please note that milliseconds are coming as 0 like UTCSeconds is giving the results as 132543344.000

                            • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                              dtakara

                              Which programming language are you using?

                               

                              Here is some sample code for VB .NET, where myPIValue is a PIValue object (whose TimeStamp property is a PITime object):

                               
                                          If Not myPIValue.IsGood Then
                                              MessageBox.Show("time: " & myPIValue.TimeStamp.LocalDate.ToString & _
                                                        "," & Microsoft.VisualBasic.Right(Format(myPIValue.TimeStamp.UTCSeconds, "#0.000"), 3) & _
                                                            " - status: " & DirectCast(myPIValue.Value, PISDK.DigitalState).Name)
                                          Else
                                              MessageBox.Show("time: " & myPIValue.TimeStamp.LocalDate.ToString & _
                                                        "," & Microsoft.VisualBasic.Right(Format(myPIValue.TimeStamp.UTCSeconds, "#0.000"), 3) & _
                                                            " - value: " & myPIValue.Value.ToString)
                                          End If
                              

                               

                                • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                  sandeep.narang

                                  I am using c# as programming language.

                                   

                                  I used the UTCSeconds property as follows:

                                   

                                   

                                   
                                  PIVal.ReceivedTime.UTCSeconds.ToString("#0.000")
                                  

                                  I am always getting UTCSeconds as 0. Please suggest if any other way around is possible.

                                   

                                   

                                   

                                  Thanks and Regards

                                   

                                  Sachin

                                    • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                      dtakara

                                      As you are using C#, please try this:

                                       
                                      PIVal.ReceivedTime.LocalDate.ToString("MM/dd/yyyy hh:mm:ss.fff");
                                      

                                      ToString in C# has this nice option that allows showing subseconds of  a DateTime variable.

                                        • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                          sandeep.narang

                                          Hi Daniel

                                           

                                          The above statement would show the miliseconds only if the PIValue object has miiseconds in the timestamp. My issue is that miliseconds are not coming in the PIObject timestamp.

                                           

                                          Can you please let me know how can I create a custom tag which will notify , say, 10 events per second. In this way, I suppose, miliseconds can be associated with timestamp.

                                           

                                          Please let me know if you want further clarifications in this regard.

                                           

                                          Thanks and Regards

                                           

                                          Sachin

                                            • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                              dtakara

                                              Hi Sachin,

                                               

                                              What is the data source of the PI tag that is being monitored by the EventPipe of the PIEventObject? Is it an off-the-shelf OSIsoft interface? Which one? Note that not all OSIsoft interfaces support writing to PI tags with subsecond resolution. Or is it a custom application that is writing (or will write) values to the PI tag?

                                               

                                              Could you share some more information about your scenario and what exactly you are trying to achieve?

                                                • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                                  andreas

                                                  As a note, if you want to generate data with millisecond timestamps in your vCampus PI Server you can create a millisecond scan class for the random interface and create a sinus tag (other wave forms don't support millisecond timestamps AFAIK)

                                                    • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                                      sandeep.narang

                                                      Thats exactly what I want Andreas, Can i get the example/sample code of doing this stuff?

                                                       

                                                      Thanks

                                                       

                                                      Sachin

                                                      • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                                        dtakara

                                                        Sachin Puri

                                                        Thats exactly what I want, Can i get the example/sample code of doing this stuff?

                                                         

                                                         

                                                         

                                                        Andreas

                                                        you can create a millisecond scan class for the random interface

                                                         

                                                         

                                                         

                                                         

                                                        This means editing the file \Program Files\PIPC\Interfaces\Random\random.bat like this, for instance, on your PI Server and restarting the Windows service named "PI Random Simulator (random) Interface":

                                                         
                                                        .\random /ps=R /Q /host=localhost:5450 /f=00:00:30 /f=00:01:00 /f=00:00:00.1
                                                        

                                                         

                                                        Andreas

                                                        and create a sinus tag

                                                         

                                                         

                                                         

                                                         

                                                        This basically means creating a PI tag with the following configuration:

                                                        • location1: 0
                                                        • location2: 2
                                                        • location3: 0
                                                        • location4: 3
                                                        • location5: 0
                                                        • pointsource: R
                                                        • pointtype: float32
                                                        • span: 100
                                                        • zero: 0

                                                        For more details on the meaning of the values of the PI tag attributes above and other information on the PI Random Simulation interface, refer to its documentation at  \Program Files\PIPC\Interfaces\Random\PI_Random.doc.

                                                         

                                                        As the creation of PI tags for the PI Random Simulation interface (and other off-the-shelf OSIsoft interfaces) is more related to configuration than programming, if you need further assistance on this, you can follow up with our regular Technical Support.

                                                          • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                                            sandeep.narang

                                                            Thanks daniel for the help:)

                                                             

                                                            I was trying to use PI Interface Configuration Utility but everytime when i attempt something on it , i get an error " You must have write permissions for module database to perform this action" . Can you please let me know how to resolve this ?

                                                             

                                                            Thanks and regards

                                                             

                                                            Sachin

                                                              • Re: PI OnNewValue events - Time required in milliseconds in ReceivedTime
                                                                dtakara

                                                                Hi Sachin,

                                                                 

                                                                This is caused by this PI ICU requirement described in its documentation (accessible by its Help menu):

                                                                 

                                                                Module Database Permission

                                                                PI ICU creates the module Interfaces under the %OSI module. PI ICU configuration settings are stored in a hierarchy of modules under the Interfaces module.

                                                                 

                                                                PI ICU requires the following:

                                                                • Write access for the PIModules table (Database Security) in order to create modules.
                                                                • Write access for the %OSI module in order to create the Interfaces module.
                                                                • Write access for the Interfaces hierarchy to register interface instances with PI ICU and to change configuration settings.

                                                                 

                                                                You will want to check:

                                                                • the permissions for the PIModules table using the Database Security plug-in of PI-SMT
                                                                • the permissions for the %OSI module using the Module Database plug-in of PI-SMT

                                                                Again, as this is more related to configuration than programming, if you need further assistance on this, you can follow up with our regular Technical Support, but don't hesitate to keep posting your questions on programming and systems integration here in the vCampus forums.

                                                                 

                                                                As a side note, I am still curious about your use case.