Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.Title = "SCADA";

            // ako je druga platforma npr. x86 nije dobra putanja!

            string acqComConfigPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "ScadaModel.xml");
            string pcConfig         = "RtuConfiguration.xml";
            string fullPcConfig     = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "RtuConfiguration.xml");
            string basePath         = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;

            // ovo dole ipak ne funkcionise ako stavis x64 ...videti sta sa ovom konfiguracijom

            //if (IntPtr.Size == 8)
            //{
            //    Console.WriteLine("size==8");
            //    // 64 bit machine
            //    acqComConfigPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "ScadaModel.xml");
            //    pcConfig = "RtuConfiguration.xml";
            //    fullPcConfig = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "RtuConfiguration.xml");
            //    basePath = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
            //}
            //else if (IntPtr.Size == 4)
            //{
            //    Console.WriteLine("size==4");
            //    // 32 bit machine
            //    acqComConfigPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName, "ScadaModel.xml");
            //    pcConfig = "RtuConfiguration.xml";
            //    fullPcConfig = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName, "RtuConfiguration.xml");
            //    basePath = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName;
            //}
            //else
            //{
            //    Console.WriteLine("aaaa");
            //}

            // to do: use cancellation tokens and TPL

            PCCommunicationEngine PCCommEng;

            while (true)
            {
                PCCommEng = new PCCommunicationEngine();

                if (!PCCommEng.Configure(basePath, pcConfig))
                {
                    Console.WriteLine("\nStart the simulator then press any key to continue the application.\n");
                    Console.ReadKey();
                    continue;
                }
                break;
            }


            CommAcqEngine AcqEngine = new CommAcqEngine();

            if (AcqEngine.Configure(acqComConfigPath))
            {
                // stavlja zahteve za icijalno komandovanje u red
                AcqEngine.InitializeSimulator();

                // uzimanje zahteva iz reda, i slanje zahteva MDBU-u. dobijanje MDB odgovora i stavljanje u red
                Thread processingRequestsFromQueue = new Thread(PCCommEng.ProcessRequestsFromQueue);

                // uzimanje odgovora iz reda
                Thread processingAnswersFromQueue = new Thread(AcqEngine.ProcessPCAnwers);

                // stavljanje zahteva za akviziju u red
                Thread producingAcquisitonRequests = new Thread(AcqEngine.StartAcquisition);

                processingRequestsFromQueue.Start();
                processingAnswersFromQueue.Start();

                // give simulator some time, and when everything is ready start acquisition
                Thread.Sleep(1000);
                producingAcquisitonRequests.Start();

                try
                {
                    Console.WriteLine("\n....");
                    SCADAService ss = new SCADAService();
                    ss.Start();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("SCADA service failed.");
                    Console.WriteLine(ex.StackTrace);
                    Console.ReadLine();
                    return;
                }
            }
            else
            {
                Console.WriteLine("Configuration of scada failed.");
            }

            Console.WriteLine("Press <Enter> to stop the service.");

            Console.ReadKey();

            AcqEngine.Stop();
            PCCommEng.Stop();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.Title = "SCADA";

            // to do: srediti kasnije, staviti fajlove u neki resource folder ili slicno
            // ako je druga platforma npr. x86 mozda nije dobra putanja!
            string pcConfig         = "RtuConfiguration.xml";
            string scadaConfig      = "ScadaModel.xml";
            string basePath         = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
            string acqComConfigPath = Path.Combine(basePath, scadaConfig);

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken;
            Task requestsConsumer, answersConsumer, acqRequestsProducer;

            var path = Directory.GetCurrentDirectory() + "..\\..\\..\\DNP3ConfigFiles\\";

            Dictionary <string, UniversalNetworkConfiguration> universalConfigurations  = new Dictionary <string, UniversalNetworkConfiguration>();
            Dictionary <string, DataPointsListConfiguration>   dataPointsConfigurations = new Dictionary <string, DataPointsListConfiguration>();

            foreach (string directory in Directory.GetDirectories(path))
            {
                XDocument  document = XDocument.Load(directory + "\\open_dnp3_slave.xml");
                XNamespace ns       = document.Root.GetDefaultNamespace();

                switch (ns.NamespaceName)
                {
                case "http://www.dnp3.org/DNP3/DeviceProfile/Jan2010":

                    DNP3DeviceProfileJan2010Parser parser = new DNP3DeviceProfileJan2010Parser(document);
                    parser.Parse();
                    parser.Configuration.NetworkConfiguration.Version = ns.NamespaceName;

                    universalConfigurations.Add(parser.Configuration.DeviceConfiguration.DeviceName, parser.Configuration.NetworkConfiguration);
                    dataPointsConfigurations.Add(parser.Configuration.DeviceConfiguration.DeviceName, parser.Configuration.DataPointsListConfiguration);
                    break;
                }
            }

            PCCommunicationEngine PCCommEng = new PCCommunicationEngine();

            PCCommEng.ConfigureEngine(basePath, pcConfig);

            PCCommEng.ConfigureEngine(universalConfigurations);

            while (true)
            {
                if (!PCCommEng.CreateChannels())
                {
                    Console.WriteLine("\nStart the simulator then press any key to continue the application.\n");
                    Console.ReadKey();
                    continue;
                }
                break;
            }

            CommandingAcquisitionEngine AcqEngine = new CommandingAcquisitionEngine();

            if (AcqEngine.ConfigureEngine(acqComConfigPath))
            {
                AcqEngine.ConfigureEngine(dataPointsConfigurations);

                AcqEngine.InitializeSimulator();
                cancellationToken = cancellationTokenSource.Token;

                // to do: for IO bound operation you <await an operation which returns a task inside of an async method>
                // await yields control to the caller of the method thet performed await

                TimeSpan consumeReqTime = TimeSpan.FromMilliseconds(10000); // it should be at least twice than acquisition timeout
                requestsConsumer = Task.Factory.StartNew(() => ProcessRequests(PCCommEng, consumeReqTime, cancellationToken),
                                                         TaskCreationOptions.LongRunning);

                TimeSpan consumeAnswTime = TimeSpan.FromMilliseconds(10000);
                answersConsumer = Task.Factory.StartNew(() => ProcessAnswers(AcqEngine, consumeReqTime, cancellationToken),
                                                        TaskCreationOptions.LongRunning);

                // give simulator some time, and when everything is ready start acquisition
                Thread.Sleep(3000);

                acqRequestsProducer = Task.Factory.StartNew(() => AcqEngine.Acquisition());

                try
                {
                    Console.WriteLine("\n....");
                    SCADAService ss = new SCADAService();
                    ss.Start();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("SCADA service failed.");
                    Console.WriteLine(ex.StackTrace);
                    Console.ReadLine();
                    return;
                }
            }
            else
            {
                Console.WriteLine("Configuration of scada failed.");
            }

            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadKey();
            if (cancellationToken.CanBeCanceled)
            {
                // ako nisu bili ni pokrenuti, vrednost taskova je ovde null..
                cancellationTokenSource.Cancel();
            }

            // to do:
            // wait tasks
            AcqEngine.Stop();
            PCCommEng.Stop();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.Title = "SCADA";

            // to do: srediti kasnije, staviti fajlove u neki resource folder ili slicno
            // ako je druga platforma npr. x86 mozda nije dobra putanja!
            string pcConfig         = "RtuConfiguration.xml";
            string scadaConfig      = "ScadaModel.xml";
            string basePath         = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
            string acqComConfigPath = Path.Combine(basePath, scadaConfig);

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken;
            Task requestsConsumer, answersConsumer, acqRequestsProducer;

            PCCommunicationEngine PCCommEng = new PCCommunicationEngine();

            while (true)
            {
                if (!PCCommEng.ConfigureEngine(basePath, pcConfig))
                {
                    Console.WriteLine("\nStart the simulator then press any key to continue the application.\n");
                    Console.ReadKey();
                    continue;
                }
                break;
            }

            CommandingAcquisitionEngine AcqEngine = new CommandingAcquisitionEngine();

            if (AcqEngine.ConfigureEngine(acqComConfigPath))
            {
                AcqEngine.InitializeSimulator();
                cancellationToken = cancellationTokenSource.Token;

                // to do: for IO bound operation you <await an operation which returns a task inside of an async method>
                // await yields control to the caller of the method thet performed await

                TimeSpan consumeReqTime = TimeSpan.FromMilliseconds(10000); // it should be at least twice than acquisition timeout
                requestsConsumer = Task.Factory.StartNew(() => PCCommEng.ProcessRequestsFromQueue(consumeReqTime, cancellationToken),
                                                         TaskCreationOptions.LongRunning);

                TimeSpan consumeAnswTime = TimeSpan.FromMilliseconds(10000);
                answersConsumer = Task.Factory.StartNew(() => AcqEngine.ProcessPCAnwers(consumeReqTime, cancellationToken),
                                                        TaskCreationOptions.LongRunning);

                // give simulator some time, and when everything is ready start acquisition
                Thread.Sleep(3000);

                acqRequestsProducer = Task.Factory.StartNew(() => AcqEngine.Acquisition());

                try
                {
                    Console.WriteLine("\n....");
                    SCADAService ss = new SCADAService();
                    ss.Start();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("SCADA service failed.");
                    Console.WriteLine(ex.StackTrace);
                    Console.ReadLine();
                    return;
                }
            }
            else
            {
                Console.WriteLine("Configuration of scada failed.");
            }

            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadKey();
            if (cancellationToken.CanBeCanceled)
            {
                // ako nisu bili ni pokrenuti, vrednost taskova je ovde null..
                cancellationTokenSource.Cancel();
            }

            // to do:
            // wait tasks
            AcqEngine.Stop();
            PCCommEng.Stop();
        }