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
        //Connecter
        private void button2_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(IpBox.Text))
            {
                hostname = IpBox.Text.ToString();
            }
            if (!String.IsNullOrEmpty(PortBox.Text))
            {
                port = Convert.ToInt32(PortBox.Text);
            }
            if (!String.IsNullOrEmpty(PassBox.Text))
            {
                password = Convert.ToString(PassBox.ToString());
            }
            if (checkBox1.Checked && firspass)
            {
                param.UsePasswordAuthentication(password); firspass = false;
            }


            bool retry = true;

            while (retry)
            {
                try
                {
                    ConnectToIED.Connect(hostname, port);
                    Disconnect_button.Enabled = true;
                    Connect_button.Enabled    = false;
                    Exit_button.Enabled       = false;
                    CreateButton.Enabled      = true;
                    Get_reports.Enabled       = true;
                    IpBox.Clear();
                    PortBox.Clear();
                    PassBox.Clear();
                    retry           = false;
                    toolStatus.Text = "Connected";
                    IEDConnected    = true;
                    int i = 1;
                    for (i = 1; i < 65; i++)
                    {
                        refer.Add("GEDeviceF650/vinGGIO1.SPCSO" + i.ToString() + "");
                        control.Add(ConnectToIED.CreateControlObject(refer[i - 1]));
                    }
                }
                catch (IedConnectionException ex)
                {
                    IEDConnected    = false;
                    toolStatus.Text = "Failed to connect";
                    if (MessageBox.Show(ex.Message + "for the following reason" + ex.GetIedClientError(), "Erreur", MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
                    {
                        retry = false;
                    }
                    else
                    {
                        retry = true;
                    }
                }
            }
        }
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 = "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);
            }
        }
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.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);
            }
        }
Esempio n. 5
0
        public void AccessDataModelClientServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

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

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

            IedServer iedServer = new IedServer(iedModel);

            iedServer.Start(10002);

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

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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

            Assert.IsTrue(stVal);

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

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

            Assert.IsFalse(stVal);

            connection.Abort();

            iedServer.Stop();

            iedServer.Destroy();
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

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

            try {
                con.Connect(hostname, 102);

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

                ReportControlBlock rcb = con.GetReportControlBlock(rcbReference);

                rcb.GetRCBValues();

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

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

                Console.WriteLine(rcb.GetDataSetReference());

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

                rcb.SetRCBValues();

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

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

                con.Abort();
            } catch (IedConnectionException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 7
0
        public void ControlWriteAccessToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

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

            IedServer iedServer = new IedServer(iedModel);

            int opDlTmmsValue = 0;

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

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

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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


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

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

            MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms);

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

            connection.Abort();

            iedServer.Stop();

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

            iedServer.Destroy();
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

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

            try
            {
                con.Connect(hostname, 102);

                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. 9
0
        public ResultValueModel WriteValue(string hostip, Int32 port, string varaddress, string FC, dynamic newvalue)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //extract fc
                data_extract dataExtract  = new data_extract();
                var          FunctionCode = dataExtract.ExtractFC(FC);
                var          Value        = dataExtract.ExtractValue(newvalue);
                dynamic      mmsresult    = null;
                //validate datatype
                mmsresult = con.WriteValue(varaddress, FunctionCode, new MmsValue(Value));
                //con close
                con.Abort();
                //result
                Value_Result listresult = new Value_Result
                {
                    Address = varaddress,
                    Value   = mmsresult,
                };
                ResultValueModel result = new ResultValueModel
                {
                    data         = listresult,
                    error        = false,
                    errormessage = null
                };
                //destroy instance
                con.Dispose();
                //result
                return(result);
            }
            catch (IedConnectionException e)
            {
                ResultValueModel result = new ResultValueModel()
                {
                    data         = null,
                    error        = true,
                    errormessage = e.Message.ToString()
                };
                //insert logs into db
                Submission dbinsert = new Submission
                {
                    CreatedAt = DateTime.Now,
                    Content   = e.Message.ToString()
                };
                _subSvc.Create(dbinsert);
                //destroy result
                con.Dispose();
                //result
                return(result);
            }
        }
Esempio n. 10
0
        public void ConnectionHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            int handlerCalled   = 0;
            int connectionCount = 0;

            IedServer iedServer = new IedServer(iedModel);

            string ipAddress = null;

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

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

            iedServer.Start(10002);

            IedConnection con1 = new IedConnection();

            con1.Connect("localhost", 10002);

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

            IedConnection con2 = new IedConnection();

            con2.Connect("localhost", 10002);

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

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

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

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

            iedServer.Stop();

            iedServer.Dispose();
        }
