public Simulator() { modbusServer = new ModbusTCPServer(); modbusServer.Subscribe(this); stopSignal = new ManualResetEvent(false); analogs = new Dictionary <long, Analog>(); discretes = new Dictionary <long, Discrete>(); readWriteMeasurementAddresses = new HashSet <int>(); commands = new ConcurrentQueue <CommandParams>(); modelLock = new ReaderWriterLockSlim(); client = new DuplexClient <ISubscribing, IPubSubClient>("callbackEndpoint", this); reclosers = new List <Tuple <Recloser, long, long, int> >(); loadProfiles = DailyLoadProfile.LoadFromXML("Daily_load_profiles.xml"); energyConsumers = new Dictionary <long, EnergyConsumer>(); }
float GetConsumerPowerValue(DateTime t, Analog a) { EnergyConsumer ec; if ((a.MeasurementType != MeasurementType.ActivePower && a.MeasurementType != MeasurementType.ReactivePower) || !energyConsumers.TryGetValue(a.PowerSystemResource, out ec)) { return(float.NaN); } DailyLoadProfile loadProfile = loadProfiles.Find(x => x.ConsumerClass == ec.ConsumerClass); if (loadProfile == null) { return(float.NaN); } return(loadProfile.Get(t.Hour, t.Minute) * (a.MeasurementType == MeasurementType.ActivePower ? ec.PFixed : ec.QFixed)); }
static void Main(string[] args) { Console.WriteLine("Waiting for NMS, press [Enter] to quit."); TopologyModelDownload download = new TopologyModelDownload(); while (!download.Download()) { while (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Enter) { return; } } Thread.Sleep(1000); } Console.WriteLine("Downloaded network model from NMS."); TopologyModel model = new TopologyModel(DailyLoadProfile.LoadFromXML("Daily_load_profiles.xml")); if (!model.ApplyUpdate(download)) { return; } TopologyModel.Instance = model; ServiceHost host = new ServiceHost(typeof(CalculationEngineService)); host.Open(); foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { Console.WriteLine(endpoint.ListenUri); } model.DownloadMeasurements(null); Console.WriteLine("[Press Enter to stop]"); Console.ReadLine(); host.Close(); }
bool ReadEnergyConsumerPowerFromLoadProfile(EnergyConsumer ec, out float re, out float im) { re = float.NaN; im = float.NaN; DailyLoadProfile loadProfile = loadProfiles.Find(x => x.ConsumerClass == ec.ConsumerClass); if (loadProfile == null) { return(false); } float pu = loadProfile.Get(t.Hour, t.Minute); if (float.IsNaN(pu)) { return(false); } re = pu * ec.PFixed; im = pu * ec.QFixed; return(true); }