예제 #1
0
파일: Main.cs 프로젝트: feuvan/libiec61850
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

            if (args.Length > 0)
                hostname = args[0];
            else
                hostname = "localhost";

            Console.WriteLine("Connect to " + hostname);

            try
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

                parameters.UsePasswordAuthentication("top secret");

                con.Connect(hostname, 102);

                List<string> serverDirectory = con.GetServerDirectory(false);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine("LD: " + entry);
                }

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
파일: Main.cs 프로젝트: zjm1060/libiec61850
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

            if (args.Length > 0)
            {
                hostname = args[0];
            }
            else
            {
                hostname = "localhost";
            }

            Console.WriteLine("Connect to " + hostname);


            try
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

                parameters.SetRemoteAddresses(1, new byte[] { 0x00, 0x01 }, new byte[] { 0x00, 0x01, 0x02, 0x03 });

                con.ConnectTimeout = 10000;

                con.GetMmsConnection().SetLocalDetail(1200);

                con.Connect(hostname, 102);

                Console.WriteLine("Negotiated PDU size: " + con.GetMmsConnection().GetLocalDetail());

                List <string> serverDirectory = con.GetServerDirectory(false);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine("LD: " + entry);
                }

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
예제 #3
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

            if (args.Length > 0)
            {
                hostname = args[0];
            }
            else
            {
                hostname = "localhost";
            }

            Console.WriteLine("Connect to " + hostname);


            try
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

                parameters.UsePasswordAuthentication("top secret");

                con.Connect(hostname, 102);

                List <string> serverDirectory = con.GetServerDirectory(false);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine("LD: " + entry);
                }

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }


            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
예제 #4
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

            if (args.Length > 0)
            {
                hostname = args[0];
            }
            else
            {
                hostname = "localhost";
            }

            Console.WriteLine("Connect to " + hostname);


            try
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

                parameters.SetRemoteAddresses(1, 1, new byte[] { 0x00, 0x01, 0x02, 0x03 });

                con.ConnectTimeout = 10000;

                con.Connect(hostname, 102);

                List <string> serverDirectory = con.GetServerDirectory(false);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine("LD: " + entry);
                }

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #5
0
파일: Main.cs 프로젝트: feuvan/libiec61850
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

            if (args.Length > 0)
                hostname = args[0];
            else
                hostname = "localhost";

            Console.WriteLine("Connect to " + hostname);

            try
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

                parameters.SetRemoteAddresses(1,1, new byte[] {0x00, 0x01, 0x02, 0x03});

                con.ConnectTimeout = 10000;

                con.Connect(hostname, 102);

                List<string> serverDirectory = con.GetServerDirectory(false);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine("LD: " + entry);
                }

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// Connect and read IED Comtrade Files.
        /// </summary>
        /// <param name="device">Device to read</param>
        private static void ProcessDeviceComtradeFiles(Device device)
        {
            var iedConnection = new IedConnection
            {
                ConnectTimeout = 20000
            };

            try
            {
                Logger.Info($"{device} - Connecting to Device");

                iedConnection.Connect(device.IPAddress);

                Logger.Info($"{device} - Connection Successful");

                Logger.Info($"{device} - Get IED Files");

                //Download a list of files in the IED:
                //Uses string.Empty as main root of the IED.
                var downloadableFileList = GetDownloadableFileList(iedConnection, device, string.Empty);

                Logger.Info($"{device} - {downloadableFileList.Count()} Files Found");

                //Remove the files that have been already downloaded before:
                //It will filter the files that are not in the DB.
                var filteredDownloadableFileList = DatabaseService.FilterExistingFiles(device, downloadableFileList);

                Logger.Info($"{device} - {filteredDownloadableFileList.Count()} New Files Found");

                if (filteredDownloadableFileList.Count() > 0)
                {
                    Logger.Info($"{device} - Downloading Comtrade files");

                    DownloadComtradeFiles(iedConnection, device, filteredDownloadableFileList);

                    Logger.Info($"{device} - Reading files");

                    //Using the recently donwloaded files:
                    //(Each temporary folder is unique for each IED)
                    var temporaryFolder        = PathHelper.GetTemporaryDownloadFolder(device);
                    var temporaryComtradeFiles = ComtradeHelper.ParseComtradeFiles(device, temporaryFolder);

                    Logger.Info($"{device} - Saving files to the DB");

                    DatabaseService.StoreComtradeFilesToDatabase(device, temporaryComtradeFiles);

                    DatabaseService.StoreIEDFilesToDatabase(device, filteredDownloadableFileList);

                    Logger.Info($"{device} - Exporting files");

                    ExportService.ExportDisturbanceRecordings(device, temporaryComtradeFiles);

                    Logger.Info($"{device} - Removing temporary files");

                    PathHelper.RemoveTemporaryFiles(device);
                }
                Logger.Info($"{device} - Disconnecting...");

                //Close connection:
                iedConnection.Release();
            }
            catch (IedConnectionException e)
            {
                Logger.Fatal($"Client Error: {e.GetIedClientError()}");
                Logger.Fatal($"Error Code: {e.GetErrorCode()}");
                Logger.Fatal($"IED Connection Exception: {e}");
            }
            catch (Exception e)
            {
                Logger.Fatal(e);
            }
            finally
            {
                try
                {
                    //libIEC61850: Dispose connection after use.
                    iedConnection.Dispose();
                }
                catch (IedConnectionException e)
                {
                    Logger.Fatal($"Dispose Client Error: {e.GetIedClientError()}");
                    Logger.Fatal($"Dispose Error Code: {e.GetErrorCode()}");
                    Logger.Fatal($"Dispose IED Connection Exception: {e}");
                }
                catch (Exception e)
                {
                    Logger.Fatal(e);
                }
                Logger.Info($"{device} - Disconnected!");
            }
        }
