コード例 #1
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);

                float setMagF = con.ReadFloatValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP);

                Console.WriteLine("ied1Inverter/ZINV1.OutWSet.setMag.f: " + setMagF);

                setMagF += 1.0f;

                con.WriteValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP, new MmsValue(setMagF));

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine("IED connection excepion: " + e.Message);
            }
        }
コード例 #2
0
 internal ReportControlBlock(string objectReference, IedConnection iedConnection, IntPtr connection)
 {
     self = ClientReportControlBlock_create(objectReference);
     this.iedConnection   = iedConnection;
     this.connection      = connection;
     this.objectReference = objectReference;
 }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: Test.cs プロジェクト: zwinlu/libiec61850
        public void AccessDataModelClientServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            ModelNode ind1 = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.Ind1.stVal");

            Assert.IsTrue(ind1.GetType().Equals(typeof(IEC61850.Server.DataAttribute)));

            IedServer iedServer = new IedServer(iedModel);

            iedServer.Start(10002);

            iedServer.UpdateBooleanAttributeValue((IEC61850.Server.DataAttribute)ind1, true);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            bool stVal = connection.ReadBooleanValue("simpleIOGenericIO/GGIO1.Ind1.stVal", FunctionalConstraint.ST);

            Assert.IsTrue(stVal);

            iedServer.UpdateBooleanAttributeValue((IEC61850.Server.DataAttribute)ind1, false);

            stVal = connection.ReadBooleanValue("simpleIOGenericIO/GGIO1.Ind1.stVal", FunctionalConstraint.ST);

            Assert.IsFalse(stVal);

            connection.Abort();

            iedServer.Stop();

            iedServer.Destroy();
        }
コード例 #5
0
        public ResultDatasetModel ReadDataset(string hostip, Int32 port, string dataaddress)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //read data set
                DataSet mmsresult = con.ReadDataSetValues(dataaddress, null);

                //get data set values
                List <Dataset_Result> valuelist        = new List <Dataset_Result>();
                data_extract          dataExtract      = new data_extract();
                List <string>         DataSetDirectory = con.GetDataSetDirectory(dataaddress);
                int i = 0;
                foreach (MmsValue value in mmsresult.GetValues())
                {
                    var ValueTuple = dataExtract.ExtractValue(value);
                    valuelist.Add(new Dataset_Result
                    {
                        Address = DataSetDirectory[i],
                        Value   = ValueTuple
                    });
                    i += 1;
                }
                //con close
                con.Abort();

                ResultDatasetModel result = new ResultDatasetModel
                {
                    data         = valuelist,
                    error        = false,
                    errormessage = null
                };
                //destroy instance
                con.Dispose();
                //result
                return(result);
            }
            catch (IedConnectionException e)
            {
                ResultDatasetModel result = new ResultDatasetModel()
                {
                    data         = null,
                    error        = true,
                    errormessage = e.Message.ToString()
                };
                //insert logs into db
                Submission dbinsert = new Submission
                {
                    CreatedAt = DateTime.Now,
                    Content   = e.Message.ToString()
                };
                _subSvc.Create(dbinsert);
                //destroy result
                con.Dispose();
                //result
                return(result);
            }
        }
コード例 #6
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

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

            try {
                con.Connect(hostname, 102);

                string rcbReference = "simpleIOGenericIO/LLN0.RP.EventsRCB01";

                ReportControlBlock rcb = con.GetReportControlBlock(rcbReference);

                rcb.GetRCBValues();

                // note: the second parameter is not required!
                rcb.InstallReportHandler(reportHandler, rcb);

                if (rcb.IsBuffered())
                {
                    Console.WriteLine("RCB: " + rcbReference + " is buffered");
                }

                Console.WriteLine(rcb.GetDataSetReference());

                rcb.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY);
                rcb.SetIntgPd(5000);
                rcb.SetRptEna(true);

                rcb.SetRCBValues();

                /* run until Ctrl-C is pressed */
                Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                    e.Cancel = true;
                    ReportingExample.running = false;
                };

                while (running)
                {
                    Thread.Sleep(10);
                }

                con.Abort();
            } catch (IedConnectionException e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #7
0
ファイル: Test.cs プロジェクト: zwinlu/libiec61850
        public void ControlWriteAccessToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal");
            IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal");

            IedServer iedServer = new IedServer(iedModel);

            int opDlTmmsValue = 0;

            iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) {
                opDlTmmsValue = value.ToInt32();
                return(MmsDataAccessError.SUCCESS);
            }, null);

            iedServer.HandleWriteAccess(rsDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) {
                if (value.ToInt32() > 1000)
                {
                    return(MmsDataAccessError.OBJECT_VALUE_INVALID);
                }
                else
                {
                    return(MmsDataAccessError.SUCCESS);
                }
            }, null);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234));


            try {
                connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234));
            }
            catch (IedConnectionException e) {
                Assert.AreEqual(IedClientError.IED_ERROR_OBJECT_VALUE_INVALID, e.GetIedClientError());
            }

            connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999));

            MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms);

            Assert.AreEqual(999, rsDlTmmsValue.ToInt32());

            connection.Abort();

            iedServer.Stop();

            Assert.AreEqual((int)1234, opDlTmmsValue);

            iedServer.Destroy();
        }
