5 Replies Latest reply on May 26, 2017 5:01 AM by Kenn07

    Issues with PI-UFL DateTime field

    Kenn07

      Hi,

       

      I am building a new configuration for a UFL interface we will be using and have found a peculiar problem. I have defined the DateTime field to accept data in the following format, "d/M/yyyy h:m:s". The issue arises when, in the input data file, I have a time stamp which doesn't contain a 'seconds' field.

       

      For example if I input a time-stamp '16/07/2016 16:25', the interface failed to read this and gives me an 'Invalid time format' error.

       

      Has anyone else encountered this issue and found a fix for this? Any help/pointers would be greatly appreciated.

        • Re: Issues with PI-UFL DateTime field
          Kenji Hashimoto

          If your csv contains both timestamp with seconds and timestamp without seconds, then you can use if sentence to check it contains seconds or not.

          First, create string fields for timestamp and check length of the timestamp.

          You should be able to use LEN() to check the length of the string.

          After that, you can create 2 timetamp fileds and you can set one of them by length results and call storeinpi.

          Example

          if( LEN(StringTimestamp) > 16) THEN
          Timestamp = ["*,(*),*,*,*"]
          StoreInPI(Tag,,Timestamp,Value,Status,QuestionableFlag)
          Else
          Timestampwithoutseconds = ["*,(*),*,*,*"]
          StoreInPI(Tag,,Timestampwithoutseconds,Value,Status,QuestionableFlag)
          EndIF
          
          1 of 1 people found this helpful
            • Re: Issues with PI-UFL DateTime field
              Kenn07

              Hi Kenji Hashimoto,

               

              Thanks for your reply.

              When I implement the code though, it's somehow overwriting the tag with the last data available. For Example, if the input is as follows.

              Then the tag gets overwritten to have only one value. So, 77.111 is overwritten with 16.111 and finally 16.111 is overwritten by 25.111 even when they all have different timestamps.

              • Re: Issues with PI-UFL DateTime field
                Kenn07

                And for some reason the Timestamp line in the code is getting saved as a comment (weird)-

                 

                  • Re: Issues with PI-UFL DateTime field
                    cramsey

                    Based on the event timestamp in PI SMT, it appears it used execution time as the timestamp because the timestamp variable was not valid.

                     

                    Why are you setting the timestamp variable to the second element in the row?  Based on your data file, it is the first element, so timestamp ="[(*),*]

                     

                    right before the StoreInPi() call, use:

                     

                    PRINT ("timestamp is")

                    PRINT (timestamp)

                     

                    That will print the value of the variable called "timestamp" to the log file to confirm that the timestamp is correct.

                      • Re: Issues with PI-UFL DateTime field
                        Kenn07

                        Hi Clint,

                        Thanks for the reply.

                        After a bit of deliberation, I went for another code which made more sense in our case.

                        I went for a Temp variable which extracts only the minute and second part ( the ':' symbol being the identifier) and trained the interface to write the seconds part or skip based on the number of fields in the input. Code is as below-

                         

                        TimeAdjust = "01:30:00"

                        IF len(Temp) <= 2 THEN

                        TimeString=TimeString+":00"

                        TimeStamp=TimeString

                        ELSE

                        TimeStamp=TimeString

                        ENDIF

                        IF (Quality == "Bad") THEN

                        TimeStamp = TimeStamp - TimeAdjust

                        StoreInPI(Tag, ,TimeStamp,Value,-255, )

                        ELSE

                        IF (Quality == "Question")THEN

                        TimeStamp = TimeStamp - TimeAdjust

                        StoreInPI(Tag, ,TimeStamp,Value,0,1 )

                        ELSE

                        TimeStamp = TimeStamp - TimeAdjust

                        StoreInPI(Tag, ,TimeStamp,Value,0, )

                        ENDIF

                        ENDIF