public void Initialize(ISystemContext context, DaElement element, ushort namespaceIndex)
{
m_element = element;
if (element == null)
{
return;
}
this.NodeId = DaModelUtils.ConstructIdForDaElement(element.ItemId, -1, namespaceIndex);
this.BrowseName = new QualifiedName(element.Name, namespaceIndex);
this.DisplayName = new LocalizedText(element.Name);
// check if TimeZone is supported.
if (element.TimeZone != null)
{
PropertyState property = this.AddProperty<Range>(Opc.Ua.BrowseNames.LocalTime, DataTypeIds.TimeZoneDataType, ValueRanks.Scalar);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
property.Value = new Range(element.HighIR, element.LowIR);
}
// set the TypeDefinition based on the ElementType.
switch (element.ElementType)
{
case DaElementType.AnalogItem:
{
this.TypeDefinitionId = Opc.Ua.VariableTypeIds.AnalogItemType;
// EURange is always present.
PropertyState property = this.AddProperty<Range>(Opc.Ua.BrowseNames.EURange, DataTypeIds.Range, ValueRanks.Scalar);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
property.Value = new Range(element.HighEU, element.LowEU);
// check if InstrumentRange is supported.
if (element.HighIR != 0 || element.LowIR != 0)
{
property = this.AddProperty<Range>(Opc.Ua.BrowseNames.InstrumentRange, DataTypeIds.Range, ValueRanks.Scalar);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
property.Value = new Range(element.HighIR, element.LowIR);
}
// check if EngineeringUnits is supported.
if (element.EngineeringUnits != null)
{
property = this.AddProperty<EUInformation>(Opc.Ua.BrowseNames.EngineeringUnits, DataTypeIds.EUInformation, ValueRanks.Scalar);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
// use the server's namespace uri to qualify the engineering units.
string namespaceUri = context.NamespaceUris.GetString(namespaceIndex);
property.Value = new EUInformation(element.EngineeringUnits, namespaceUri);
}
break;
}
case DaElementType.DigitalItem:
{
this.TypeDefinitionId = Opc.Ua.VariableTypeIds.TwoStateDiscreteType;
// check if CloseLabel is supported.
if (element.CloseLabel != null)
{
PropertyState property = this.AddProperty<LocalizedText>(Opc.Ua.BrowseNames.TrueState, DataTypeIds.LocalizedText, ValueRanks.Scalar);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
property.Value = element.CloseLabel;
}
// check if OpenLabel is supported.
if (element.OpenLabel != null)
{
PropertyState property = this.AddProperty<LocalizedText>(Opc.Ua.BrowseNames.FalseState, DataTypeIds.LocalizedText, ValueRanks.Scalar);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
property.Value = element.OpenLabel;
}
break;
}
case DaElementType.EnumeratedItem:
{
this.TypeDefinitionId = Opc.Ua.VariableTypeIds.MultiStateDiscreteType;
// check if EuInfo is supported.
if (element.EuInfo != null)
{
PropertyState property = this.AddProperty<LocalizedText[]>(Opc.Ua.BrowseNames.EnumStrings, DataTypeIds.LocalizedText, ValueRanks.OneDimension);
property.NodeId = DaModelUtils.ConstructIdForComponent(property, namespaceIndex);
LocalizedText[] strings = new LocalizedText[element.EuInfo.Length];
for (int ii = 0; ii < strings.Length; ii++)
{
strings[ii] = element.EuInfo[ii];
}
property.Value = strings;
}
break;
}
}
if (element.Description != null)
{
this.Description = element.Description;
}
this.Value = null;
this.StatusCode = StatusCodes.BadWaitingForInitialData;
this.Timestamp = DateTime.UtcNow;
bool isArray = false;
this.DataType = ComUtils.GetDataTypeId(element.DataType, out isArray);
this.ValueRank = (isArray)?ValueRanks.OneOrMoreDimensions:ValueRanks.Scalar;
this.AccessLevel = AccessLevels.None;
if ((element.AccessRights & OpcRcw.Da.Constants.OPC_READABLE) != 0)
{
this.AccessLevel |= AccessLevels.CurrentRead;
}
if ((element.AccessRights & OpcRcw.Da.Constants.OPC_WRITEABLE) != 0)
{
this.AccessLevel |= AccessLevels.CurrentWrite;
}
this.UserAccessLevel = this.AccessLevel;
this.MinimumSamplingInterval = element.ScanRate;
}