コード例 #8
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

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

            try
            {
                con.Connect(hostname, 102);

                Console.WriteLine("Files in server root directory:");
                List <string> serverDirectory = con.GetServerDirectory(true);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine(entry);
                }

                Console.WriteLine();

                Console.WriteLine("File directory tree at server:");
                printFiles(con, "", "");
                Console.WriteLine();

                string filename = "IEDSERVER.BIN";

                Console.WriteLine("Download file " + filename);

                /* Download file from server and write it to a new local file */
                FileStream   fs = new FileStream(filename, FileMode.Create);
                BinaryWriter w  = new BinaryWriter(fs);

                con.GetFile(filename, new IedConnection.GetFileHandler(getFileHandler), w);

                fs.Close();

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

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
コード例 #9
0
        public ResultValueModel WriteValue(string hostip, Int32 port, string varaddress, string FC, dynamic newvalue)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //extract fc
                data_extract dataExtract  = new data_extract();
                var          FunctionCode = dataExtract.ExtractFC(FC);
                var          Value        = dataExtract.ExtractValue(newvalue);
                dynamic      mmsresult    = null;
                //validate datatype
                mmsresult = con.WriteValue(varaddress, FunctionCode, new MmsValue(Value));
                //con close
                con.Abort();
                //result
                Value_Result listresult = new Value_Result
                {
                    Address = varaddress,
                    Value   = mmsresult,
                };
                ResultValueModel result = new ResultValueModel
                {
                    data         = listresult,
                    error        = false,
                    errormessage = null
                };
                //destroy instance
                con.Dispose();
                //result
                return(result);
            }
            catch (IedConnectionException e)
            {
                ResultValueModel result = new ResultValueModel()
                {
                    data         = null,
                    error        = true,
                    errormessage = e.Message.ToString()
                };
                //insert logs into db
                Submission dbinsert = new Submission
                {
                    CreatedAt = DateTime.Now,
                    Content   = e.Message.ToString()
                };
                _subSvc.Create(dbinsert);
                //destroy result
                con.Dispose();
                //result
                return(result);
            }
        }
コード例 #10
0
ファイル: Test.cs プロジェクト: costasvassilakis/libiec61850
        public void ConnectionHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            int handlerCalled   = 0;
            int connectionCount = 0;

            IedServer iedServer = new IedServer(iedModel);

            string ipAddress = null;

            iedServer.SetConnectionIndicationHandler(delegate(IedServer server, ClientConnection clientConnection, bool connected, object parameter) {
                handlerCalled++;
                if (connected)
                {
                    connectionCount++;
                }
                else
                {
                    connectionCount--;
                }

                ipAddress = clientConnection.GetPeerAddress();
            }, null);

            iedServer.Start(10002);

            IedConnection con1 = new IedConnection();

            con1.Connect("localhost", 10002);

            Assert.AreEqual(1, handlerCalled);
            Assert.AreEqual(1, connectionCount);

            IedConnection con2 = new IedConnection();

            con2.Connect("localhost", 10002);

            Assert.AreEqual(2, handlerCalled);
            Assert.AreEqual(2, connectionCount);

            con1.Abort();
            con2.Abort();

            Assert.AreEqual(4, handlerCalled);
            Assert.AreEqual(0, connectionCount);

            Assert.AreEqual("127.0.0.1:", ipAddress.Substring(0, 10));

            iedServer.Stop();

            iedServer.Dispose();
        }
