Ejemplo n.º 1
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!!!"));
        }
Ejemplo n.º 2
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"));
        }