2 Replies Latest reply on Jan 5, 2015 9:45 AM by weeranuch

    PIACE : I got an error when debugging "Conversion from Digitalstate to type Double is not valid"

    weeranuch

      I would like to get time in second when tag captured  "Comm Fail" or "I/O Timeout"

      I try to code as below and got an error when debugging "Conversion from Digitalstate to type Double is not valid"

       

      Dim temp As Object

      temp = tag.TimeEQ("*-1h", "*", "Comm Fail")

       

      I try to change temp to double also and got the same error ,too

       

      anyone who can help me ,pls

        • Re: PIACE : I got an error when debugging "Conversion from Digitalstate to type Double is not valid"
          bshang

          Hi Weeranuch,

           

          I believe this issue arises when a float or int tag has a digital state over the entire time period of the TimeEQ evaluation. So in this case, when the error occurred, the tag had a digital state from *-1h to *. I believe this issue also arises in Performance Equations, as the TimeEQ from ACE and TimeEQ from PE's all boil down to the same native methods. If the above condition arises, then the state "Calc Failed" will be returned to ACE and it tries to be cast to a Double. Hence, there is an InvalidCastException thrown as you saw.

           

          If the tag has a good value at any time during the requested range in TimeEQ, then the method will return the correct result. The behavior looks to be an issue with the calculation libraries. I'll try to find further details and get back to you.

           

          In the meantime, a workaround is to use a Try/Catch pattern and handle the InvalidCastException. You may just have to return the entire time range (in seconds) in the Catch block for now as a workaround.

           

                  Try
                      time = tag.TimeEQ("*-1h", "*", "Comm Fail")
                  Catch ex As InvalidCastException
                      'Handle exception here
                  End Try
          
          1 of 1 people found this helpful
          • Re: PIACE : I got an error when debugging "Conversion from Digitalstate to type Double is not valid"
            weeranuch

            Thanks, Barry

             

            I coding more function to skip that error as below then it 's work .

             

            If tag.PctGood("*-1h", "*") = 0 Then

                       temp = 3600

            Else

                        temp = tag.TimeEQ("*-1h", "*", "I/O Timeout")

                     

            End If