Esempio n. 1
0
        public void SetControlListener(string ObjRef)
        {
            DataObject ControlPoint = (DataObject)iedModel.GetModelNodeByShortObjectReference(ObjRef);

            iedServer.SetCheckHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck) {
                Console.WriteLine("SYSLOG: Received binary control command:");
                Console.WriteLine("   ctlNum: " + action.GetCtlNum());
                Console.WriteLine("   execution-time: " + action.GetControlTimeAsDataTimeOffset().ToString());

                return(CheckHandlerResult.ACCEPTED);
            }, null);

            iedServer.SetControlHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) {
                bool val = ctlVal.GetBoolean();

                if (val)
                {
                    Console.WriteLine("CTRL: Execute binary control command: ON");
                }
                else
                {
                    Console.WriteLine("CTRL: Execute binary control command: OFF");
                }

                return(ControlHandlerResult.OK);
            }, null);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            bool running = true;

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

            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            if (iedModel == null)
            {
                Console.WriteLine("No valid data model found!");
                return;
            }

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

            IedServer iedServer = new IedServer(iedModel);

            iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) {
                bool val = ctlVal.GetBoolean();

                if (val)
                {
                    Console.WriteLine("received binary control command: on");
                }
                else
                {
                    Console.WriteLine("received binary control command: off");
                }

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

            iedServer.Start(102);
            Console.WriteLine("Server started");

            GC.Collect();

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

            iedServer.Stop();
            Console.WriteLine("Server stopped");

            iedServer.Destroy();
        }
Esempio n. 3
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. 4
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. 5
0
        public async Task SetControlListener(string ObjRef)
        {
            _logger.LogInformation($"SYSLOG: Set Control Listener: {ObjRef}");
            DataObject        ControlPoint = (DataObject)iedModel.GetModelNodeByShortObjectReference(ObjRef);
            DataObjectMapping tmp          = new DataObjectMapping(ControlPoint, ObjRef);

            DoMapping.Add(tmp);
            iedServer.SetCheckHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck) {
                _logger.LogInformation($"SYSLOG: Received binary control command:" +
                                       $"\n\tctlNum: {action.GetCtlNum()}" +
                                       $"\n\texecution-time: {action.GetControlTimeAsDataTimeOffset().ToString()}");

                return(CheckHandlerResult.ACCEPTED);
            }, null);

            iedServer.SetControlHandler(ControlPoint, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) {
                bool val = ctlVal.GetBoolean();

                string result = (from v in DoMapping
                                 where v.dataObject == ControlPoint
                                 select v.tagName).FirstOrDefault();
                result = result.Split('.').Last();

                if (val)
                {
                    AddTagout(result);
                    _logger.LogInformation("CTRL: Execute binary control command: ON");
                }
                else
                {
                    RemoveTagout(result);
                    _logger.LogInformation("CTRL: Execute binary control command: OFF");
                }
                return(ControlHandlerResult.OK);
            }, null);
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            bool running = true;

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

            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg");

            if (iedModel == null)
            {
                Console.WriteLine("No valid data model found!");
                return;
            }

            iedModel.SetIedName("TestIED");

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

            IedServerConfig config = new IedServerConfig();

            config.ReportBufferSize = 100000;

            IedServer iedServer = new IedServer(iedModel, config);

            iedServer.SetCheckHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck)
            {
                Console.WriteLine("Received binary control command:");
                Console.WriteLine("   ctlNum: " + action.GetCtlNum());
                Console.WriteLine("   execution-time: " + action.GetControlTimeAsDataTimeOffset().ToString());

                return(CheckHandlerResult.ACCEPTED);
            }, null);

            iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test)
            {
                bool val = ctlVal.GetBoolean();

                if (val)
                {
                    Console.WriteLine("execute binary control command: on");
                }
                else
                {
                    Console.WriteLine("execute binary control command: off");
                }

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

            DataObject spcso2 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO2");

            iedServer.SetSelectStateChangedHandler(spcso2, delegate(ControlAction action, object parameter, bool isSelected, SelectStateChangedReason reason)
            {
                DataObject cObj = action.GetControlObject();

                Console.WriteLine("Control object " + cObj.GetObjectReference() + (isSelected ? " selected" : " unselected") + " reason: " + reason.ToString());
            }, null);

            iedServer.Start(102);

            if (iedServer.IsRunning())
            {
                Console.WriteLine("Server started");

                GC.Collect();

                DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1");

                DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f");
                DataAttribute ggio1AnIn1T    = (DataAttribute)ggio1AnIn1.GetChild("t");

                float floatVal = 1.0f;

                while (running)
                {
                    floatVal += 1f;
                    iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now));
                    iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal);
                    Thread.Sleep(100);
                }

                iedServer.Stop();
                Console.WriteLine("Server stopped");
            }
            else
            {
                Console.WriteLine("Failed to start server");
            }

            iedServer.Destroy();
        }
