Example #1
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);
            }
        }
Example #2
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();
        }
        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);
                }


                // create a new data set

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

                dataSetElements.Add("IEDM1CPUBHKW/DRCS1.ModOnConn.stVal[ST]");
                dataSetElements.Add("IEDM1CPUBHKW/DRCS1.ModOnConn.t[ST]");

                con.CreateDataSet("IEDM1CPUBHKW/LLN0.ds1", dataSetElements);

                // get the directory of the data set
                List <string> dataSetDirectory = con.GetDataSetDirectory("IEDM1CPUBHKW/LLN0.ds1");

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


                // read the values of the newly created data set
                DataSet dataSet = con.ReadDataSetValues("IEDM1CPUBHKW/LLN0.ds1", 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("IEDM1CPUBHKW/LLN0.ds1");

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #4
0
        public ResultDatasetModel ReadMultipleVariableValues(string hostip, Int32 port, string[] valueaddress)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //dataset elements
                List <string> dataSetElements = new List <string>();

                foreach (string address in valueaddress)
                {
                    dataSetElements.Add(address);
                }
                string LDname      = dataSetElements[0].Split("/")[0];
                string LNname      = dataSetElements[0].Split("/")[1].Split(".")[0];
                string DSname      = "ReadValues";
                string dataSetName = LDname + "/" + LNname + "." + DSname;

                //create dataset
                con.CreateDataSet(dataSetName, dataSetElements);
                //read data set
                DataSet mmsresult = con.ReadDataSetValues(dataSetName, null);

                List <string> DataSetDirectory = con.GetDataSetDirectory(dataSetName);
                if (DataSetDirectory != null)
                {
                    //delete dataset
                    con.DeleteDataSet(dataSetName);
                }


                //con close
                con.Abort();

                //get data set values
                List <Dataset_Result> valuelist   = new List <Dataset_Result>();
                data_extract          dataExtract = new data_extract();
                int i = 0;
                foreach (var value in mmsresult.GetValues())
                {
                    var ValueTuple = dataExtract.ExtractValue(value);

                    valuelist.Add(new Dataset_Result
                    {
                        Address = DataSetDirectory[i],
                        Value   = ValueTuple
                    });
                    i += 1;
                }
                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);
            }
        }
Example #5
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);

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

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

                con.CreateDataSet("simpleIOGenericIO/LLN0.ds1", dataSetElements);

                // get the directory of the data set
                List <string> dataSetDirectory = con.GetDataSetDirectory("simpleIOGenericIO/LLN0.ds1");

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

                // read the values of the newly created data set
                DataSet dataSet = con.ReadDataSetValues("simpleIOGenericIO/LLN0.ds1", 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("simpleIOGenericIO/LLN0.ds1");

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message + " reason: " + e.GetIedClientError().ToString());
            }
        }
Example #6
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);

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