Пример #1
0
        private void DataAcquisition()
        {
            while (true)
            {
                LogHelper.Log(LogTarget.File, LogService.SCADACrunching, " INFO - SCADACrunching.cs - Data acquisition, new measurement ciclus.");
                timestamp = DateTime.Now;

                lock (SCADAModel.Instance.Lock2PC)
                {
                    foreach (var analogValue in scadaModel.AnalogValues)
                    {
                        var value = client.ReadHoldingRegisters2(analogValue.Address, 1);

                        SynchronousMachine syncMachine = adapter.GetSyncMachineByGid(analogValue.SynchronousMachine);

                        if (syncMachine == null)
                        {
                            LogHelper.Log(LogTarget.File, LogService.SCADACrunching, " ERROR - SCADACrunching.cs - Data acquisition, Synchronous machine is not assigned to analog value.");
                            throw new Exception("Synchronous machine is not assigned to analog value.");
                        }

                        analogValue.Value = RawValuesConverter.ConvertRange(value[0], RAW_MIN, RAW_MAX, EGU_MIN, EGU_MAX);

                        analogValue.Timestamp = timestamp.Ticks;
                    }

                    SCADASubscriber.Instance.NotifySubscribers(DMSType.ANALOGVALUE);
                }

                Thread.Sleep(3000);
            }
        }
Пример #2
0
 public void ReceiveAndSetSetpoint(Setpoint setpoint)
 {
     foreach (var item in setpoint.PDistributionByAV)
     {
         AnalogValue av    = scadaModel.AnalogValues.Where(o => o.GlobalId.Equals(item.Key)).FirstOrDefault();
         float       value = RawValuesConverter.ConvertRange(item.Value, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
         //short value = floatToShort(RawValuesConverter.ConvertRange(item.Value, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX));
         //client.WriteSingleHoldingRegister(av.Address, value);
         LogHelper.Log(LogTarget.File, LogService.SCADASetpoint, " INFO - SCADASetpoint.cs - Receiving and setting setpoint.");
         client.WriteSingleHoldingRegister2(av.Address, value);
     }
 }
Пример #3
0
        /// <summary>
        /// Simulation of analog points changes
        /// </summary>
        private void SimulatorForAnalogPoints()
        {
            while (true)
            {
                lock (SimulatorModel.Instance.Lock2PC)
                {
                    foreach (AnalogValue value in model.AnalogPoints)
                    {
                        SynchronousMachine der = model.Ders[value.SynchronousMachine];

                        if (!SimulatorModel.Instance.CurrentWeathers.ContainsKey(der.GlobalId))
                        {
                            Console.WriteLine(DateTime.Now + ": Weather forecast is not available for GlobalId: " + der.GlobalId);
                            continue;
                        }

                        CAS signal = SimulatorModel.Instance.ControlActiveSignals.Where(o => o.Gid.Equals(value.GlobalId)).FirstOrDefault();

                        if (signal != null)
                        {
                            if (signal.ControlledBy.Equals(CASEnum.Normal))
                            {
                                Console.WriteLine(DateTime.Now + ": Signal gid: {0}, Status: {1}", signal.Gid, signal.ControlledBy);
                                continue;
                            }
                        }

                        WeatherInfo wInfo = SimulatorModel.Instance.CurrentWeathers[der.GlobalId];

                        switch (der.FuelType)
                        {
                        case FuelType.Sun:
                        {
                            if (value.PowerType == PowerType.Reactive)
                            {
                                float currentQ = 0;
                                currentQ = RawValuesConverter.ConvertRange(currentQ, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentQ);
                            }
                            else
                            {
                                long sunriseTime = wInfo.Daily.Data.FirstOrDefault().SunriseTime;
                                long sunsetTime  = wInfo.Daily.Data.FirstOrDefault().SunsetTime;

                                float currentP = pCalculator.GetActivePowerForSolarGenerator((float)wInfo.Currently.Temperature, (float)wInfo.Currently.CloudCover, der.NominalP, sunriseTime, sunsetTime);

                                currentP = RawValuesConverter.ConvertRange(currentP, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentP);
                            }
                        }

                        break;

                        case FuelType.Wind:
                        {
                            float currentP = pCalculator.GetActivePowerForWindGenerator(der.NominalP, (float)(wInfo.Currently.WindSpeed));

                            if (value.PowerType == PowerType.Reactive)
                            {
                                // 5% of active power
                                float currentQ = currentP * 0.05f;

                                currentQ = RawValuesConverter.ConvertRange(currentQ, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentQ);
                            }
                            else
                            {
                                currentP = RawValuesConverter.ConvertRange(currentP, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentP);
                            }
                        }

                        break;
                        }
                    }
                }

                Thread.Sleep(5000);
            }
        }