Esempio n. 11
0
        public void ControlWriteAccessComplexDAToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model2.cfg");

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

            IedServer iedServer = new IedServer(iedModel);

            int handlerCalled = 0;

            MmsValue receivedValue = null;

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

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

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

            MmsValue complexValue = MmsValue.NewEmptyStructure(1);

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

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

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

            receivedValue.Dispose();

            receivedValue = null;

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

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

            connection.Abort();

            iedServer.Stop();

            iedServer.Dispose();
        }
Esempio n. 12
0
 public bool Start()
 {
     try
     {
         _connection.Connect(_hostname, _port);
         _runConnect = true;
         return(true);
     }
     catch (IedConnectionException e)
     {
         Log.Write(e, Log.Code.ERROR);
         return(false);
     }
 }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

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

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

            try
            {
                con.Connect(hostname, 102);

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

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

                Console.WriteLine();

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

                string filename = "IEDSERVER.BIN";

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

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

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

                fs.Close();

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
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
            {
                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. 15
0
        public void ControlHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

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

            Assert.IsNotNull(spcso1);

            int handlerCalled = 0;

            IedServer iedServer = new IedServer(iedModel);

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

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

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

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

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

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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

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

            Assert.IsNotNull(controlClient);

            controlClient.Operate(true);

            connection.Abort();

            Assert.AreEqual(1, handlerCalled);

            iedServer.Stop();

            iedServer.Destroy();
        }
Esempio n. 16
0
        public void WriteAccessPolicy()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

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

            IedServer iedServer = new IedServer(iedModel);

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


            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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

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

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

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

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

            MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms);

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

            connection.Abort();

            iedServer.Stop();

            iedServer.Dispose();
        }
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 = "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();
        }
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);

                string objectReference = "IEDM1CPUBHKW/DRCC1.DERStr";

                ControlObject control = con.CreateControlObject(objectReference);

                ControlModel controlModel = control.GetControlModel();

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

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



                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
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
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

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

                con.ConnectTimeout = 10000;

                con.Connect(hostname, 102);

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

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

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 20
0
        public void ConnectToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IedServer iedServer = new IedServer(iedModel);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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

            Assert.IsNotEmpty(list);

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

            iedServer.Stop();

            iedServer.Destroy();
        }
Esempio n. 21
0
        public void ReadNonExistingObject()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IedServer iedServer = new IedServer(iedModel);

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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

            Assert.IsNotNull(value);

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

            iedServer.Stop();

            iedServer.Destroy();
        }
        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. 23
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. 24
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

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

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

            try
            {
                IsoConnectionParameters parameters = con.GetConnectionParameters();

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

                con.ConnectTimeout = 10000;

                con.Connect(hostname, 102);

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

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

                con.Release();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 25
0
        public void ControlHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

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

            Assert.IsNotNull(spcso1);

            int handlerCalled = 0;

            IedServer iedServer = new IedServer(iedModel);

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

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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

            Assert.IsNotNull(controlClient);

            controlClient.Operate(true);

            connection.Abort();

            Assert.AreEqual(1, handlerCalled);

            iedServer.Stop();

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

            string hostname;

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

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

            try {
                con.Connect (hostname, 102);

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

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

                rcb1.GetRCBValues();

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

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

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

                rcb1.SetRCBValues();

                rcb2.GetRCBValues();

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

                rcb2.InstallReportHandler(reportHandler, rcb2);

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

                rcb2.SetRCBValues();

                rcb3.GetRCBValues();

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

                rcb3.InstallReportHandler(reportHandler, rcb2);

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

                rcb3.SetRCBValues();

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

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

                con.Abort ();
            } catch (IedConnectionException e) {
                Console.WriteLine (e.Message);
            }
        }
Esempio n. 29
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection ();

            string hostname;

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

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

            try
            {
                con.Connect(hostname, 102);

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

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

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

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

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

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

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

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

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

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

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

            System.Threading.Thread.Sleep(2000);
        }
Esempio n. 30
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());
               }
        }
Esempio n. 31
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);
            }
        }
Esempio n. 32
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. 33
0
        public static void Main(string[] args)
        {
            IedConnection con = new IedConnection();

            string hostname;

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

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


            try
            {
                con.Connect(hostname, 102);

                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. 34
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.");

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

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

            string hostname;

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

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

            try
            {
                con.Connect(hostname, 102);

                // 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());
            }
        }
Esempio n. 36
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. 37
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. 38
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. 39
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);
                }


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