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

                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();
        }
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
            {
                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();
        }
Esempio n. 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
            {
                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();
        }
        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();
        }
Esempio n. 7
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        // 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();
        }
Esempio n. 8
0
        public ResultDatasetModel ReadRCB(string hostip, Int32 port, string dataaddress)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //read data set
                // 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 = "@ss";

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

                // Console.WriteLine(mmsresult.GetRCBValues());
                List <Dataset_Result> valuelist   = new List <Dataset_Result>();
                data_extract          dataExtract = new data_extract();

                //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);
            }
        }
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.MaxPduSize = 1000;

                con.StateChanged = delegate(IedConnection connection, IedConnectionState newState) {
                    Console.WriteLine("state change: " + newState.ToString());
                };

                con.Connect(hostname, port);

                AutoResetEvent waitForCallback = new AutoResetEvent(false);

                List <string> ldList = null;

                con.GetServerDirectoryAsync(ldList, null, delegate(uint invokeId, object parameter, IedClientError err, System.Collections.Generic.List <string> nameList, bool moreFollows) {
                    if (nameList != null)
                    {
                        ldList = nameList;
                    }
                    else
                    {
                        Console.WriteLine("Get server directory error: " + err.ToString());
                    }

                    waitForCallback.Set();
                }, null);

                waitForCallback.WaitOne();

                if (ldList != null)
                {
                    string firstLdName = null;

                    Console.WriteLine("Server directory:");

                    foreach (string ldName in ldList)
                    {
                        Console.WriteLine("  LD: " + ldName);
                        if (firstLdName == null)
                        {
                            firstLdName = ldName;
                        }
                    }

                    bool   moreVariabesFollows = true;
                    string lastVariableName    = null;

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

                    while (moreVariabesFollows)
                    {
                        waitForCallback.Reset();

                        con.GetLogicalDeviceVariablesAsync(variablesList, firstLdName, lastVariableName, delegate(uint invokeId, object parameter, IedClientError err, List <string> nameList, bool moreFollows) {
                            if (nameList != null)
                            {
                                if (moreFollows)
                                {
                                    Console.WriteLine("More variables available...");
                                }

                                lastVariableName = nameList[nameList.Count - 1];
                            }
                            else
                            {
                                Console.WriteLine("Get logical device variables error: " + err.ToString());
                            }


                            moreVariabesFollows = moreFollows;

                            waitForCallback.Set();
                        }, null);

                        waitForCallback.WaitOne();
                    }

                    Console.WriteLine("Variables in logical device {0}:", firstLdName);

                    foreach (string variableName in variablesList)
                    {
                        Console.WriteLine("  {0}", variableName);
                    }
                }

                Console.WriteLine("Now read variables...");

                /* read FCDO */
                con.ReadValueAsync("simpleIOGenericIO/GGIO1.AnIn1", FunctionalConstraint.MX, delegate(uint invokeId, object parameter, IedClientError err, MmsValue value) {
                    if (err == IedClientError.IED_ERROR_OK)
                    {
                        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());
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Read error: " + err.ToString());
                    }
                }, null);

                con.ReadValueAsync("simpleIOGenericIO/GGIO1.AnIn1", FunctionalConstraint.MX, delegate(uint invokeId, object parameter, IedClientError err, MmsValue value) {
                    if (err == IedClientError.IED_ERROR_OK)
                    {
                        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());
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Read error: " + err.ToString());
                    }
                }, null);

                Thread.Sleep(5000);

                con.Abort();

                Console.WriteLine("Aborted");
            }
            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. 10
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);
            }
        }