예제 #7
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

            if (args.Length > 0)
            {
                hostname = args[0];
            }
            else
            {
                hostname = "localhost";
            }

            Console.WriteLine("Connect to " + hostname);


            try
            {
                con.Connect(hostname, 102);

                Console.WriteLine("Negotiated PDU size: " + con.GetMmsConnection().GetLocalDetail());

                List <string> serverDirectory = con.GetServerDirectory(false);

                foreach (string deviceName in serverDirectory)
                {
                    Console.WriteLine("LD: " + deviceName);
                    List <string> deviceDirectory = con.GetLogicalDeviceDirectory(deviceName);

                    foreach (string lnName in deviceDirectory)
                    {
                        Console.WriteLine("  LN: " + lnName);

                        List <string> lcbs = con.GetLogicalNodeDirectory(deviceName + "/" + lnName, IEC61850.Common.ACSIClass.ACSI_CLASS_LCB);

                        foreach (string lcbName in lcbs)
                        {
                            Console.WriteLine("    LCB: " + lcbName);

                            MmsValue lcbValues = con.ReadValue(deviceName + "/" + lnName + "." + lcbName, FunctionalConstraint.LG);

                            Console.WriteLine("      values: " + lcbValues.ToString());
                        }

                        List <string> logs = con.GetLogicalNodeDirectory(deviceName + "/" + lnName, IEC61850.Common.ACSIClass.ACSI_CLASS_LOG);

                        foreach (string logName in logs)
                        {
                            Console.WriteLine("    LOG: " + logName);
                        }
                    }
                }

                bool moreFollows;

                Console.WriteLine("\nQueryLogAfter:");

                List <MmsJournalEntry> journalEntries = con.QueryLogAfter("simpleIOGenericIO/LLN0$EventLog",
                                                                          new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, out moreFollows);

                PrintJournalEntries(journalEntries);

                Console.WriteLine("\nQueryLogByTime:");

                journalEntries = con.QueryLogByTime("simpleIOGenericIO/LLN0$EventLog",
                                                    new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                                                    DateTime.UtcNow,
                                                    out moreFollows);

                PrintJournalEntries(journalEntries);

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }