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 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); } }
public ResultSingleModel ReadSingleGroup(string hostip, Int32 port, string FC, string vargroup) { //instance IedConnection con = new IedConnection(); try { //connection con.Connect(hostip, port); //exctract fc data_extract dataExtract = new data_extract(); var FunctionCode = dataExtract.ExtractFC(FC); //read group MmsValue mmsresult = con.ReadValue(vargroup, FunctionCode); //con close con.Abort(); //result list dynamic ValueTuple = mmsresult; Read_Result listresult = null; Int16 Quality; DateTimeOffset Timestamp; List <dynamic> valueArray = new List <dynamic>(); if (mmsresult.GetType() == MmsType.MMS_STRUCTURE) { if (mmsresult.Size() == 4) { ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0)); Quality = dataExtract.ExtractValue(mmsresult.GetElement(2)); Timestamp = dataExtract.ExtractValue(mmsresult.GetElement(3)); } else { ValueTuple = dataExtract.ExtractValue(mmsresult.GetElement(0)); Quality = dataExtract.ExtractValue(mmsresult.GetElement(1)); Timestamp = dataExtract.ExtractValue(mmsresult.GetElement(2)); } listresult = new Read_Result { Address = vargroup, Value = ValueTuple, Quality = Quality, Timestamp = Timestamp }; } ResultSingleModel result = new ResultSingleModel() { data = listresult, error = false, errormessage = null }; //destroy instance con.Dispose(); //result return(result); } catch (IedConnectionException e) { ResultSingleModel result = new ResultSingleModel() { 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 instance con.Dispose(); //error result return(result); } }