Esempio n. 11
0
        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);
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
Esempio n. 12
0
        /// <summary>
        /// Connect and read IED Comtrade Files.
        /// </summary>
        /// <param name="device">Device to read</param>
        private static void ProcessDeviceComtradeFiles(Device device)
        {
            var iedConnection = new IedConnection
            {
                ConnectTimeout = 20000
            };

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

                iedConnection.Connect(device.IPAddress);

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

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

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

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

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

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

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

                    DownloadComtradeFiles(iedConnection, device, filteredDownloadableFileList);

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

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

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

                    DatabaseService.StoreComtradeFilesToDatabase(device, temporaryComtradeFiles);

                    DatabaseService.StoreIEDFilesToDatabase(device, filteredDownloadableFileList);

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

                    ExportService.ExportDisturbanceRecordings(device, temporaryComtradeFiles);

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

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

                //Close connection:
                iedConnection.Release();
            }
            catch (IedConnectionException e)
            {
                Logger.Fatal($"Client Error: {e.GetIedClientError()}");
                Logger.Fatal($"Error Code: {e.GetErrorCode()}");
                Logger.Fatal($"IED Connection Exception: {e}");
            }
            catch (Exception e)
            {
                Logger.Fatal(e);
            }
            finally
            {
                try
                {
                    //libIEC61850: Dispose connection after use.
                    iedConnection.Dispose();
                }
                catch (IedConnectionException e)
                {
                    Logger.Fatal($"Dispose Client Error: {e.GetIedClientError()}");
                    Logger.Fatal($"Dispose Error Code: {e.GetErrorCode()}");
                    Logger.Fatal($"Dispose IED Connection Exception: {e}");
                }
                catch (Exception e)
                {
                    Logger.Fatal(e);
                }
                Logger.Info($"{device} - Disconnected!");
            }
        }
Esempio n. 13
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. 14
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);

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

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
Esempio n. 15
0
        public ResultValueModel WriteCMD(string hostip, Int32 port, bool operate, string cmdaddress)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //create control object
                ControlObject control      = con.CreateControlObject(cmdaddress);
                ControlModel  controlModel = control.GetControlModel();
                //result variable
                dynamic ValueTuple = null;

                //validate control model type
                if (controlModel == ControlModel.DIRECT_ENHANCED)
                {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);
                    ValueTuple = control.Operate(operate);
                }
                else if (controlModel == ControlModel.DIRECT_NORMAL)
                {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);
                    ValueTuple = control.Operate(operate);
                }
                else if (controlModel == ControlModel.SBO_ENHANCED)
                {
                    //set handler
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);
                    //set SynchroCheck
                    control.SetSynchroCheck(true);
                    //set InterlockCheck
                    control.SetInterlockCheck(true);
                    //validate  cmd select
                    if (control.SelectWithValue(true))
                    {
                        //operate  cmd
                        ValueTuple = control.Operate(operate);
                    }
                    else if (control.SelectWithValue(false))
                    {
                        //operate  cmd
                        ValueTuple = control.Operate(operate);
                    }
                    else if (control.Select())
                    {
                        //operate  cmd
                        ValueTuple = control.Operate(operate);
                    }
                    else
                    {
                        ValueTuple = "SBO cmd not selected!";
                        //insert logs into db
                        Submission dbinsert = new Submission
                        {
                            CreatedAt = DateTime.Now,
                            Content   = ValueTuple
                        };
                        _subSvc.Create(dbinsert);
                    }
                }
                else
                {
                    ValueTuple = "CMD type is not DIRECT_ENHANCED or DIRECT_NORMAL or SBO_ENHANCED kindly Check!";
                    //insert logs into db
                    Submission dbinsert = new Submission
                    {
                        CreatedAt = DateTime.Now,
                        Content   = ValueTuple
                    };
                    _subSvc.Create(dbinsert);
                }

                //con close
                con.Abort();

                //result
                Value_Result listresult = new Value_Result
                {
                    Address = cmdaddress,
                    Value   = ValueTuple,
                };
                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);
            }
        }
Esempio n. 16
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. 17
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();
        }
Esempio n. 18
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());
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
Esempio n. 19
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);

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

                /* stop main loop when connection is lost */
                con.InstallConnectionClosedHandler(delegate(IedConnection connection) {
                    Console.WriteLine("Connection closed");
                    ReportingExample.running = false;
                });

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

                /* Dispose the RCBs when you no longer need them */
                rcb1.Dispose();
                rcb2.Dispose();
                rcb3.Dispose();

                con.Abort();

                con.Dispose();
            } catch (IedConnectionException e) {
                Console.WriteLine("Error: " + e.Message);

                con.Dispose();
            }
        }