コード例 #11
0
ファイル: Test.cs プロジェクト: costasvassilakis/libiec61850
        public void ControlWriteAccessComplexDAToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model2.cfg");

            IEC61850.Server.DataAttribute setAnVal_setMag = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/LLN0.SetAnVal.setMag");

            IedServer iedServer = new IedServer(iedModel);

            int handlerCalled = 0;

            MmsValue receivedValue = null;

            iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY);

            iedServer.HandleWriteAccessForComplexAttribute(setAnVal_setMag, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) {
                receivedValue = value;
                handlerCalled++;
                return(MmsDataAccessError.SUCCESS);
            }, null);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            MmsValue complexValue = MmsValue.NewEmptyStructure(1);

            complexValue.SetElement(0, new MmsValue((float)1.0));

            connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag", FunctionalConstraint.SP, complexValue);

            Assert.NotNull(receivedValue);
            Assert.AreEqual(MmsType.MMS_STRUCTURE, receivedValue.GetType());
            Assert.AreEqual(1.0, receivedValue.GetElement(0).ToFloat());

            receivedValue.Dispose();

            receivedValue = null;

            connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag.f", FunctionalConstraint.SP, new MmsValue((float)2.0));

            Assert.NotNull(receivedValue);
            Assert.AreEqual(MmsType.MMS_FLOAT, receivedValue.GetType());
            Assert.AreEqual(2.0, receivedValue.ToFloat());

            connection.Abort();

            iedServer.Stop();

            iedServer.Dispose();
        }
コード例 #12
0
        public static void printFiles(IedConnection con, string prefix, string parent)
        {
            List<FileDirectoryEntry> files = con.GetFileDirectory (parent);

            foreach (FileDirectoryEntry file in files) {
                Console.WriteLine(prefix + file.GetFileName() + "\t" + file.GetFileSize() + "\t" +
                                  MmsValue.MsTimeToDateTimeOffset(file.GetLastModified()));

                if (file.GetFileName().EndsWith("/")) {
                    printFiles (con, prefix + "  ", parent + file.GetFileName());
                }
            }
        }
コード例 #13
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

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

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

            try
            {
                con.Connect(hostname, 102);

                Console.WriteLine ("Files in server root directory:");
                List<string> serverDirectory = con.GetServerDirectory(true);

                foreach (string entry in serverDirectory) {
                    Console.WriteLine(entry);
                }

                Console.WriteLine();

                Console.WriteLine ("File directory tree at server:");
                printFiles(con, "", "");
                Console.WriteLine();

                string filename = "IEDSERVER.BIN";

                Console.WriteLine("Download file " + filename);

                /* Download file from server and write it to a new local file */
                FileStream fs = new FileStream(filename, FileMode.Create);
                BinaryWriter w = new BinaryWriter(fs);

                con.GetFile(filename, new IedConnection.GetFileHandler(getFileHandler), w);

                fs.Close();

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #14
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();
        }
コード例 #15
0
ファイル: RelayManagment2.cs プロジェクト: benvert/pfe
 private void RelayManagment_Load(object sender, EventArgs e)
 {
     // DbReport = MesVariables.DbReport;  //
     Dbisopen            = false;
     IEDConnected        = false;
     OPCconnected        = false;
     firstUse            = true;
     Valeur              = Class.SPCS;
     database_connection = new SQLiteConnection("Data Source=:memory:;Version=3;;cache=shared");
     ConnectToIED        = new IedConnection();
     param = ConnectToIED.GetConnectionParameters();
     initialiser();
     password = "******";
     hostname = "192.168.1.65";
 }
コード例 #16
0
        public static void printFiles(IedConnection con, string prefix, string parent)
        {
            List <FileDirectoryEntry> files = con.GetFileDirectory(parent);

            foreach (FileDirectoryEntry file in files)
            {
                Console.WriteLine(prefix + file.GetFileName() + "\t" + file.GetFileSize() + "\t" +
                                  MmsValue.MsTimeToDateTimeOffset(file.GetLastModified()));

                if (file.GetFileName().EndsWith("/"))
                {
                    printFiles(con, prefix + "  ", parent + file.GetFileName());
                }
            }
        }
コード例 #17
0
            internal ControlObject(string objectReference, IntPtr connection, IedConnection iedConnection)
            {
                this.iedConnection = iedConnection;

                this.self = ControlObjectClient_create(objectReference, connection);

                if (this.self == System.IntPtr.Zero)
                {
                    throw new IedConnectionException("Control object not found", 0);
                }

                intCommandTerminationHandler = new InternalCommandTerminationHandler(MyCommandTerminationHandler);

                ControlObjectClient_setCommandTerminationHandler(self, intCommandTerminationHandler, self);
            }
