Esempio n. 1
0
        public dynamic GetValue(Item61850 item)
        {
            dynamic val;

            switch (item.typeMMS)
            {
            case MmsType.MMS_BIT_STRING:
                val = _connection.ReadBitStringValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_BOOLEAN:
                val = _connection.ReadBooleanValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_FLOAT:
                val = _connection.ReadFloatValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_INTEGER:
                val = _connection.ReadIntegerValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_UNSIGNED:
                val = _connection.ReadValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_STRING:
                val = _connection.ReadStringValue(item.path, item.typeFC);
                break;

            case MmsType.MMS_UTC_TIME:
                val = _connection.ReadTimestampValue(item.path, item.typeFC);
                break;

            default:
                val = _connection.ReadValue(item.path, item.typeFC);
                break;
            }

            return(val);
        }
Esempio n. 2
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);
            }
        }