Esempio n. 1
0
        public dynamic GetValue(Item61850 item)
        {
            dynamic val;

            switch (item.typeMMS)
            {
            case MmsType.MMS_BIT_STRING:
                val = _connection.ReadBitStringValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_BOOLEAN:
                val = _connection.ReadBooleanValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_FLOAT:
                val = _connection.ReadFloatValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_INTEGER:
                val = _connection.ReadIntegerValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_UNSIGNED:
                val = _connection.ReadValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_STRING:
                val = _connection.ReadStringValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_UTC_TIME:
                val = _connection.ReadTimestampValue(item.path, item.typeFC);
                break;

            default:
                val = _connection.ReadValue(item.path, item.typeFC);
                break;
            }

            return(val);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
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);

                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();
        }
Esempio n. 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
            {
                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();
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            IedConnection con = new IedConnection();

            string hostname;

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

            int port = 102;

            if (args.Length > 1)
            {
                port = Int32.Parse(args [1]);
            }

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

            try
            {
                con.Connect(hostname, port);

                /* Get variable specification of the SGCB (optional) */
                MmsVariableSpecification sgcbVarSpec = con.GetVariableSpecification("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP);

                /* Read SGCB */
                MmsValue sgcbVal = con.ReadValue("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP);

                Console.WriteLine("NumOfSG: {0}", sgcbVal.GetChildValue("NumOfSG", sgcbVarSpec).ToString());
                Console.WriteLine("ActSG: {0}", sgcbVal.GetChildValue("ActSG", sgcbVarSpec).ToString());
                Console.WriteLine("EditSG: {0}", sgcbVal.GetChildValue("EditSG", sgcbVarSpec).ToString());
                Console.WriteLine("CnfEdit: {0}", sgcbVal.GetChildValue("CnfEdit", sgcbVarSpec).ToString());

                /* Set active setting group */
                con.WriteValue("DEMOPROT/LLN0.SGCB.ActSG", FunctionalConstraint.SP, new MmsValue((uint)2));

                /* Set edit setting group */
                con.WriteValue("DEMOPROT/LLN0.SGCB.EditSG", FunctionalConstraint.SP, new MmsValue((uint)1));

                /* Change a setting group value */
                con.WriteValue("DEMOPROT/PTOC1.StrVal.setMag.f", FunctionalConstraint.SE, new MmsValue(1.0f));

                /* Confirm new setting group values */
                con.WriteValue("DEMOPROT/LLN0.SGCB.CnfEdit", FunctionalConstraint.SP, new MmsValue(true));

                /* Read SGCB again */
                sgcbVal = con.ReadValue("DEMOPROT/LLN0.SGCB", FunctionalConstraint.SP);

                Console.WriteLine("ActSG: {0}", sgcbVal.GetChildValue("ActSG", sgcbVarSpec).ToString());


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

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
Esempio n. 6
0
        public ResultSingleModel ReadSingleGroup(string hostip, Int32 port, string FC, string vargroup)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //exctract fc
                data_extract dataExtract  = new data_extract();
                var          FunctionCode = dataExtract.ExtractFC(FC);
                //read group
                MmsValue mmsresult = con.ReadValue(vargroup, FunctionCode);
                //con close
                con.Abort();

                //result list
                dynamic        ValueTuple = mmsresult;
                Read_Result    listresult = null;
                Int16          Quality;
                DateTimeOffset Timestamp;
                List <dynamic> valueArray = new List <dynamic>();

                if (mmsresult.GetType() == MmsType.MMS_STRUCTURE)
                {
                    if (mmsresult.Size() == 4)
                    {
                        ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0));
                        Quality    = dataExtract.ExtractValue(mmsresult.GetElement(2));
                        Timestamp  = dataExtract.ExtractValue(mmsresult.GetElement(3));
                    }
                    else
                    {
                        ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0));
                        Quality    = dataExtract.ExtractValue(mmsresult.GetElement(1));
                        Timestamp  = dataExtract.ExtractValue(mmsresult.GetElement(2));
                    }

                    listresult = new Read_Result
                    {
                        Address   = vargroup,
                        Value     = ValueTuple,
                        Quality   = Quality,
                        Timestamp = Timestamp
                    };
                }
                ResultSingleModel result = new ResultSingleModel()
                {
                    data         = listresult,
                    error        = false,
                    errormessage = null
                };
                //destroy instance
                con.Dispose();
                //result
                return(result);
            }
            catch (IedConnectionException e)
            {
                ResultSingleModel result = new ResultSingleModel()
                {
                    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 instance
                con.Dispose();
                //error result
                return(result);
            }
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            TLSConfiguration tlsConfig = new TLSConfiguration();

            tlsConfig.SetOwnCertificate(new X509Certificate2("client1.cer"));

            tlsConfig.SetOwnKey("client1-key.pem", null);

            // Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false
            tlsConfig.AddCACertificate(new X509Certificate2("root.cer"));

            // Check if the certificate is signed by a provided CA
            tlsConfig.ChainValidation = true;

            // Check that the shown server certificate is in the list of allowed certificates
            tlsConfig.AllowOnlyKnownCertificates = false;

            IedConnection con = new IedConnection(tlsConfig);

            string hostname;

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

            int port = -1;

            if (args.Length > 1)
            {
                port = Int32.Parse(args [1]);
            }

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

            try
            {
                con.Connect(hostname, port);

                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();
        }
Esempio n. 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);

                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);
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

            int port = 102;

            if (args.Length > 1)
            {
                port = Int32.Parse(args [1]);
            }

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

            try
            {
                con.Connect(hostname, port);

                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());

                /* read multiple variables (WARNING: this is not IEC 61850 standard compliant but might
                 * be supported by most servers).
                 */
                MmsConnection mmsConnection = con.GetMmsConnection();

                MmsValue result = mmsConnection.ReadMultipleVariables("simpleIOGenericIO", new List <string>()
                {
                    "GGIO1$ST$Ind1", "GGIO1$ST$Ind1", "GGIO1$ST$Ind1", "GGIO1$ST$Ind1"
                });

                Console.WriteLine(result.ToString());

                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();
        }