/// <summary> /// Sets the value with the specified name. /// </summary> public void SetValue(string name, object value) { Entry entry; Opc.Ua.TypeInfo type = Opc.Ua.TypeInfo.Construct(value); for (int ii = 0; ii < m_entries.Count; ii++) { entry = m_entries[ii]; if (entry.Name == name) { entry.Value = value; entry.DataType = type.BuiltInType; m_entries[ii] = entry; return; } } entry = new Entry(); entry.Name = name; entry.DataType = type.BuiltInType; entry.Value = value; m_entries.Add(entry); }
private ServiceResult OnWriteDataItem( ISystemContext context, NodeState node, NumericRange indexRange, QualifiedName dataEncoding, ref object value, ref StatusCode statusCode, ref DateTime timestamp) { DataItemState variable = node as DataItemState; // verify data type. Opc.Ua.TypeInfo typeInfo = Opc.Ua.TypeInfo.IsInstanceOfDataType( value, variable.DataType, variable.ValueRank, context.NamespaceUris, context.TypeTable); if (typeInfo == null || typeInfo == Opc.Ua.TypeInfo.Unknown) { return(StatusCodes.BadTypeMismatch); } if (typeInfo.BuiltInType != BuiltInType.DateTime) { double number = Convert.ToDouble(value); number = Math.Round(number, (int)variable.ValuePrecision.Value); value = Opc.Ua.TypeInfo.Cast(number, typeInfo.BuiltInType); } return(ServiceResult.Good); }
private ServiceResult OnWriteAnalog( ISystemContext context, NodeState node, NumericRange indexRange, QualifiedName dataEncoding, ref object value, ref StatusCode statusCode, ref DateTime timestamp) { AnalogItemState variable = node as AnalogItemState; // verify data type. Opc.Ua.TypeInfo typeInfo = Opc.Ua.TypeInfo.IsInstanceOfDataType( value, variable.DataType, variable.ValueRank, context.NamespaceUris, context.TypeTable); if (typeInfo == null || typeInfo == Opc.Ua.TypeInfo.Unknown) { return(StatusCodes.BadTypeMismatch); } // check index range. if (variable.ValueRank >= 0) { if (indexRange != NumericRange.Empty) { object target = variable.Value; ServiceResult result = indexRange.UpdateRange(ref target, value); if (ServiceResult.IsBad(result)) { return(result); } value = target; } } // check instrument range. else { if (indexRange != NumericRange.Empty) { return(StatusCodes.BadIndexRangeInvalid); } double number = Convert.ToDouble(value); if (variable.InstrumentRange != null && (number < variable.InstrumentRange.Value.Low || number > variable.InstrumentRange.Value.High)) { return(StatusCodes.BadOutOfRange); } } return(ServiceResult.Good); }
public ServiceResult OnWrite( ISystemContext context, NodeState node, NumericRange indexRange, QualifiedName dataEncoding, ref object value, ref StatusCode statusCode, ref DateTime timestamp) { BaseDataVariableState variable = node as BaseDataVariableState; // verify data type. Opc.Ua.TypeInfo typeInfo = Opc.Ua.TypeInfo.IsInstanceOfDataType( value, variable.DataType, variable.ValueRank, context.NamespaceUris, context.TypeTable); if (typeInfo == null || typeInfo == Opc.Ua.TypeInfo.Unknown) { return StatusCodes.BadTypeMismatch; } // check index range. if (variable.ValueRank >= 0) { if (indexRange != NumericRange.Empty) { object target = variable.Value; ServiceResult result = indexRange.UpdateRange(ref target, value); if (ServiceResult.IsBad(result)) { return result; } value = target; } } return ServiceResult.Good; }
private ServiceResult OnWriteDiscrete( ISystemContext context, NodeState node, NumericRange indexRange, QualifiedName dataEncoding, ref object value, ref StatusCode statusCode, ref DateTime timestamp) { MultiStateDiscreteState variable = node as MultiStateDiscreteState; // verify data type. Opc.Ua.TypeInfo typeInfo = Opc.Ua.TypeInfo.IsInstanceOfDataType( value, variable.DataType, variable.ValueRank, context.NamespaceUris, context.TypeTable); if (typeInfo == null || typeInfo == Opc.Ua.TypeInfo.Unknown) { return(StatusCodes.BadTypeMismatch); } if (indexRange != NumericRange.Empty) { return(StatusCodes.BadIndexRangeInvalid); } double number = Convert.ToDouble(value); if (number >= variable.EnumStrings.Value.Length | number < 0) { return(StatusCodes.BadOutOfRange); } return(ServiceResult.Good); }