コード例 #18
0
ファイル: Test.cs プロジェクト: zwinlu/libiec61850
        public void ControlHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1");

            Assert.IsNotNull(spcso1);

            int handlerCalled = 0;

            IedServer iedServer = new IedServer(iedModel);

            iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) {
                byte [] orIdent = action.GetOrIdent();

                string orIdentStr = System.Text.Encoding.UTF8.GetString(orIdent, 0, orIdent.Length);

                Assert.AreEqual("TEST1234", orIdentStr);
                Assert.AreEqual(OrCat.MAINTENANCE, action.GetOrCat());

                Assert.AreSame(spcso1, action.GetControlObject());

                handlerCalled++;
                return(ControlHandlerResult.OK);
            }, null);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            ControlObject controlClient = connection.CreateControlObject("simpleIOGenericIO/GGIO1.SPCSO1");

            controlClient.SetOrigin("TEST1234", OrCat.MAINTENANCE);

            Assert.IsNotNull(controlClient);

            controlClient.Operate(true);

            connection.Abort();

            Assert.AreEqual(1, handlerCalled);

            iedServer.Stop();

            iedServer.Destroy();
        }
コード例 #19
0
ファイル: MMSService.cs プロジェクト: destroyer78/Ordos
        /// <summary>
        /// Download each file in the download list.
        /// </summary>
        /// <param name="iedConnection"></param>
        /// <param name="device"></param>
        /// <param name="downloadableFileList"></param>
        private static void DownloadComtradeFiles(IedConnection iedConnection, Device device, IEnumerable <IEDFile> downloadableFileList)
        {
            foreach (var iedFile in downloadableFileList)
            {
                Logger.Info($"{device} - Downloading file: {iedFile.FileName} ({iedFile.FileSize})");
                //TODO: Check if the GetTemporaryDownloadPath works on both IEDs: 670, 615;
                //var destinationFilename = PathService.GetTemporaryDownloadPath(device, FileName.ReplaceAltDirectorySeparator().CleanFileName());
                var destinationFilename = PathHelper.GetTemporaryDownloadPath(device, iedFile.FileName.GetDestinationFilename());

                using (var fs = new FileStream(destinationFilename, FileMode.Create, FileAccess.ReadWrite))
                    using (var w = new BinaryWriter(fs))
                    {
                        iedConnection.GetFile(iedFile.FileName, GetFileHandler, w);
                    }
            }
        }
コード例 #20
0
ファイル: Test.cs プロジェクト: costasvassilakis/libiec61850
        public void WriteAccessPolicy()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal");
            IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal");

            IedServer iedServer = new IedServer(iedModel);

            iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) {
                return(MmsDataAccessError.SUCCESS);
            }, null);


            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_ALLOW);

            connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234));

            iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY);

            connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234));

            try {
                connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999));
            }
            catch (IedConnectionException e) {
                Assert.AreEqual(IedClientError.IED_ERROR_ACCESS_DENIED, e.GetIedClientError());
            }

            MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms);

            Assert.AreEqual(1234, rsDlTmmsValue.ToInt32());

            connection.Abort();

            iedServer.Stop();

            iedServer.Dispose();
        }
コード例 #21
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();
        }
コード例 #22
0
ファイル: MMSService.cs プロジェクト: destroyer78/Ordos
        private static IEnumerable <IEDFile> GetDownloadableFileList(IedConnection iedConnection, Device device, string directoryName)
        {
            //Get Files from Device:
            var files = iedConnection.GetFileDirectory(directoryName);

            var downloadableFileList = new List <IEDFile>();

            var logDirectoryName = string.IsNullOrWhiteSpace(directoryName) ? "Root" : directoryName;

            Logger.Trace($"{device} - List IED Files on: {logDirectoryName}");

            //Foreach file in the Device:
            //Check if file is a directoty or a file
            //If directory, recursive call with directory name
            //If file, and a valid download extension, add file to downloadable list
            foreach (var file in files)
            {
                var filename = file.GetFileName();

                Logger.Trace($"{device} - {directoryName}{filename}");

                if (filename.IsDirectory())
                {
                    downloadableFileList.AddRange(GetDownloadableFileList(iedConnection, device, directoryName + filename));
                }
                else
                {
                    if (!filename.IsDownloadable())
                    {
                        continue;
                    }

                    var iedFile = new IEDFile()
                    {
                        CreationTime = file.GetLastModified(),
                        FileSize     = file.GetFileSize(),
                        FileName     = directoryName + filename,
                    };
                    downloadableFileList.Add(iedFile);
                }
            }
            return(downloadableFileList);
        }
