protected override void WriteCommand_Execute(object obj) { try { ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)GetWriteFunctionCode(type), address, (ushort)CommandedValue, configuration); Common.IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); this.commandExecutor.EnqueueCommand(fn); } catch (Exception ex) { string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}"; this.stateUpdater.LogMessage(message); } }
protected override void WriteCommand_Execute(object obj) { try { // TODO implement ushort raw = 0; raw = EGUConverter.ConvertToRaw(configItem.ScaleFactor, configItem.Deviation, CommandedValue); ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)GetWriteFunctionCode(type), address, raw, configuration); Common.IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); this.commandExecutor.EnqueueCommand(fn); } catch (Exception ex) { string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}"; this.stateUpdater.LogMessage(message); } }
public async Task <bool> GetWeatherForecastAsyncSimulate() { //MOCK_Start bool isFileFull = true; Dictionary <long, List <HourDataPoint> > keyValuePairs = new Dictionary <long, List <HourDataPoint> >(); //Dictionary<long, List<HourDataPoint>> keyValuePairs = cache.ReadFromFileDataPoint(); if (keyValuePairs.Count == 0) { isFileFull = false; } //MOCK_End foreach (KeyValuePair <long, IdentifiedObject> kvp in analogniStari) { List <HourDataPoint> hourDataPoints; //MOCK_Start if (!isFileFull) { //MOCK_End Forecast result = await darkSkyProxy.GetTimeMachineWeatherAsync(((Analog)kvp.Value).Longitude, ((Analog)kvp.Value).Latitude, DateTime.Now, Unit.Auto); hourDataPoints = result.Hourly.Hours.ToList(); //MOCK_Start keyValuePairs.Add(((Analog)kvp.Value).GlobalId, hourDataPoints); } else { hourDataPoints = keyValuePairs[((Analog)kvp.Value).GlobalId]; DateTimeOffset timeOffset = DateTimeOffset.Parse("00:00 AM"); foreach (HourDataPoint dataPoint in hourDataPoints) { dataPoint.Time = timeOffset; timeOffset = timeOffset.AddHours(1); } } //MOCK_End DERMSCommon.WeatherForecast.WeatherForecast weatherForecast = new DERMSCommon.WeatherForecast.WeatherForecast(1001, 1, 1, 1, 1, DateTime.Now, ""); foreach (HourDataPoint hdr in hourDataPoints) { if (hdr.Time.Hour.Equals(DateTime.Now.Hour)) { hourDataPoint = hdr; } } float vrednost = 0; vrednost = CalculateHourAhead(((Analog)kvp.Value).Name, ((Analog)kvp.Value).NormalValue, ((Analog)kvp.Value).Latitude, ((Analog)kvp.Value).Longitude); foreach (KeyValuePair <List <long>, ushort> gidoviNaAdresu in GidoviNaAdresu) { if (gidoviNaAdresu.Key[1] == (((Analog)kvp.Value).GlobalId) && ((Analog)kvp.Value).Description == "Simulation") { try { ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, gidoviNaAdresu.Value, (ushort)vrednost, configuration); Common.IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); commandExecutor.EnqueueCommand(fn); ((Analog)kvp.Value).NormalValue = vrednost; ModbusWriteCommandParameters p1 = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, (ushort)(gidoviNaAdresu.Value - 1), (ushort)vrednost, configuration); Common.IModbusFunction fn1 = FunctionFactory.CreateModbusFunction(p1); commandExecutor.EnqueueCommand(fn1); ModbusWriteCommandParameters p12 = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, (ushort)(gidoviNaAdresu.Value - 2), 0, configuration); Common.IModbusFunction fn12 = FunctionFactory.CreateModbusFunction(p12); commandExecutor.EnqueueCommand(fn12); } catch (Exception ex) { string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}"; return(false); } } } } //MOCK_Start if (!isFileFull) { cache.WriteToFile(keyValuePairs); } //MOCK_End //foreach (KeyValuePair<long, IdentifiedObject> kvp in digitalniStari) //{ // float vrednost = 0; // List<Forecast> fo = new List<Forecast>(); // GetWeatherForecastAsync(((Discrete)kvp.Value).Latitude, ((Discrete)kvp.Value).Longitude); // vrednost = CalculateHourAhead(((Discrete)kvp.Value).Name, ((Discrete)kvp.Value).NormalValue, ((Discrete)kvp.Value).Latitude, ((Discrete)kvp.Value).Latitude); // foreach (KeyValuePair<List<long>, ushort> gidoviNaAdresu in GidoviNaAdresu) // { // if (gidoviNaAdresu.Key.Contains(((Discrete)kvp.Value).GlobalId)) // { // ushort raw = 0; // raw = EGUConverter.ConvertToRaw(2, 5, vrednost); // ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_COIL, gidoviNaAdresu.Value, raw, configuration); // IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); // commandExecutor.EnqueueCommand(fn); // } // } //} if (analogniStari.Count.Equals(0)) { return(false); } return(true); }
public void SendListOfGenerators(Dictionary <long, double> generators) { foreach (KeyValuePair <long, double> generator in generators) { //if (analogniStari.ContainsKey(generator.Key)) //{ foreach (KeyValuePair <List <long>, ushort> gidoviNaAdresu in GidoviNaAdresu) { if (generator.Key == gidoviNaAdresu.Key[0]) { if (analogniStari.Keys.Contains(gidoviNaAdresu.Key[1])) { if (analogniStari[gidoviNaAdresu.Key[1]].Description == "Commanding") { { KeyValuePair <long, IdentifiedObject> a = analogniStari.ElementAt(gidoviNaAdresu.Value - 3000 - 1); float zbir = ((Analog)a.Value).NormalValue + (float)generator.Value * ((Analog)a.Value).NormalValue / 100; ((Analog)a.Value).NormalValue = zbir; zbir = (float)Math.Round(zbir); double vred = (generator.Value * ((Analog)a.Value).NormalValue / 100); vred = (double)Math.Round(vred); if (vred < 0) { vred = vred * (-1); } ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, gidoviNaAdresu.Value, (ushort)vred, configuration); Common.IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); commandExecutor.EnqueueCommand(fn); ModbusWriteCommandParameters p1 = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, (ushort)(gidoviNaAdresu.Value - 2), (ushort)zbir, configuration); Common.IModbusFunction fn1 = FunctionFactory.CreateModbusFunction(p1); commandExecutor.EnqueueCommand(fn1); } } } else if (digitalniStari.Keys.Contains(gidoviNaAdresu.Key[1])) { if (digitalniStari[gidoviNaAdresu.Key[1]].Description == "Commanding") { { ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_COIL, gidoviNaAdresu.Value, (ushort)generator.Value, configuration); Common.IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); commandExecutor.EnqueueCommand(fn); } } } } //else if (digitalniStari.ContainsKey(generator.Key)) //{ // foreach (KeyValuePair<List<long>, ushort> gidoviNaAdresu in GidoviNaAdresu) // { // if (generator.Key == gidoviNaAdresu.Key[0] && gidoviNaAdresu.Key[2] == 1) // { // ushort raw = 0; // raw = EGUConverter.ConvertToRaw(2, 5, generator.Value); // ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_COIL, gidoviNaAdresu.Value, raw, configuration); // Common.IModbusFunction fn = FunctionFactory.CreateModbusFunction(p); // commandExecutor.EnqueueCommand(fn); // } // } //} } // LISTA GENERATORA KOJI SU PROMENILI FLEXIBILITY } }