/// <summary> /// Sets private members to default values. /// </summary> private void Initialize() { m_engineeringUnits = new EUInformation(); m_eURange = new Range(); m_title = null; m_axisScaleType = AxisScaleEnumeration.LINEAR; m_axisSteps = new DoubleCollection(); }
/// <summary> /// Reads tag unit. /// </summary> async Task ReadUnit(ReferenceDescription[] rds, UaTcpSessionChannel channel, Tag tag) { ReadValueId[] unit = new ReadValueId[1]; unit[0] = new ReadValueId { NodeId = NodeId.Parse(rds.Last().NodeId.ToString()), AttributeId = AttributeIds.Value }; ReadRequest unitRequest = new ReadRequest { NodesToRead = unit }; ReadResponse unitResponse = await channel.ReadAsync(unitRequest); ExtensionObject EO = (ExtensionObject)unitResponse.Results[0].Value; EUInformation EU = (EUInformation)EO.Body; tag.Unit = EU.DisplayName; //zapis jednostki }
private WeatherData GetNewValue(String name) { WeatherData weatherInfo = new WeatherData(); OpenWeatherMapDataClass openWeatherData = apiRequests.GetWeatherDataByCity(name); if (openWeatherData != null) { EUInformation info_temp = new EUInformation(); EUInformation info_press = new EUInformation(); info_press.DisplayName = new String("Pa"); info_press.Description = new String("Pascal"); info_press.NamespaceUri = new string("http://www.opcfoundation.org/UA/units/un/cefact"); info_press.UnitId = 4932940; info_temp.DisplayName = new String("K"); info_temp.Description = new String("Kelvin"); info_temp.NamespaceUri = new string("http://www.opcfoundation.org/UA/units/un/cefact"); info_temp.UnitId = 5259596; weatherInfo.CityName = new string(name); AnalogData temperature = new AnalogData(); AnalogData maxTemperature = new AnalogData(); AnalogData minTemperature = new AnalogData(); AnalogData pressure = new AnalogData(); maxTemperature.Data = openWeatherData.Main.TempMax; maxTemperature.Info = info_temp; weatherInfo.MaxTemperature = maxTemperature; minTemperature.Data = openWeatherData.Main.TempMin; minTemperature.Info = info_temp; weatherInfo.MinTemperature = minTemperature; temperature.Data = openWeatherData.Main.Temp; temperature.Info = info_temp; weatherInfo.Temperature = temperature; pressure.Data = openWeatherData.Main.Pressure; pressure.Info = info_press; weatherInfo.Pressure = pressure; } //timer set on m_simulationTimer = new Timer(OnRaiseSystemEvents, null, 20000, 20000); return(weatherInfo); }
/// <summary> /// Updates a variable from a tag. /// </summary> /// <param name="context">The context.</param> /// <param name="tag">The tag.</param> /// <param name="variable">The variable to update.</param> private void UpdateVariable(ISystemContext context, UnderlyingSystemTag tag, BaseVariableState variable) { variable.Description = tag.Description; variable.Value = tag.Value; variable.Timestamp = tag.Timestamp; switch (tag.DataType) { case UnderlyingSystemDataType.Integer1: { variable.DataType = DataTypes.SByte; break; } case UnderlyingSystemDataType.Integer2: { variable.DataType = DataTypes.Int16; break; } case UnderlyingSystemDataType.Integer4: { variable.DataType = DataTypes.Int32; break; } case UnderlyingSystemDataType.Real4: { variable.DataType = DataTypes.Float; break; } case UnderlyingSystemDataType.String: { variable.DataType = DataTypes.String; break; } } variable.ValueRank = ValueRanks.Scalar; variable.ArrayDimensions = null; if (tag.IsWriteable) { variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; } else { variable.AccessLevel = AccessLevels.CurrentRead; variable.UserAccessLevel = AccessLevels.CurrentRead; } variable.MinimumSamplingInterval = MinimumSamplingIntervals.Continuous; variable.Historizing = false; switch (tag.TagType) { case UnderlyingSystemTagType.Analog: { AnalogItemState node = variable as AnalogItemState; if (tag.EuRange != null) { if (tag.EuRange.Length >= 2 && node.EURange != null) { Range range = new Range(tag.EuRange[0], tag.EuRange[1]); node.EURange.Value = range; node.EURange.Timestamp = tag.Block.Timestamp; } if (tag.EuRange.Length >= 4 && node.InstrumentRange != null) { Range range = new Range(tag.EuRange[2], tag.EuRange[3]); node.InstrumentRange.Value = range; node.InstrumentRange.Timestamp = tag.Block.Timestamp; } } if (!String.IsNullOrEmpty(tag.EngineeringUnits) && node.EngineeringUnits != null) { EUInformation info = new EUInformation(); info.DisplayName = tag.EngineeringUnits; info.NamespaceUri = Namespaces.HistoricalAccess; node.EngineeringUnits.Value = info; node.EngineeringUnits.Timestamp = tag.Block.Timestamp; } break; } case UnderlyingSystemTagType.Digital: { TwoStateDiscreteState node = variable as TwoStateDiscreteState; if (tag.Labels != null && node.TrueState != null && node.FalseState != null) { if (tag.Labels.Length >= 2) { node.TrueState.Value = new LocalizedText(tag.Labels[0]); node.TrueState.Timestamp = tag.Block.Timestamp; node.FalseState.Value = new LocalizedText(tag.Labels[1]); node.FalseState.Timestamp = tag.Block.Timestamp; } } break; } case UnderlyingSystemTagType.Enumerated: { MultiStateDiscreteState node = variable as MultiStateDiscreteState; if (tag.Labels != null) { LocalizedText[] strings = new LocalizedText[tag.Labels.Length]; for (int ii = 0; ii < tag.Labels.Length; ii++) { strings[ii] = new LocalizedText(tag.Labels[ii]); } node.EnumStrings.Value = strings; node.EnumStrings.Timestamp = tag.Block.Timestamp; } break; } } }
/// <summary> /// Sets private members to default values. /// </summary> private void Initialize() { m_data = (float)0; m_info = new EUInformation(); }
private ServiceResult WriteWeatherData(string city, string measureOfTemperature) { WeatherData insideData = new WeatherData(); AnalogData insideTempData = new AnalogData(); AnalogData insideMaxTempData = new AnalogData(); AnalogData insideMinTempData = new AnalogData(); AnalogData insidePressureData = new AnalogData(); EUInformation info_press = new EUInformation(); EUInformation info_temp = new EUInformation(); lock (Lock) { if (city != null) { double conversionFactor = 0; info_press.DisplayName = new String("Pa"); info_press.Description = new String("Pascal"); info_press.NamespaceUri = new string("http://www.opcfoundation.org/UA/units/un/cefact"); info_press.UnitId = 4932940; switch (measureOfTemperature) { case "K": Console.WriteLine("Unit of measurement for Temperature choosed: " + "Kelvin"); info_temp.DisplayName = new String("K"); info_temp.Description = new String("Kelvin"); info_temp.NamespaceUri = new string("http://www.opcfoundation.org/UA/units/un/cefact"); info_temp.UnitId = 5259596; break; case "C": Console.WriteLine("Unit of measurement for Temperature choosed: " + "Celsius"); info_temp.DisplayName = new String("°C"); info_temp.Description = new String("degree Celsius"); info_temp.NamespaceUri = new string("http://www.opcfoundation.org/UA/units/un/cefact"); info_temp.UnitId = 4408652; conversionFactor = 273.15; break; default: Console.WriteLine("Unit of measurement for Temperature choosed: " + "Kelvin"); info_temp.DisplayName = new String("K"); info_temp.Description = new String("Kelvin"); info_temp.NamespaceUri = new string("http://www.opcfoundation.org/UA/units/un/cefact"); info_temp.UnitId = 5259596; break; } Console.WriteLine("mesure " + measureOfTemperature); OpenWeatherMapDataClass openWeatherData = apiRequests.GetWeatherDataByCity(city.ToString()); if (openWeatherData != null) { insideMaxTempData.Data = (float)(openWeatherData.Main.TempMax - conversionFactor); insideMaxTempData.Info = info_temp; insideData.MaxTemperature = insideMaxTempData; insideMinTempData.Data = (float)(openWeatherData.Main.TempMin - conversionFactor); insideMinTempData.Info = info_temp; insideData.MinTemperature = insideMinTempData; insideTempData.Data = (float)(openWeatherData.Main.Temp - conversionFactor); insideTempData.Info = info_temp; insideData.Temperature = insideTempData; insidePressureData.Data = openWeatherData.Main.Pressure; insidePressureData.Info = info_press; insideData.Pressure = insidePressureData; insideData.CityName = new string(city); if (insideData != null) { openWeatherObject.CityName.Value = new String(insideData.CityName); openWeatherObject.WeatherData.Value = insideData; openWeatherObject.WeatherData.StatusCode = StatusCodes.Good; openWeatherObject.WeatherData.Timestamp = DateTime.UtcNow; return(ServiceResult.Good); } else { return(StatusCodes.BadUnknownResponse); } } } } Console.WriteLine("INPUT ERROR: I can't get informations for this city or city is null: " + city); return(StatusCodes.BadAggregateInvalidInputs); }