コード例 #23
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);

                string objectReference = "IEDM1CPUBHKW/DRCC1.DERStr";

                ControlObject control = con.CreateControlObject(objectReference);

                ControlModel controlModel = control.GetControlModel();

                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                if (!control.Operate(true))
                {
                    Console.WriteLine("operate failed!");
                }



                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #24
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);
            }
        }
コード例 #25
0
ファイル: m61850.cs プロジェクト: victor3359/PingIP-Service
        public m61850(string host)
        {
            _host = host;
            _conn = new IedConnection();
            Console.WriteLine("Connect to " + _host);

            try
            {
                IedConnect();

                Console.WriteLine("Files in server root directory:");
                List <string> serverDirectory = _conn.GetServerDirectory(true);

                foreach (string entry in serverDirectory)
                {
                    Console.WriteLine(entry);
                }

                Console.WriteLine();
                Console.WriteLine("File directory tree at server:");
                printFiles(_conn, "", "");
                Console.WriteLine();

                if (!Directory.Exists(@"COMTRADE"))
                {
                    Directory.CreateDirectory(@"COMTRADE");
                }
                DirectoryInfo di = new DirectoryInfo(@"COMTRADE");
                foreach (var fi in di.GetFiles())
                {
                    fileList.Add($"/COMTRADE/{fi.Name}");
                }
                _conn.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }

            //_conn.Dispose();
        }
コード例 #26
0
        public static void printFiles(IedConnection con, string prefix, string parent)
        {
            bool moreFollows = false;

            List <FileDirectoryEntry> files = con.GetFileDirectoryEx(parent, null, out moreFollows);

            foreach (FileDirectoryEntry file in files)
            {
                Console.WriteLine(prefix + file.GetFileName() + "\t" + file.GetFileSize() + "\t" +
                                  MmsValue.MsTimeToDateTimeOffset(file.GetLastModified()));

                if (file.GetFileName().EndsWith("/"))
                {
                    printFiles(con, prefix + "  ", parent + file.GetFileName());
                }
            }

            if (moreFollows)
            {
                Console.WriteLine("-- MORE FILES AVAILABLE --");
            }
        }
コード例 #27
0
ファイル: Test.cs プロジェクト: zwinlu/libiec61850
        public void ReadNonExistingObject()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IedServer iedServer = new IedServer(iedModel);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            MmsValue value = connection.ReadValue("simpleIOGenericIO/GGIO1.SPCSO1.stVal", FunctionalConstraint.MX);

            Assert.IsNotNull(value);

            Assert.AreEqual(MmsType.MMS_DATA_ACCESS_ERROR, value.GetType());

            iedServer.Stop();

            iedServer.Destroy();
        }
コード例 #28
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);

                float setMagF = con.ReadFloatValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP);

                Console.WriteLine("ied1Inverter/ZINV1.OutWSet.setMag.f: " + setMagF);

                setMagF += 1.0f;

                con.WriteValue("ied1Inverter/ZINV1.OutWSet.setMag.f", FunctionalConstraint.SP, new MmsValue(setMagF));

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine("IED connection excepion: " + e.Message);
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
コード例 #29
0
ファイル: Test.cs プロジェクト: zwinlu/libiec61850
        public void ConnectToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IedServer iedServer = new IedServer(iedModel);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            List <string> list = connection.GetServerDirectory();

            Assert.IsNotEmpty(list);

            Assert.AreEqual(list.ToArray() [0], "simpleIOGenericIO");

            iedServer.Stop();

            iedServer.Destroy();
        }
コード例 #30
0
ファイル: SclServer.cs プロジェクト: ttgzs/iedexplorer
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        // Test implementations
        public static void TestClient()
        {
            IedConnection con = new IedConnection();

            try
            {
                System.Windows.Forms.MessageBox.Show("Server Start");
                con.Connect("localhost", 102);

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

                foreach (string entry in serverDirectory)
                {
                    System.Windows.Forms.MessageBox.Show("LD: " + entry);
                }
                con.Abort();
            }
            catch (IedConnectionException e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
            con.Dispose();
        }
コード例 #31
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);
            }
        }
コード例 #32
0
        public void ControlHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1");

            Assert.IsNotNull(spcso1);

            int handlerCalled = 0;

            IedServer iedServer = new IedServer(iedModel);

            iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) {
                handlerCalled++;
                return(ControlHandlerResult.OK);
            }, null);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            ControlObject controlClient = connection.CreateControlObject("simpleIOGenericIO/GGIO1.SPCSO1");

            Assert.IsNotNull(controlClient);

            controlClient.Operate(true);

            connection.Abort();

            Assert.AreEqual(1, handlerCalled);

            iedServer.Stop();

            iedServer.Destroy();
        }
