Esempio n. 1
0
        public void ModifyFloatValue(string ObjRef, string value)
        {
            DataObject DataObj = (DataObject)iedModel.GetModelNodeByShortObjectReference(ObjRef);

            DataAttribute DataObj_F = (DataAttribute)DataObj.GetChild("mag.f");
            DataAttribute DataObj_T = (DataAttribute)DataObj.GetChild("t");

            iedServer.UpdateFloatAttributeValue(DataObj_F, float.Parse(value));
            iedServer.UpdateTimestampAttributeValue(DataObj_T, new Timestamp(DateTime.Now));
        }
Esempio n. 2
0
        private static void UpdateFloat(string path, string value, IedServer iedServer, IedModel iedModel)
        {
            iedServer.LockDataModel();

            try
            {
                float str = Convert.ToSingle(value);
                iedServer.UpdateFloatAttributeValue((DataAttribute)iedModel.GetModelNodeByShortObjectReference(path), str);
            }
            catch
            {
                // ignored
            }

            iedServer.UnlockDataModel();
        }
Esempio n. 3
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. 4
0
            public void UpdateValue(IedServer server, object DataValue)
            {
                if (DataValue == null)
                {
                    return;
                }
                if (server == null)
                {
                    return;
                }
                if (mmsValue == null)
                {
                    mmsValueInit();
                }
                switch (mmsType)
                {
                /** array type (multiple elements of the same type) */
                case MmsType.MMS_ARRAY:
                    // not supported
                    break;

                /** structure type (multiple elements of different types) */
                case MmsType.MMS_STRUCTURE:
                    // not supported
                    break;

                /** boolean */
                case MmsType.MMS_BOOLEAN:
                    server.UpdateBooleanAttributeValue(this, Convert.ToBoolean(DataValue));
                    break;

                /** bit string */
                case MmsType.MMS_BIT_STRING:
                    if (DataValue is uint)
                    {
                        server.UpdateBitStringAttributeValue(this, Convert.ToUInt32(DataValue));
                    }
                    break;

                case MmsType.MMS_INTEGER:
                    if (daType == DataAttributeType.INT8 ||
                        daType == DataAttributeType.INT16 ||
                        daType == DataAttributeType.INT32)
                    {
                        server.UpdateInt32AttributeValue(this, Convert.ToInt32(DataValue));
                    }
                    else if (daType == DataAttributeType.INT64)
                    {
                        server.UpdateInt64AttributeValue(this, Convert.ToInt64(DataValue));
                    }
                    else if (daType == DataAttributeType.ENUMERATED)
                    {
                        server.UpdateInt32AttributeValue(this, Convert.ToInt32(DataValue));
                    }
                    break;

                /** unsigned integer */
                case MmsType.MMS_UNSIGNED:
                    if (daType == DataAttributeType.INT8U ||
                        daType == DataAttributeType.INT16U ||
                        daType == DataAttributeType.INT32U)
                    {
                        server.UpdateUnsignedAttributeValue(this, Convert.ToUInt32(DataValue));
                    }
                    break;

                /** floating point value (32 or 64 bit) */
                case MmsType.MMS_FLOAT:
                    if (daType == DataAttributeType.FLOAT32)
                    {
                        server.UpdateFloatAttributeValue(this, (float)DataValue);
                    }
                    else if (daType == DataAttributeType.FLOAT64)
                    {
                        // !!! Attention does not generate reports !!!
                        mmsValue.SetDouble((double)DataValue);
                    }
                    break;

                /** octet string */
                case MmsType.MMS_OCTET_STRING:
                    // !!! Attention does not generate reports !!!
                    mmsValue.setOctetString((byte[])DataValue);
                    break;

                /** visible string - ANSI string */
                case MmsType.MMS_VISIBLE_STRING:
                    server.UpdateVisibleStringAttributeValue(this, (string)DataValue);
                    break;

                /** Generalized time */
                case MmsType.MMS_GENERALIZED_TIME:
                    // not supported
                    break;

                case MmsType.MMS_BINARY_TIME:
                    // !!! Attention does not generate reports !!!
                    mmsValue.SetBinaryTime((ulong)DataValue);
                    break;

                /** Binary coded decimal (BCD) - not used */
                case MmsType.MMS_BCD:
                    // Not supported
                    break;

                /** object ID - not used */
                case MmsType.MMS_OBJ_ID:
                    // Not supported
                    break;

                /** Unicode string */
                case MmsType.MMS_STRING:
                    // Not supported
                    //mmsValue.SetMmsString((string)DataValue);
                    break;

                /** UTC time */
                case MmsType.MMS_UTC_TIME:
                    if (DataValue is ulong)
                    {
                        server.UpdateUTCTimeAttributeValue(this, Convert.ToUInt64(DataValue));
                    }
                    else if (DataValue is DateTime)
                    {
                        server.UpdateUTCTimeAttributeValue(this, Util.ConvertDateTime((DateTime)DataValue));
                    }
                    //mmsValue.SetUtcTimeMs((ulong)DataValue);
                    break;

                /** will be returned in case of an error (contains error code) */
                case MmsType.MMS_DATA_ACCESS_ERROR:
                    // Not supported
                    break;
                }
            }
        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. 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");

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