5 Replies Latest reply on Jun 12, 2015 12:36 PM by dng

    Converting a tag value of type double into string or digital type

    vdhar1992


      I have tag which is calculating values from two tags of type double in PI ACE.  I want to implement a condition in which if the input tags display "no data" then the output tag should also write "no data" after calculation.

      I have tried this using an if condition in which (input_tag_1.value = " no data" ) or (input_tag_1.value = " no data") then output_tag.value = "no data".

       

      But in this case when I am debugging, it is not going inside if statement and thus displaying bad input. I have also tried converting the input tags values to string and digital. But it failed. Can anyone help with this?

        • Re: Converting a tag value of type double into string or digital type
          Dan Fishman

          Is the value of tag1 and tag2 a system digital state "No Data".   If so, you want to check for "No Data" instead of "no data".

           

          If you only want to trigger if there is data at the execution timestamp there are other ways of doing this.

          • Re: Converting a tag value of type double into string or digital type
            Eugene Lee

            Hi Vaishali,

             

            Since your input tags are of type double. I think that 'No Data' is probably a digital state. You can use this code to test for that

             

                    If Not input_tag_1.Value.IsGood Or Not input_tag_2.Value.IsGood Then
                        If input_tag_1.Value.Name.Equals("No Data") Then
                            output_tag.Value() = "no data"
                        End If
                        If input_tag_2.Value.Name.Equals("No Data") Then
                            output_tag.Value() = "no data"
                        End If
                    End If
            
              • Re: Converting a tag value of type double into string or digital type
                vdhar1992

                How PI will consider input tag's "No Data" as good value or bad value?

                 

                I have tried the above code snippet but still it is not working. It is not going inside the If statement itself.

                  • Re: Converting a tag value of type double into string or digital type
                    Eugene Lee

                    Normally, since your tag is a double type. "No Data" will be a system digital state. What does

                     

                    debug.print input_tag_1.Value()

                     

                    show when it is "No Data"?

                     

                    I think the above code that I gave was for PIValue and not an PIACEPoint. My apologies. Therefore, you can test directly for IsGood on the PIACEPoint.

                     

                            If Not input_tag_1.IsGood() Or Not input_tag_2.IsGood() Then  
                                If input_tag_1.Code() = input_tag_1.DigState("No Data").Code Then  
                                    output_tag.Value() = "no data"  
                                End If  
                                If input_tag_2.Code() = input_tag_2.DigState("No Data").Code Then  
                                    output_tag.Value() = "no data"  
                                End If  
                            End If
                    

                     

                • Re: Converting a tag value of type double into string or digital type
                  dng

                  Hi Vaishali,

                   

                  Can you paste the code snippet you are using right now? Can you step through your code line by line to make sure your input tags are getting the values intended? You might have noticed that if the input tag is indeed using a digital state of "No Data" from the SYSTEM digital state set, input_tag_1.Value should give you a String object. If this is what you observed while stepping through your code, try a simple string comparison:

                   

                      Public Overrides Sub ACECalculations()
                          Dim test As Boolean
                          Dim val As Object
                          val = input_tag_1.Value
                          If val.Equals("No Data") Then
                              test = True
                          Else
                              test = False
                          End If
                          Debug.WriteLine(test)
                      End Sub