コード例 #33
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);

                string rcbReference1 = "simpleIOGenericIO/LLN0.RP.EventsRCB01";
                string rcbReference2 = "simpleIOGenericIO/LLN0.RP.EventsIndexed01";
                string rcbReference3 = "simpleIOGenericIO/LLN0.BR.Measurements01";

                ReportControlBlock rcb1 = con.GetReportControlBlock(rcbReference1);
                ReportControlBlock rcb2 = con.GetReportControlBlock(rcbReference2);
                ReportControlBlock rcb3 = con.GetReportControlBlock(rcbReference3);

                rcb1.GetRCBValues();

                // note: the second parameter is not required!
                rcb1.InstallReportHandler(reportHandler, rcb1);

                if (rcb1.IsBuffered())
                    Console.WriteLine ("RCB: " + rcbReference1 + " is buffered");

                rcb1.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY);
                rcb1.SetIntgPd(5000);
                rcb1.SetRptEna(true);

                rcb1.SetRCBValues();

                rcb2.GetRCBValues();

                if (rcb2.IsBuffered())
                    Console.WriteLine ("RCB: " + rcbReference2 + " is buffered");

                rcb2.InstallReportHandler(reportHandler, rcb2);

                rcb2.SetOptFlds(ReportOptions.REASON_FOR_INCLUSION | ReportOptions.SEQ_NUM | ReportOptions.TIME_STAMP |
                    ReportOptions.CONF_REV | ReportOptions.ENTRY_ID | ReportOptions.DATA_REFERENCE | ReportOptions.DATA_SET);
                rcb2.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY);
                rcb2.SetIntgPd(2000);
                rcb2.SetRptEna(true);

                rcb2.SetRCBValues();

                rcb3.GetRCBValues();

                if (rcb3.IsBuffered())
                    Console.WriteLine ("RCB: " + rcbReference3 + " is buffered");

                rcb3.InstallReportHandler(reportHandler, rcb2);

                rcb3.SetOptFlds(ReportOptions.REASON_FOR_INCLUSION | ReportOptions.SEQ_NUM | ReportOptions.TIME_STAMP |
                                ReportOptions.CONF_REV | ReportOptions.ENTRY_ID | ReportOptions.DATA_REFERENCE | ReportOptions.DATA_SET);
                rcb3.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY);
                rcb3.SetIntgPd(2000);
                rcb3.SetRptEna(true);

                rcb3.SetRCBValues();

                /* run until Ctrl-C is pressed */
                Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                    e.Cancel = true;
                    ReportingExample.running = false;
                };

                while (running) {
                    Thread.Sleep(10);
                }

                con.Abort ();
            } catch (IedConnectionException e) {
                Console.WriteLine (e.Message);
            }
        }
コード例 #34
0
ファイル: DataSetExample.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
            {
                con.Connect(hostname, 102);

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

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

                // create a new data set

                List<string> dataSetElements = new List<string>();

                string dataSetName = "simpleIOGenericIO/UNKNOWN.ds1";

                //string dataSetName = "simpleIOGenericIO/LLN0.ds1";

                dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]");
                dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]");

                con.CreateDataSet(dataSetName, dataSetElements);

                // get the directory of the data set
                List<string> dataSetDirectory = con.GetDataSetDirectory(dataSetName);

                foreach (string entry in dataSetDirectory)
                {
                    Console.WriteLine("DS element: " + entry);
                }

                // read the values of the newly created data set
                DataSet dataSet = con.ReadDataSetValues(dataSetName, null);

                MmsValue dataSetValues = dataSet.GetValues();

                Console.WriteLine ("Data set contains " + dataSetValues.Size() + " elements");

                foreach (MmsValue value in dataSetValues) {
                    Console.WriteLine("  DS value: " + value + " type: " + value.GetType());
                }

                // delete the data set
                con.DeleteDataSet(dataSetName);

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString());
               }
        }
コード例 #35
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();
        }
