3 Replies Latest reply on Sep 25, 2018 5:18 PM by anogueira

    Write Data from Datalink to PI Server - IMD Tags

    NoéAlvarado

      Hi to all

      I have a macro to write tags from Datalink to Excel. I am using a String Datatype to write some comments of the shift. The problem that I have is that I don´t know how to limit the period of time of comments.

      For example:

       

      TAG "String1" values:

      - 08:00 - 09:00     --> "The SAG Mill has been stopped".

      - 13:00 - 14:35     --> "Problem with the pump XX".

      When I write this values to the tag I write on the macro the first value. For example

           Write "The SAG Mill has been stopped" to 'String1' at 08:00.

      After that I write the next Value:

           Write "Problem with the pump XX" to 'String1' at 13:00.

       

      The macro is working, the problem that I have is how to finish the first value at 09:00 or 14:35. I tried to write 'String1' value at 09:00 to "NoOutput()" but doesn´t work, I want to have "No Data", because I didn´t have any event there, just like the "No Data" that I have when I created the tag. When I write "NoOutput()" this can give me problems with some calculations and also doesn´t look well on trends.

      Please can someone help me with this?

      Regards,

      Noé.

        • Re: Write Data from Datalink to PI Server - IMD Tags
          Lal_Babu_Shaik

          Hi Noe

           

          "No Data" is system digital state in PI. You can pass digital state code (248) as value to PI point and it will write "No Data" value.

           

          Thanks

          Lal

            • Re: Write Data from Datalink to PI Server - IMD Tags
              NoéAlvarado

              @Lal Babu Shaik

              Thanks for the reply. I know that "No Data" is a Digital State in PI. But I don´t know how to write that using VBA con Excel. Also I don´t know if that works on a IMD tag that collects String data.

              The code line that I am using to write is this one:

               

              "srv.PIPoints(Sheet5.Cells(IntFilaTA_1, IntColTA_1).Text).Data.UpdateValue DBLValorTA_1, DTFechaTA, dmReplaceDuplicates IntContadorTA_1 = IntContadorTA_1 + 1"

               

              Sheet5.Cells(IntFilaTA_1, IntColTA_1 --> Here is the tagname to write

              DBLValorTA_1 --> Here is the value to write to the tag.

              DTFechaTA --> The date to write the PI Point.

               

              Please,

              Can you help me with this.

                • Re: Write Data from Datalink to PI Server - IMD Tags
                  anogueira

                  Hi Noé,

                   

                  According to the PI SDK Programming reference the method updatevalue syntax is:

                   

                  object.UpdateValue NewValue, TimeStamp, [MergeType], [AsyncStatus]

                   

                  Where NewValue has many possible values types. One of them is VT_BSTR. This type can be used as follows:

                   

                  "Supported for all point types.  Note, value coercion may be required for numeric types with can result in lowered precision of the value.  For TimeStamp points, a string is parsed according to the time string parsing rules on the PI server.  See the PI Server Reference Guide for more information on valid PI Server time string representations.  For digital points, a positive numeric value is interpreted as an offset in its digital state set, a negative value is interpreted as an offset in the System Digital State Set.  For digital points, the string representation of a digital state, either system or for the point's own digital state set, can be passed to the PI SDK which will coerce the string into a DigitalState object.  For all other point types, if a non-numeric string is passed to a numeric point type, the PI SDK will attempt to coerce the string to a system DigitalState object only."

                   

                  Therefore, if you are using a numeric tag you can use a string with the Digital Set Name such as "No Data".

                   

                  However, you mentioned a string data. Therefore, I believe that , when using a string type PI Point the best option would be to create a digital state variable and use it as the NewValue parameter. See code below:

                   

                      Dim srv As server                                                               'Server declaration
                      Dim tag As PIPoint                                                              'PIPoint declaration
                      Dim timestamp As String                                                         'Time stamp variable declaration
                      Dim tagValue As Variant                                                       'New value variable declaration
                      Dim myDigState As DigitalState
                      Dim myStateSet As StateSet
                      
                      Set srv = PISDK.Servers.DefaultServer                                           'Setting the declared server as the default server(MARC-RAS)
                      Set tag = srv.PIPoints(txtTagName.Text)                                         'Setting the declared PIPoint as the PIPoint with the same name written in the textbox
                      timestamp = txtTime.Text                                                        'Assigning the text written in the textbox(txtTime) to the string timestamp
                      
                      Set myStateSet = srv.StateSets("SYSTEM")                                        'Assigning the SYSTEM Digital Set 
                      Set myDigState = myStateSet("No Data")                                           'Assigning the "No Data" as digital State
                      
                      tag.Data.UpdateValue myDigState, timestamp, dmReplaceDuplicates                   'Replace the value stored at the chosen timestamp with the new value