Esempio n. 7
0
        public static void InitHandlers(IedServer iedServer, IedModel iedModel)
        {
            foreach (var itemDataObject in UpdateDataObj.UpdateListDestination)
            {
                var temp = (DataObject)iedModel.GetModelNodeByShortObjectReference(itemDataObject.NameDataObj);

                if (itemDataObject.BaseClass.GetType() == typeof(SpcClass))
                {
                    object tempParam = ((SpcClass)itemDataObject.BaseClass).ctlModel;

                    iedServer.SetCheckHandler(temp,
                                              (controlObject, parameter, ctlVal, test, interlockCheck, connection) =>
                    {
                        //controlObject
                        //iedServer.

                        //if(interlockCheck)

                        var result = CheckHandlerResult.ACCEPTED;
                        return(result);
                    },
                                              tempParam);

                    iedServer.SetWaitForExecutionHandler(temp,
                                                         (controlObject, parameter, ctlVal, test, synchroCheck) =>
                    {
                        //ControlHandlerResult.WAITING
                        var result = ControlHandlerResult.OK;
                        return(result);
                    },
                                                         tempParam);

                    iedServer.SetControlHandler(temp,
                                                (controlObject, parameter, ctlVal, test) =>
                    {
                        if (ctlVal.GetType() != MmsType.MMS_BOOLEAN)
                        {
                            return(ControlHandlerResult.FAILED);
                        }

                        if (!test)
                        {
                            var tempValue = new
                            {
                                Key   = "stVal",
                                Value = ctlVal.GetBoolean()
                            };
                            itemDataObject.WriteValue(tempValue);
                        }

                        return(ControlHandlerResult.OK);
                    },
                                                tempParam);
                }
                else if (itemDataObject.BaseClass.GetType() == typeof(IncClass))
                {
                    iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) =>
                                                         test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null);

                    iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) =>
                    {
                        if (ctlVal.GetType() != MmsType.MMS_INTEGER)
                        {
                            return(ControlHandlerResult.FAILED);
                        }

                        itemDataObject.WriteValue(ctlVal.ToInt32());

                        return(ControlHandlerResult.OK);
                    }, null);
                }
            }
        }
        public static void Main(string[] args)
        {
            bool running = true;

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

            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg");

            if (iedModel == null)
            {
                Console.WriteLine("No valid data model found!");
                return;
            }

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

            IedServerConfig config = new IedServerConfig();

            config.ReportBufferSize = 100000;

            IedServer iedServer = new IedServer(iedModel, config);

            iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) {
                bool val = ctlVal.GetBoolean();

                if (val)
                {
                    Console.WriteLine("received binary control command: on");
                }
                else
                {
                    Console.WriteLine("received binary control command: off");
                }

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

            iedServer.Start(102);
            Console.WriteLine("Server started");

            GC.Collect();

            DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1");

            DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f");
            DataAttribute ggio1AnIn1T    = (DataAttribute)ggio1AnIn1.GetChild("t");

            float floatVal = 1.0f;

            while (running)
            {
                floatVal += 1f;
                iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now));
                iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal);
                Thread.Sleep(100);
            }

            iedServer.Stop();
            Console.WriteLine("Server stopped");

            iedServer.Destroy();
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            bool running = true;

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

            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg");

            if (iedModel == null)
            {
                Console.WriteLine("No valid data model found!");
                return;
            }

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

            TLSConfiguration tlsConfig = new TLSConfiguration();

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

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

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

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

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

            IedServer iedServer = new IedServer(iedModel, tlsConfig);

            iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) {
                bool val = ctlVal.GetBoolean();

                if (val)
                {
                    Console.WriteLine("received binary control command: on");
                }
                else
                {
                    Console.WriteLine("received binary control command: off");
                }

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

            iedServer.Start();
            Console.WriteLine("Server started");

            GC.Collect();

            DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1");

            DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f");
            DataAttribute ggio1AnIn1T    = (DataAttribute)ggio1AnIn1.GetChild("t");

            float floatVal = 1.0f;

            while (running)
            {
                floatVal += 1f;
                iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now));
                iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal);
                Thread.Sleep(100);
            }

            iedServer.Stop();
            Console.WriteLine("Server stopped");

            iedServer.Destroy();
        }