コード例 #36
0
ファイル: ModelBrowsing.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";

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

                con.Connect(hostname, 102);

                Console.WriteLine("Connected.");

                MmsConnection mmsCon = con.GetMmsConnection();

                MmsServerIdentity identity = mmsCon.GetServerIdentity();

                Console.WriteLine("Vendor:   " + identity.vendorName);
                Console.WriteLine("Model:    " + identity.modelName);
                Console.WriteLine("Revision: " + identity.revision);

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

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

                    List<string> lnNames = con.GetLogicalDeviceDirectory(ldName);

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

                        string logicalNodeReference = ldName + "/" + lnName;

                        // discover data objects
                        List<string> dataObjects =
                            con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_DATA_OBJECT);

                        foreach (string dataObject in dataObjects) {
                            Console.WriteLine("    DO: " + dataObject);

                            List<string> dataDirectory = con.GetDataDirectoryFC(logicalNodeReference + "." + dataObject);

                            foreach (string dataDirectoryElement in dataDirectory) {

                                string daReference = logicalNodeReference + "." + dataObject + "." + ObjectReference.getElementName(dataDirectoryElement);

                                // get the type specification of a variable
                                MmsVariableSpecification specification = con.GetVariableSpecification(daReference,  ObjectReference.getFC(dataDirectoryElement));

                                Console.WriteLine ("      DA/SDO: [" + ObjectReference.getFC(dataDirectoryElement) + "] " +
                                                   ObjectReference.getElementName(dataDirectoryElement) + " : " + specification.GetType()
                                                   + "(" + specification.Size() + ")");

                                if (specification.GetType() == MmsType.MMS_STRUCTURE) {
                                    foreach (MmsVariableSpecification elementSpec in specification) {
                                        Console.WriteLine("           " + elementSpec.GetName() + " : " + elementSpec.GetType());
                                    }
                                }
                            }

                        }

                        // discover data sets
                        List<string> dataSets =
                            con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_DATA_SET);

                        foreach (string dataSet in dataSets) {
                            Console.WriteLine("    Dataset: " + dataSet);
                        }

                        // discover unbuffered report control blocks
                        List<string> urcbs =
                            con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_URCB);

                        foreach (string urcb in urcbs) {
                            Console.WriteLine("    URCB: " + urcb);
                        }

                        // discover buffered report control blocks
                        List<string> brcbs =
                            con.GetLogicalNodeDirectory(logicalNodeReference, ACSIClass.ACSI_CLASS_BRCB);

                        foreach (string brcb in brcbs) {
                            Console.WriteLine("    BRCB: " + brcb);
                        }

                    }

                }

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #37
0
ファイル: Control.cs プロジェクト: feuvan/libiec61850
            internal ControlObject(string objectReference, IntPtr connection, IedConnection iedConnection)
            {
                this.iedConnection = iedConnection;

                this.controlObject = ControlObjectClient_create(objectReference, connection);

                if (this.controlObject == System.IntPtr.Zero)
                    throw new IedConnectionException("Control object not found", 0);

                InternalCommandTerminationHandler intCommandTerminationHandler = new InternalCommandTerminationHandler (MyCommandTerminationHandler);

                ControlObjectClient_setCommandTerminationHandler(controlObject, intCommandTerminationHandler, controlObject);
            }
コード例 #38
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 = "10.0.2.2";

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

            try
            {
                con.Connect(hostname, 102);

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

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

                List<string> lnDirectory = con.GetLogicalNodeDirectory("simpleIOGenericIO/LLN0", ACSIClass.ACSI_CLASS_DATA_SET);

                foreach (string entry in lnDirectory)
                {
                    Console.WriteLine("Dataset: " + entry);
                }

                string vendor = con.ReadStringValue ("simpleIOGenericIO/LLN0.NamPlt.vendor", FunctionalConstraint.DC);
                Console.WriteLine ("Vendor: " + vendor);

                /* read FCDO */
                MmsValue value = con.ReadValue("simpleIOGenericIO/GGIO1.AnIn1", FunctionalConstraint.MX);

                if (value.GetType() == MmsType.MMS_STRUCTURE)
                {
                    Console.WriteLine("Value is of complex type");

                    for (int i = 0; i < value.Size(); i++)
                    {
                        Console.WriteLine("  element: " + value.GetElement(i).GetType());
                        if (value.GetElement(i).GetType() == MmsType.MMS_UTC_TIME)
                        {
                            Console.WriteLine("   -> " + value.GetElement(i).GetUtcTimeAsDateTimeOffset());
                        }
                    }
                }

                DataSet dataSet = con.ReadDataSetValues("simpleIOGenericIO/LLN0.Events", null);

                Console.WriteLine("Read data set " + dataSet.GetReference());

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

            System.Threading.Thread.Sleep(2000);
        }
コード例 #39
0
ファイル: MMSService.cs プロジェクト: destroyer78/Ordos
        /// <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!");
            }
        }
