Exemplo n.º 1
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);

                string objectReference = "IEDM1CPUBHKW/DRCC1.DERStr";

                ControlObject control = con.CreateControlObject(objectReference);

                ControlModel controlModel = control.GetControlModel();

                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                if (!control.Operate(true))
                {
                    Console.WriteLine("operate failed!");
                }



                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
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);

                /* direct control with normal security or SBO with normal security */
                string objectReference = "simpleIOGenericIO/GGIO1.SPCSO1";

                ControlObject control = con.CreateControlObject(objectReference);

                ControlModel controlModel = control.GetControlModel();

                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());


                switch (controlModel)
                {
                case ControlModel.STATUS_ONLY:
                    Console.WriteLine("Control is status-only!");
                    break;

                case ControlModel.DIRECT_NORMAL:
                case ControlModel.DIRECT_ENHANCED:
                    if (!control.Operate(true))
                    {
                        Console.WriteLine("operate failed!");
                    }
                    else
                    {
                        Console.WriteLine("operated successfully!");
                    }
                    break;

                case ControlModel.SBO_NORMAL:
                case ControlModel.SBO_ENHANCED:

                    if (control.Select())
                    {
                        if (!control.Operate(true))
                        {
                            Console.WriteLine("operate failed!");
                        }
                        else
                        {
                            Console.WriteLine("operated successfully!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Select failed!");
                    }

                    break;
                }

                /* direct control with enhanced security */
                objectReference = "simpleIOGenericIO/GGIO1.SPCSO3";
                control         = con.CreateControlObject(objectReference);

                controlModel = control.GetControlModel();
                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                if (controlModel == ControlModel.DIRECT_ENHANCED)
                {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);

                    control.Operate(true);

                    Thread.Sleep(1000);
                }

                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }

            // release all resources - do NOT use the object after this call!!
            con.Dispose();
        }
Exemplo n.º 3
0
        public ResultValueModel WriteCMD(string hostip, Int32 port, bool operate, string cmdaddress)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //create control object
                ControlObject control      = con.CreateControlObject(cmdaddress);
                ControlModel  controlModel = control.GetControlModel();
                //result variable
                dynamic ValueTuple = null;

                //validate control model type
                if (controlModel == ControlModel.DIRECT_ENHANCED)
                {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);
                    ValueTuple = control.Operate(operate);
                }
                else if (controlModel == ControlModel.DIRECT_NORMAL)
                {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);
                    ValueTuple = control.Operate(operate);
                }
                else if (controlModel == ControlModel.SBO_ENHANCED)
                {
                    //set handler
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);
                    //set SynchroCheck
                    control.SetSynchroCheck(true);
                    //set InterlockCheck
                    control.SetInterlockCheck(true);
                    //validate  cmd select
                    if (control.SelectWithValue(true))
                    {
                        //operate  cmd
                        ValueTuple = control.Operate(operate);
                    }
                    else if (control.SelectWithValue(false))
                    {
                        //operate  cmd
                        ValueTuple = control.Operate(operate);
                    }
                    else if (control.Select())
                    {
                        //operate  cmd
                        ValueTuple = control.Operate(operate);
                    }
                    else
                    {
                        ValueTuple = "SBO cmd not selected!";
                        //insert logs into db
                        Submission dbinsert = new Submission
                        {
                            CreatedAt = DateTime.Now,
                            Content   = ValueTuple
                        };
                        _subSvc.Create(dbinsert);
                    }
                }
                else
                {
                    ValueTuple = "CMD type is not DIRECT_ENHANCED or DIRECT_NORMAL or SBO_ENHANCED kindly Check!";
                    //insert logs into db
                    Submission dbinsert = new Submission
                    {
                        CreatedAt = DateTime.Now,
                        Content   = ValueTuple
                    };
                    _subSvc.Create(dbinsert);
                }

                //con close
                con.Abort();

                //result
                Value_Result listresult = new Value_Result
                {
                    Address = cmdaddress,
                    Value   = ValueTuple,
                };
                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);
            }
        }
Exemplo n.º 4
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);

                /* direct control with normal security */
                string objectReference = "simpleIOGenericIO/GGIO1.SPCSO1";

                ControlObject control = con.CreateControlObject(objectReference);

                ControlModel controlModel = control.GetControlModel();

                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                if (controlModel != ControlModel.CONTROL_MODEL_STATUS_ONLY)
                {
                    control.Operate(true);
                }

                if (!control.Operate(true))
                {
                    Console.WriteLine("operate failed!");
                }

                /* direct control with enhanced security */
                objectReference = "simpleIOGenericIO/GGIO1.SPCSO3";
                control         = con.CreateControlObject(objectReference);

                controlModel = control.GetControlModel();
                Console.WriteLine(objectReference + " has control model " + controlModel.ToString());

                if (controlModel == ControlModel.CONTROL_MODEL_DIRECT_ENHANCED)
                {
                    control.SetCommandTerminationHandler(commandTerminationHandler, null);

                    control.Operate(true);

                    Thread.Sleep(1000);
                }



                con.Abort();
            }
            catch (IedConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }