4 Replies Latest reply on May 22, 2015 3:43 PM by aseck

    No value coming


      Hi All,

      In my calculations I'm taking all previous day values (previous day mid night to today mid night) of input tag in a array called PreviousDayValues, using Values function.


      PreviousDayValues = Input_tag.Values("y", "t", 0)


      Noe I want to calculate how many bad inputs are present in all those previousDayValues.

      For testing I had put 'Bad Input' as values of input tag ,with previous day timestamp.


      And calculating number of bad inputs with counter:

      For counter = 1 To (PreviousDayValues.Count)

                           If PreviousDayValues(counter).Value.ToString.Equals("Bad Input") Then

                              BadInputCount = BadInputCount + 1

                              End If


                          msgbox("no bad input ")

      Exit For


      Now I'm getting system com error.

      I think line PreviousDayValues(counter).Value.ToString.Equals("Bad Input") is not comparing the actual "Bad Input" present in input tag as value and string "Bad Input".

      If I'm not wrong , funtion 'Values' used in code line  Input_tag.Values("y", "t", 0) , taking all values of input tag along with timestamp, then

      why the comparision ' PreviousDayValues(counter).Value.ToString.Equals("Bad Input")' is not accepting the value?


      Help will be very much appriciated!



        • Re: No value coming
          Eugene Lee

          This is because Bad Input is a digital state and not a string. So try:


          If (CType(PreviousDayValues(counter).Value,DigitalState)).Name.ToString.Equals("Bad Input") Then

          1 of 1 people found this helpful
          • Re: No value coming

            Thanks Eugene Lee!

            Code is perfectly running for digital 'Bad Input' but the input tag is of datatype "float32" ,so other good data (also updating with bad Input ) is in float format.(sorry I missed to mention it earlier!)

            The code line (CType(PreviousDayValues(counter).Value,DigitalState)) is converting value to digital state but not working for float 32.

            Hence, throwing the error as:Unable to cast object of type 'system.single' to 'PISDK.DigitalState'.


            I want to check the Bad Input values from the bunch of all the values!

              • Re: No value coming

                Hi Supriya,


                Here's what is going on. When the cast in (CType(PreviousDayValues(counter).Value,DigitalState)) fails, it throws an InvalidCastException. You can use TryCast instead. The result of TryCast will be Nothing if it fails.


                However, there is a more native way using ACE functions to check if a float tag has a digital state as an event.


                First, for numeric PI tags, its values are considered "Bad" if the value is associated with a digital state from the System digital state set. If the value is bad, its PISDK.PIValue.Value property will be of the PISDK.DigitalState type (although you might see it as System.__ComObject in the debugger).


                To inspect the name of the digital state, use digstate.Name property, which returns a string.


                Therefore, you can try the below example:


                    Public Overrides Sub ACECalculations()
                        Dim vals As PIValues
                        vals = testACE.Values("y", "t", 0)
                        Dim badCount As Integer
                        badCount = 0
                        For Each item As PIValue In vals
                            If Not (item.IsGood) Then
                                If (item.Value.Name.Equals("Bad Input")) Then
                                    badCount += 1
                                End If
                            End If
                    End Sub


                First, it will check if the value is bad (e.g. belongs to a float tag but value is from System digstate). If so, then it checks if the specific digital state is Bad Input. There is probably also a clever LINQ one-liner for this.

              • Re: No value coming

                Hi Supriya,


                Did Eugene and Barry's suggestions help? If you were able to solve the issue, please mark the most useful answer as the correct answer. If not, please let use know how we can help further