2 Replies Latest reply on Aug 27, 2010 9:45 PM by spilon

    Reading the value of a timestamp tag

    lchaylian

      Hi, we are using the next code to read the values of a tag which its data type is timestamp:

      if (myValue.Value.GetType().IsCOMObject)
      {
          PISDK.DigitalState myDigState;
          myDigState = (PISDK.DigitalState) myValue.Value;  // Aqui es donde marca error
          textBox4.Text = myDigState.Name;
      }
      else
      {
          textBox4.Text = myValue.Value.ToString();
      };

      The problem is that the SDK take it as IsCOMObject and is trying to read it as a digital state and we get an error.

       

      What do we need to do in order to read a timestamp tag?

       

      Regards

       

      Luis

        • Re: Reading the value of a timestamp tag
          Ahmad Fattahi

          Why don't you retrieve the point type and compare it directly with 'timestamp'?

          • Re: Reading the value of a timestamp tag

            The SDK is not exactly taking the COMObject as a digital state... you are telling the SDK to do so ;)   Essentially, your code is assuming that a COMObject is necessarily a PISDK.DigitalState under the hood - you need to make it more flexible and assume the COMObject can be a PITimeServer.PITime object too.

             

            Something along the lines of:

            PISDK.PIValue myValue = myServer.PIPoints["timestamptag"].Data.Snapshot;
                        
            if (myValue.Value.GetType().IsCOMObject)
            {
                if (myValue.Value is PISDK.DigitalState)
                {
                    PISDK.DigitalState myDigState = (PISDK.DigitalState) myValue.Value;
                    textBox4.Text = myDigState.Name;
                }
                else if (myValue.Value is PITimeServer.PITime)
                {
                    PITimeServer.PITime myTimestamp = (PITimeServer.PITime) myValue.Value;
                    textBox4.Text = myTimestamp.LocalDate.ToString();
                }
            }
            else
            {
                textBox4.Text = myValue.Value.ToString();
            }

            Another use case you might want to account for is BLOB type tags, if used within your organization. Do not hesitate to start a new discussion thread on the topic, if you need further information...