Skip to content
  • There are no suggestions because the search field is empty.

ReadItem vs ReadItemValue

[PDF version here]

You have probably seen in the OPC Data Client that there are 2 methods that have similar names:

  • ReadItem()
  • ReadItemValue()

So why are there two methods that essentially do the same thing?


Firstly, these 2 methods are NOT the same, not in function and not in what they provide you.

  • ReadItemValue(): returns the value of a Tag only
  • ReadItem(): returns the value, quality and timestamp of a Tag.

Apart from the obvious difference, the way that these methods work can have a significant impact on your system.

ReadItemValue

ReadItemValue() returns the value of the Tag only. If your application does not care about the quality or timestamp of the tag, then this is the method for you. If you need the Tag quality and/or timestamp, then you cannot use this method.

Because this method returns a value ONLY, it has to make a decision as to when to provide that information to you, after all, there are quality codes that indicate whether or the value is accurate.

When requesting a Tag value using ReadItemValue() the quality will ALWAYS be good. If the quality of the Tag is not good quality, then the OPC Data Client will wait (based on your timeout settings) for the value to become Good. If after the timeout period has expired and the value is still not Good, then an error will be returned for you to handle accordingly.

ReadItemValue() can have a negative performance impact on your system if the tag qualities are not Good and your timeout settings are set high - allowing more time for the Tag's quality to go good. Therefore, if you cannot afford to potentially lose time based on a Tag whose quality is not Good, then you should consider using the ReadItem() method instead. Likewise, if your OPC Server connection to the device has proven to be 100% stable and reliable, then this may not be a concern for you.

ReadItem

ReadItem() returns the value, quality and timestamp of a Tag. We can't emphasize this enough, but when working with Tag values it is essential that you check the Quality of the Tag. If using the ReadItemValue() method then you know the quality is ALWAYS Good because of the way that method works. This is not the case when you use ReadItem().

When reading a Tag using the ReadItem() method, you will receive the values as the OPC Server provides them, good or bad. This is actually a good thing!

When reading a tag, you should always check the quality of the tag. Here's a pseudo or this:

myObject = ReadItem(.....)
If myObject.Quality = Good Then
doSomethingWithGoodQualityData
Else
doSomethingWithBadQualityData
logAndDisplayBadQualityData
End If

We strongly recommend this approach to OPC Client development for the following reasons:

  • you remain in control as you have access to the quality code, so you have more information about the Tag and its current state
  • your application will not be subject to the same delays as would be possible with the ReadItemValue() method.