Esempio n. 10
0
        private static void InitHandlersClass(IedServer iedServer, IedModel iedModel)
        {
            foreach (var itemDataObject in UpdateDataObj.UpdateListDestination)
            {
                var temp = (DataObject)iedModel.GetModelNodeByShortObjectReference(itemDataObject.NameDataObj);

                if (itemDataObject.BaseClass.GetType() == typeof(SpcClass))
                {
                    iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) =>
                                                         test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null);

                    iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) =>
                    {
                        if (ctlVal.GetType() != MmsType.MMS_BOOLEAN)
                        {
                            return(ControlHandlerResult.FAILED);
                        }

                        itemDataObject.WriteValue(ctlVal.GetBoolean());

                        return(ControlHandlerResult.OK);
                    }, null);
                }
                else if (itemDataObject.BaseClass.GetType() == typeof(IncClass))
                {
                    iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) =>
                                                         test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null);

                    iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) =>
                    {
                        if (ctlVal.GetType() != MmsType.MMS_INTEGER)
                        {
                            return(ControlHandlerResult.FAILED);
                        }

                        itemDataObject.WriteValue(ctlVal.ToInt32());

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

            //foreach (var itemGetObjects in UpdateDataObj.ClassGetObjects)
            //{
            //	foreach (var itemDataClass in itemGetObjects.DataClass)
            //	{
            //		var temp = (DataObject)iedModel.GetModelNodeByShortObjectReference(itemDataClass.NameDataObj);

            //		if (itemDataClass.DataObj.GetType() == typeof(SpcClass))
            //		{
            //			//switch (((SpcClass) itemDataClass.DataObj).ctlModel.CtlModels)

            //			iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) =>
            //				test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null);

            //			iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) =>
            //			{
            //				if (ctlVal.GetType() != MmsType.MMS_BOOLEAN )
            //					return ControlHandlerResult.FAILED;

            //				UpdateSPC(UpdateDataObj.ClassGetObjects.IndexOf(itemGetObjects), itemGetObjects.DataClass.IndexOf(itemDataClass), ctlVal.GetBoolean());

            //				return ControlHandlerResult.OK;
            //			}, null);
            //		}

            //		else if (itemDataClass.DataObj.GetType() == typeof(IncClass))
            //		{
            //			iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) =>
            //				test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null);

            //			iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) =>
            //			{
            //				if (ctlVal.GetType() != MmsType.MMS_INTEGER)
            //					return ControlHandlerResult.FAILED;

            //				UpdateINC(UpdateDataObj.ClassGetObjects.IndexOf(itemGetObjects), ctlVal.ToInt32());
            //				return ControlHandlerResult.OK;
            //			}, null);
            //		}
            //	}
            //}

            foreach (var itemMod in UpdateDataObj.ModClass.PathModList)
            {
                var temp = (DataObject)iedModel.GetModelNodeByShortObjectReference(itemMod);

                iedServer.SetWaitForExecutionHandler(temp, (controlObject, parameter, val, test, check) =>
                                                     test ? ControlHandlerResult.FAILED : ControlHandlerResult.OK, null);

                iedServer.SetControlHandler(temp, (controlObject, parameter, ctlVal, test) =>
                {
                    if (ctlVal.GetType() != MmsType.MMS_INTEGER)
                    {
                        return(ControlHandlerResult.FAILED);
                    }

                    UpdateMod(ctlVal.ToInt32());
                    return(ControlHandlerResult.OK);
                }, null);
            }
        }