예제 #1
0
파일: Test.cs 프로젝트: zwinlu/libiec61850
        public void ControlWriteAccessToServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

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

            IedServer iedServer = new IedServer(iedModel);

            int opDlTmmsValue = 0;

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

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

            iedServer.Start(10002);

            IedConnection connection = new IedConnection();

            connection.Connect("localhost", 10002);

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


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

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

            MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms);

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

            connection.Abort();

            iedServer.Stop();

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

            iedServer.Destroy();
        }
예제 #2
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();
        }
예제 #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);
            }
        }
예제 #4
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();
        }
예제 #5
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);
            }
        }
예제 #6
0
        //Ecrire sur les virtual inputs
        private void WriteIED(CancellationToken token)
        {
            if (token.IsCancellationRequested)
            {
                toolStatus.Text = "Cancellation thrown"; return;
            }
            if (IEDConnected)
            {
                try
                {
                    ligne line = new ligne();
                    if (!Dbisopen)
                    {
                        Opendb();
                    }
                    string sql = "select * from vinTable";
                    cmd = new SQLiteCommand(sql, database_connection);

                    using (SQLiteDataReader read = cmd.ExecuteReader())
                    {
                        while (read.Read())
                        {
                            line._val  = ToBool(read.GetInt32(1));
                            line._name = read.GetString(0);
                            ConnectToIED.WriteValue("GEDeviceF650/vinGGIO1." + line._name + "", FunctionalConstraint.CF, new MmsValue(line._val));
                        }
                    }
                    //Closedb();
                }
                catch (Exception er)
                {
                    toolStatus.Text = er.Message;
                    IEDCancelation.Cancel();
                }
            }
            else
            {
                toolStatus.Text = "IED Disconnected";
            }
        }
        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();
        }
예제 #8
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();
        }