internal static DaValue GetAttributeValue(Session session, ComNamespaceMapper mapper, uint attributeId, DataValue value)
{
switch (attributeId)
{
case INTERNAL_ATTRIBUTE_ANNOTATION:
{
DaValue result = new DaValue();
Annotation annotation = value.GetValue<Annotation>(null);
if (annotation == null)
{
result.Error = ResultIds.E_BADTYPE;
return result;
}
result.Value = annotation;
result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
result.Timestamp = value.SourceTimestamp;
result.Error = ResultIds.S_OK;
return result;
}
case Constants.OPCHDA_ENG_UNITS:
{
DaValue result = new DaValue();
EUInformation engineeringUnits = value.GetValue<EUInformation>(null);
if (engineeringUnits == null)
{
result.Error = ResultIds.E_INVALIDATTRID;
return result;
}
if (engineeringUnits.DisplayName != null)
{
result.Value = engineeringUnits.DisplayName.Text;
}
result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
result.Timestamp = value.SourceTimestamp;
result.Error = ResultIds.S_OK;
return result;
}
case Constants.OPCHDA_HIGH_ENTRY_LIMIT:
case Constants.OPCHDA_NORMAL_MAXIMUM:
{
DaValue result = new DaValue();
Range range = value.GetValue<Range>(null);
if (range == null)
{
result.Error = ResultIds.E_INVALIDATTRID;
return result;
}
result.Value = range.High;
result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
result.Timestamp = value.SourceTimestamp;
result.Error = ResultIds.S_OK;
return result;
}
case Constants.OPCHDA_LOW_ENTRY_LIMIT:
case Constants.OPCHDA_NORMAL_MINIMUM:
{
DaValue result = new DaValue();
Range range = value.GetValue<Range>(null);
if (range == null)
{
result.Error = ResultIds.E_INVALIDATTRID;
return result;
}
result.Value = range.Low;
result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
result.Timestamp = value.SourceTimestamp;
result.Error = ResultIds.S_OK;
return result;
}
case Constants.OPCHDA_MAX_TIME_INT:
case Constants.OPCHDA_MIN_TIME_INT:
{
DaValue result = new DaValue();
int error = ComHdaProxy.MapReadStatusToErrorCode(value.StatusCode);
if (error < 0)
{
result.Error = error;
return result;
}
// need to support the VT_CY type.
result.Value = (decimal)value.GetValue<double>(0);
result.HdaQuality = ComUtils.GetHdaQualityCode(value.StatusCode);
result.Timestamp = value.SourceTimestamp;
result.Error = ResultIds.S_OK;
return result;
}
default:
case Constants.OPCHDA_ITEMID:
case Constants.OPCHDA_ARCHIVING:
case Constants.OPCHDA_STEPPED:
case Constants.OPCHDA_EXCEPTION_DEV:
case Constants.OPCHDA_EXCEPTION_DEV_TYPE:
case Constants.OPCHDA_DERIVE_EQUATION:
{
return mapper.GetLocalDataValue(value);
}
}
}