コード例 #40
0
ファイル: ControlExample.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
            {
                con.Connect(hostname, 102);

                /* direct control with normal security or SBO with normal security */
                string objectReference = "simpleIOGenericIO/GGIO1.SPCSO1";

                ControlObject control = con.CreateControlObject(objectReference);

                ControlModel controlModel = control.GetControlModel();

                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                switch (controlModel) {

                case ControlModel.STATUS_ONLY:
                    Console.WriteLine("Control is status-only!");
                    break;

                case ControlModel.DIRECT_NORMAL:
                case ControlModel.DIRECT_ENHANCED:
                    if (!control.Operate(true))
                        Console.WriteLine("operate failed!");
                    else
                        Console.WriteLine("operated successfully!");
                    break;

                case ControlModel.SBO_NORMAL:
                case ControlModel.SBO_ENHANCED:

                    if (control.Select()) {
                        if (!control.Operate(true))
                            Console.WriteLine("operate failed!");
                        else
                            Console.WriteLine("operated successfully!");
                    }
                    else
                        Console.WriteLine("Select failed!");

                    break;
                }

                /* direct control with enhanced security */
                objectReference = "simpleIOGenericIO/GGIO1.SPCSO3";
                control = con.CreateControlObject(objectReference);

                controlModel = control.GetControlModel();
                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                if (controlModel == ControlModel.DIRECT_ENHANCED) {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);

                    control.Operate(true);

                    Thread.Sleep(1000);
                }

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
               }
        }
コード例 #41
0
ファイル: Main.cs プロジェクト: somma/dslink-c-iec61850
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

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


            try
            {
                con.Connect(hostname, 102);

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

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


                List <string> lnDirectory = con.GetLogicalNodeDirectory("simpleIOGenericIO/LLN0", ACSIClass.ACSI_CLASS_DATA_SET);

                foreach (string entry in lnDirectory)
                {
                    Console.WriteLine("Dataset: " + entry);
                }

                string vendor = con.ReadStringValue("simpleIOGenericIO/LLN0.NamPlt.vendor", FunctionalConstraint.DC);
                Console.WriteLine("Vendor: " + vendor);

                /* read FCDO */
                MmsValue value = con.ReadValue("simpleIOGenericIO/GGIO1.AnIn1", FunctionalConstraint.MX);

                if (value.GetType() == MmsType.MMS_STRUCTURE)
                {
                    Console.WriteLine("Value is of complex type");

                    for (int i = 0; i < value.Size(); i++)
                    {
                        Console.WriteLine("  element: " + value.GetElement(i).GetType());
                        if (value.GetElement(i).GetType() == MmsType.MMS_UTC_TIME)
                        {
                            Console.WriteLine("   -> " + value.GetElement(i).GetUtcTimeAsDateTimeOffset());
                        }
                    }
                }

                DataSet dataSet = con.ReadDataSetValues("simpleIOGenericIO/LLN0.Events", null);

                Console.WriteLine("Read data set " + dataSet.GetReference());

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

            System.Threading.Thread.Sleep(2000);

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
コード例 #42
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
            {
                con.Connect(hostname, 102);

                // create a new data set

                List<string> dataSetElements = new List<string>();

                dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn1.mag.f[MX]");
                dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn2.mag.f[MX]");
                dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn3.mag.f[MX]");
                dataSetElements.Add("simpleIOGenericIO/GGIO1.AnIn4.mag.f[MX]");

                // permanent (domain specific) data set
                //string dataSetReference = "simpleIOGenericIO/LLN0.ds1";

                // temporary (association specific) data set
                string dataSetReference = "@newds";

                // Note: this function will throw an exception when a data set with the same name already exists
                con.CreateDataSet(dataSetReference, dataSetElements);

                // reconfigure existing RCB with new data set

                string rcbReference = "simpleIOGenericIO/LLN0.RP.EventsRCB01";

                ReportControlBlock rcb = con.GetReportControlBlock(rcbReference);

                rcb.GetRCBValues();

                // note: the second parameter is not required!
                rcb.InstallReportHandler(reportHandler, rcb);

                string rcbDataSetReference = dataSetReference.Replace('.', '$');

                rcb.SetDataSetReference(rcbDataSetReference);
                rcb.SetTrgOps(TriggerOptions.DATA_CHANGED | TriggerOptions.INTEGRITY);
                rcb.SetIntgPd(5000);
                rcb.SetRptEna(true);

                rcb.SetRCBValues();

                /* run until Ctrl-C is pressed */
                Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                    e.Cancel = true;
                    running = false;
                };

                while (running) {
                    Thread.Sleep(1000);
                }

                // delete the data set
                con.DeleteDataSet(dataSetReference);

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString());
            }
        }