Esempio n. 20
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. 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
            {
                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);
            }

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

            try
            {   //connection
                con.Connect(hostip, port);
                //extract fc
                data_extract dataExtract  = new data_extract();
                var          FunctionCode = dataExtract.ExtractFC(FC);
                dynamic      mmsresult    = null;
                //validate datatype
                if (datatype == "BOOLEAN")
                {
                    mmsresult = con.ReadBooleanValue(valueaddress, FunctionCode);
                }
                else if (datatype == "FLOAT")
                {
                    mmsresult = con.ReadFloatValue(valueaddress, FunctionCode);
                }
                else if (datatype == "INT")
                {
                    mmsresult = con.ReadIntegerValue(valueaddress, FunctionCode);
                }
                else if (datatype == "STRING")
                {
                    mmsresult = con.ReadStringValue(valueaddress, FunctionCode);
                }
                else if (datatype == "BITSTRING")
                {
                    mmsresult = con.ReadBitStringValue(valueaddress, FunctionCode);
                }

                //con close
                con.Abort();
                //extract value
                dynamic ValueTuple = null;
                ValueTuple = dataExtract.ExtractValue(mmsresult);
                //result
                Value_Result listresult = new Value_Result
                {
                    Address = valueaddress,
                    Value   = ValueTuple,
                };
                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);
            }
        }
Esempio n. 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);

                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. 24
0
        public ResultMultipleModel ReadMultipleGroups(string hostip, Int32 port, string logicaldevicename, string[] vargroup)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //list variable group
                var variable_group = new List <string>();

                foreach (string address in vargroup)
                {
                    variable_group.Add(address);
                }
                //mms connecton
                MmsConnection mmsConnection = con.GetMmsConnection();
                //read data
                MmsValue mmsresult = mmsConnection.ReadMultipleVariables(logicaldevicename, variable_group);
                //connection close
                con.Abort();
                //result list
                data_extract   dataExtract = new data_extract();
                dynamic        ValueTuple  = null;
                Int16          Quality;
                DateTimeOffset Timestamp;
                Read_Result    listresult = null;

                List <Read_Result> Variableset = new List <Read_Result>();
                int i = 0;

                foreach (MmsValue address in mmsresult)
                {
                    if (address.Size() == 4)
                    {
                        ValueTuple = dataExtract.ExtractValue(address.GetElement(0));
                        Quality    = dataExtract.ExtractValue(address.GetElement(2));
                        Timestamp  = dataExtract.ExtractValue(address.GetElement(3));
                    }
                    else
                    {
                        ValueTuple = dataExtract.ExtractValue(address.GetElement(0));
                        Quality    = dataExtract.ExtractValue(address.GetElement(1));
                        Timestamp  = dataExtract.ExtractValue(address.GetElement(2));
                    }

                    listresult = new Read_Result
                    {
                        Address   = variable_group[i],
                        Value     = ValueTuple,
                        Quality   = Quality,
                        Timestamp = Timestamp
                    };
                    Variableset.Add(listresult);


                    i = i + 1;
                }

                ResultMultipleModel result = new ResultMultipleModel()
                {
                    data         = Variableset,
                    error        = false,
                    errormessage = null
                };
                //destroy instance
                con.Dispose();
                //result
                return(result);
            }
            catch (IedConnectionException e)
            {
                ResultMultipleModel result = new ResultMultipleModel()
                {
                    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. 25
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. 26
0
        public void OnGet()
        {
            IndexModel viewdata = new IndexModel();

            IedConnection con = new IedConnection();

            string hostname;

            hostname = "100.100.100.100";

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

            try {
                con.Connect(hostname, 102);

                string rcbReference3 = "TEMPLATEMEAS/LLN0.RP.urcbAinA01";
                // string rcbReference3 = "TEMPLATECTRL/LLN0.BR.brcbDinD01";
                ReportControlBlock rcb3 = con.GetReportControlBlock(rcbReference3);

                rcb3.GetRCBValues();

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

                rcb3.InstallReportHandler(reportHandler, rcb3);

                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;
                    IndexModel.running = false;
                };

                /* stop main loop when connection is lost */
                con.InstallConnectionClosedHandler(delegate(IedConnection connection) {
                    Console.WriteLine("Connection closed");
                    IndexModel.running = false;
                });

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

                /* Dispose the RCBs when you no longer need them */
                rcb3.Dispose();

                con.Abort();

                con.Dispose();
            } catch (IedConnectionException e) {
                Console.WriteLine("Error: " + e.Message);

                con.Dispose();
            }
        }