public IActionResult write([FromBody] WriteCMD rawdata)
        {
            string           IpAddress  = rawdata.IpAddress;
            int              Port       = rawdata.Port;
            bool             Operate    = rawdata.Operate;
            string           CMDAddress = rawdata.VarAddress;
            Read_Write       readwrite  = new Read_Write(_subSvc);
            ResultValueModel data       = readwrite.WriteCMD(IpAddress, Port, Operate, CMDAddress);

            return(Json(data));
        }
Exemplo n.º 2
0
        public ResultValueModel WriteValue(string hostip, Int32 port, string varaddress, string FC, dynamic newvalue)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //extract fc
                data_extract dataExtract  = new data_extract();
                var          FunctionCode = dataExtract.ExtractFC(FC);
                var          Value        = dataExtract.ExtractValue(newvalue);
                dynamic      mmsresult    = null;
                //validate datatype
                mmsresult = con.WriteValue(varaddress, FunctionCode, new MmsValue(Value));
                //con close
                con.Abort();
                //result
                Value_Result listresult = new Value_Result
                {
                    Address = varaddress,
                    Value   = mmsresult,
                };
                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);
            }
        }
        public IActionResult readvalue([FromBody] Read_Value rawdata)
        {
            string           IpAddress  = rawdata.IpAddress;
            int              Port       = rawdata.Port;
            string           FC         = rawdata.FC;
            string           Datatype   = rawdata.Datatype;
            string           VarAddress = rawdata.VarAddress;
            Read_Write       readwrite  = new Read_Write(_subSvc);
            ResultValueModel data       = readwrite.ReadVariableValue(IpAddress, Port, Datatype, FC, VarAddress);

            return(Json(data));
        }
        public IActionResult writevalue([FromBody] WriteValue rawdata)
        {
            string           IpAddress  = rawdata.IpAddress;
            int              Port       = rawdata.Port;
            string           VarAddress = rawdata.VarAddress;
            string           FC         = rawdata.FC;
            dynamic          NewValue   = rawdata.NewValue;
            Read_Write       readwrite  = new Read_Write(_subSvc);
            ResultValueModel data       = readwrite.WriteValue(IpAddress, Port, VarAddress, FC, NewValue);

            return(Json(data));
        }
Exemplo n.º 5
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.º 6
0
        public ResultValueModel ReadVariableValue(string hostip, Int32 port, string datatype, string FC, string valueaddress)
        {   //instance
            IedConnection con = new IedConnection();

            try
            {   //connection
                con.Connect(hostip, port);
                //extract fc
                data_extract dataExtract  = new data_extract();
                var          FunctionCode = dataExtract.ExtractFC(FC);
                dynamic      mmsresult    = null;
                //validate datatype
                if (datatype == "BOOLEAN")
                {
                    mmsresult = con.ReadBooleanValue(valueaddress, FunctionCode);
                }
                else if (datatype == "FLOAT")
                {
                    mmsresult = con.ReadFloatValue(valueaddress, FunctionCode);
                }
                else if (datatype == "INT")
                {
                    mmsresult = con.ReadIntegerValue(valueaddress, FunctionCode);
                }
                else if (datatype == "STRING")
                {
                    mmsresult = con.ReadStringValue(valueaddress, FunctionCode);
                }
                else if (datatype == "BITSTRING")
                {
                    mmsresult = con.ReadBitStringValue(valueaddress, FunctionCode);
                }

                //con close
                con.Abort();
                //extract value
                dynamic ValueTuple = null;
                ValueTuple = dataExtract.ExtractValue(mmsresult);
                //result
                Value_Result listresult = new Value_Result
                {
                    Address = valueaddress,
                    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);
            }
        }