Esempio n. 1
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. 2
0
        private void TestServer(object obj)
        {
            SCLServer self  = (SCLServer)obj;
            IedModel  model = new IedModel("bubak");

            LogicalDevice ldevice1 = new LogicalDevice("strasidlo", model);

            LogicalNode lln0 = new LogicalNode("LLN0", ldevice1);

            DataObject lln0_mod    = CDCFactory.CDC_ENG("Mod", lln0, CDCOptions.NONE);
            DataObject lln0_health = CDCFactory.CDC_ENG("Health", lln0, CDCOptions.NONE);

            SettingGroupControlBlock sgcb = new SettingGroupControlBlock(lln0, 1, 1);

            /* Add a temperature sensor LN */
            LogicalNode ttmp1       = new LogicalNode("TTMP1", ldevice1);
            DataObject  ttmp1_tmpsv = CDCFactory.CDC_SAV("TmpSv", ttmp1, 0, false);

            DataAttribute temperatureValue     = ttmp1_tmpsv.GetChild_DataAttribute("instMag.f");
            DataAttribute temperatureTimestamp = ttmp1_tmpsv.GetChild_DataAttribute("t");

            IEC61850.Server.DataSet dataSet = new IEC61850.Server.DataSet("events", lln0);
            DataSetEntry            dse     = new DataSetEntry(dataSet, "TTMP1$MX$TmpSv$instMag$f", -1, null);

            IEC61850.Common.ReportOptions rptOptions = IEC61850.Common.ReportOptions.SEQ_NUM | IEC61850.Common.ReportOptions.TIME_STAMP | IEC61850.Common.ReportOptions.REASON_FOR_INCLUSION;

            IEC61850.Server.ReportControlBlock rcb1 = new IEC61850.Server.ReportControlBlock("events01", lln0, "events01", false, null, 1, IEC61850.Common.TriggerOptions.DATA_CHANGED, rptOptions, 50, 0);
            IEC61850.Server.ReportControlBlock rcb2 = new IEC61850.Server.ReportControlBlock("events02", lln0, "events02", true, null, 1, IEC61850.Common.TriggerOptions.DATA_CHANGED | IEC61850.Common.TriggerOptions.GI, rptOptions, 50, 0);

            IedServer server = new IedServer(model);

            server.Start(tcpPort);

            logger.LogInfo(String.Format("SCL Server Started at port 102!!!"));

            float val = 0.0f;

            while (_run)
            {
                server.LockDataModel();
                temperatureValue.MmsValue.SetFloat(val);
                temperatureTimestamp.MmsValue.SetUtcTimeMs(Util.GetTimeInMs());
                server.UnlockDataModel();

                val += 0.1f;

                int waitres = WaitHandle.WaitAny(_waitHandles, 500);
                switch (waitres)
                {
                case 0:         // endthread
                    self._run = false;
                    break;

                case WaitHandle.WaitTimeout:
                    break;
                }
            }
            logger.LogInfo(String.Format("SCL Server Finished!!!"));
        }
Esempio n. 3
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. 4
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. 5
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. 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;
            }

            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. 7
0
        private void WorkerThreadProc(object obj)
        {
            SCLServer self = (SCLServer)obj;

            logger.LogInfo(String.Format("SCL Server " + sclModel.iec.Name + " - Creating model. It takes a while..."));
            IedModel model = makeIecModel();

            server = new IedServer(model);
            InitializeValues(sclModel.iec);

            server.Start(tcpPort);
            //Thread.Sleep(100);
            if (!server.isRunning())
            {
                logger.LogError(String.Format("SCL Server " + sclModel.iec.Name + " Failed at port " + tcpPort.ToString() + "!!!"));
                self._run = false;
            }
            else
            {
                logger.LogInfo(String.Format("SCL Server " + sclModel.iec.Name + " Started at port " + tcpPort.ToString() + "!!!"));
            }

            while (self._run)
            {
                int waitres = WaitHandle.WaitAny(_waitHandles, 500);
                switch (waitres)
                {
                case 0:         // endthread
                    self._run = false;
                    break;

                case WaitHandle.WaitTimeout:
                    if (!server.isRunning())     //logger.LogInfo("Server not running???");
                    {
                        self._run = false;
                    }
                    break;
                }
            }
            server.Stop();
            resetModelObjects(sclModel.iec);
            server.Dispose();
            server = null;
            model.Dispose();
            model    = null;
            sclModel = null;
            logger.LogInfo(String.Format("SCL Server Stopped"));
        }
Esempio n. 8
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. 9
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. 10
0
        public void StartStopSimpleServer()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            IedServer iedServer = new IedServer(iedModel);

            Assert.NotNull(iedServer);

            iedServer.Start(10002);

            Assert.IsTrue(iedServer.IsRunning());

            iedServer.Stop();

            Assert.IsFalse(iedServer.IsRunning());

            iedServer.Destroy();
        }
Esempio n. 11
0
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
     await Task.Factory.StartNew(() => {
         iedServer.Start(102);
         for (int i = 1; i <= 30; i++)
         {
             try
             {
                 SetControlListener($"ICPSI/STGGIO1.SPCSO{i}");
             }
             catch (Exception ex)
             {
                 _logger.LogWarning(ex.Message);
             }
         }
         _logger.LogInformation("SYSLOG: Iec61850 Server is Listening on port 102.");
         GC.Collect();
     }, stoppingToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);
 }
Esempio n. 12
0
        public static bool StartServer()
        {
            if (_iedModel != null)
            {
                _iedServer.Start(ServerConfig.ServerPort);

                Log.Log.Write(@"ServerIEC61850.StartServer: ServerIEC61850 started", @"Start");

                UpdateModBus.StartModBus();
            }
            else
            {
                Log.Log.Write(@"ServerIEC61850.StartServer: No valid data model found!", @"Error");

                return(false);
            }

            return(true);
        }
Esempio n. 13
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();
        }
Esempio n. 14
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. 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(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. 16
0
        public s61850()
        {
            iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg");
            if (iedModel == null)
            {
                Console.WriteLine("SYSERR: No Valid DataModel Found!");
                return;
            }


            config = new IedServerConfig();
            config.ReportBufferSize = 100000;

            iedServer = new IedServer(iedModel, config);


            iedServer.Start(10102);
            Console.WriteLine("SYSLOG: Iec61850 Server is Listening on port 10103.");
            GC.Collect();

            /*Console.WriteLine("Starting GOOSE subscriber...");
             *
             * GooseReceiver receiver = new GooseReceiver();
             * //\Device\NPF_{874C4A5F-2D90-42E8-AFD3-E76B65365490}
             * receiver.SetInterfaceId(@"0");
             *
             * GooseSubscriber subscriber = new GooseSubscriber(@"BUSBAYCTRL/LLN0$GO$Control_DataSet");
             *
             * subscriber.SetAppId(1000);
             *
             * subscriber.SetListener(gooseListener, null);
             *
             * receiver.AddSubscriber(subscriber);
             *
             * receiver.Start();*/
        }
Esempio n. 17
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. 18
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. 19
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");

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