/// <summary> /// Simulates values when no online data are available. /// </summary> /// <param name="station">Station to update.</param> /// <param name="x">Randomizer.</param> private void SimulateValues(structWeatherStation station, float x) { station.StationStatus.Cyclic = (short)enumStationStatus.Unknown; station.DewPoint.Cyclic = 0; station.Temp.Cyclic = 0; station.Pressure.Cyclic = 0; station.WindSpeed.Cyclic = 0; station.WindHeading.Cyclic = 0; station.Visibility.Cyclic = 0; }
/// <summary> /// Simulates values when no online data are available. /// </summary> /// <param name="station">Station to update.</param> /// <param name="x">Randomizer.</param> private void SimulateValues(structWeatherStation station, float x) { station.StationStatus.Cyclic = (short)enumStationStatus.Unknown; station.DewPoint.Cyclic = 30.0f * x; station.Temp.Cyclic = -50.0f * x; station.Pressure.Cyclic = 800.0f * x; station.WindSpeed.Cyclic = 50.0f * x; station.WindHeading.Cyclic = (ushort)(360f * x); station.Visibility.Cyclic = 15.0f * x; }
/// <summary> /// Outputs data read from the PLC to the console. /// </summary> /// <param name="station">Station to output data.</param> private void PrintOutStationData(structWeatherStation station) { var output = $"{station.AttributeName} [{(enumStationStatus)station.StationStatus.Synchron}][{station.StationICAO.Synchron}]:" + $"{station.DewPoint.AttributeName}: {station.DewPoint.Synchron} [{station.DewPoint.AttributeUnits}] " + $"{station.Temp.AttributeName}: {station.Temp.Synchron} [{station.Temp.AttributeUnits}] " + $"{station.Pressure.AttributeName}: {station.Pressure.Synchron} [{station.Pressure.AttributeUnits}] " + $"{station.Visibility.AttributeName}: {station.Visibility.Synchron} [{station.Visibility.AttributeUnits}] " + $"{station.WindSpeed.AttributeName}: {station.WindSpeed.Synchron} [{station.WindSpeed.AttributeUnits}] " + $"{station.WindHeading.AttributeName}: {station.WindHeading.Synchron} [{station.WindHeading.AttributeUnits}]"; System.Console.WriteLine(output); }
/// <summary> /// Outputs data read from the PLC to the console. /// </summary> /// <param name="station">Station to output data.</param> private void PrintOutStationData(structWeatherStation station) { // Notice that we use property 'LastValue' to read the value of the PLC variable. 'LastValue' is the last value read from the // controller using Batched reading. When you access 'LastValue' system does not adds this variable to the cyclic reading queue. var output = $"{station.AttributeName} [{(enumStationStatus)station.StationStatus.LastValue}][{station.StationICAO.LastValue}]:" + $"{station.DewPoint.AttributeName}: {station.DewPoint.LastValue} [{station.DewPoint.AttributeUnits}] " + $"{station.Temp.AttributeName}: {station.Temp.LastValue} [{station.Temp.AttributeUnits}] " + $"{station.Pressure.AttributeName}: {station.Pressure.LastValue} [{station.Pressure.AttributeUnits}] " + $"{station.Visibility.AttributeName}: {station.Visibility.LastValue} [{station.Visibility.AttributeUnits}] " + $"{station.WindSpeed.AttributeName}: {station.WindSpeed.LastValue} [{station.WindSpeed.AttributeUnits}] " + $"{station.WindHeading.AttributeName}: {station.WindHeading.LastValue} [{station.WindHeading.AttributeUnits}]"; System.Console.WriteLine(output); }
/// <summary> /// Updates station's data. /// </summary> /// <param name="station">Station to update.</param> internal void UpdateStationData(structWeatherStation station) { try { // Reads Weather Data from the internet. var icao = OpenWeather.MetarStationLookup.Instance.Lookup(station.StationICAO.Synchron); station.StationStatus.Cyclic = (short)enumStationStatus.Available; station.DewPoint.Cyclic = (float)icao.Weather.Dewpoint; station.Temp.Cyclic = (float)icao.Weather.Temperature; station.Pressure.Cyclic = (float)icao.Weather.Pressure; station.WindSpeed.Cyclic = (float)icao.Weather.WindSpeed; station.WindHeading.Cyclic = (ushort)icao.Weather.WindHeading; station.Visibility.Cyclic = (float)icao.Weather.Visibility; } catch (Exception ex) { // When online data not available we simulate the values. station.StationStatus.Cyclic = (short)enumStationStatus.Unknown; SimulateValues(station, new Random().Next()); } }